This is a migrated thread and some comments may be shown as answers.

How to validate dropdown contains text?

3 Answers 252 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jan Mark P.
Top achievements
Rank 1
Jan Mark P. asked on 10 Jan 2011, 11:32 AM
Hi,

How do I verify if my RadComboBox contains a specific text?
I used the coded step as below:

string textToFind = "ATAX";
bool found = false

 

 

foreach(Telerik.WebAii.Controls.Xaml.RadComboBoxItem item in Pages.Tiger.SilverlightApp.TaxCodeComboBoxRadcombobox.Items)
{
    if (item.Content.ToString().Equals(textToFind))
    {
        found =
true;
        break;
    }
}
Assert.IsTrue(found);

But when execution, I got the following error:

Exception thrown executing coded step: '[test] : test'.InnerException:ArtOfTest.Common.Exceptions.AssertException: Assert.IsTrue - [Expected:True],[Actual:False] at ArtOfTest.Common.UnitTesting.Assert.IsTrue(Boolean condition, String message) at ArtOfTest.Common.UnitTesting.Assert.IsTrue(Boolean condition)

 

 

Am I missing something? It doesn't seem to correctly identify the items of the combo box.

I edited TaxComboBoxRadComboBox in such a way automationid = TaxCodeComboBox, but I am still getting the same error

I can show to you how I create the script through SharedView

Regards,
Jan Mark

 

 

3 Answers, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 13 Jan 2011, 04:16 PM
Hi Jan Mark,
    Silverlight comboboxes are "virtualized". The items of the combobox are generated on demand when the drop-down of the combobox is expanded. In fact if the combobox contains a lot of elements and some cannot be displayed - those elements will be generated when you scroll-down the drop-down to make them visible.

 Here's what I think is happening in your code: the collection of items you're getting is actually empty because you haven't expanded the combobox. So your loop statements doesn't get executed and the value of boolean found is never changed. From there the statement:
Assert.IsTrue(found);
fails the method because found=false.

Here's what you need to do:
Record a click on the combobox. Add in a "WaitFor drop-down is open" step for good measure (see screenshot 1). Also, if the there are a lot of items and some are not displayed - drag the menu until you get to the end - this will be recorder as a drag step. Put those two or three steps before the coded step. Now your test should work.

Let me know how it goes.

Best wishes,
Stoich
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
Jan Mark P.
Top achievements
Rank 1
answered on 13 Jan 2011, 04:30 PM
Hi Stoich,

I appreciate your response but I still get the same error. I've tried it with a combo box with few items (no dragging required) but same error was found. I also included the "WaitFor drop-down is open" step but still not a success.

Regards,
Jan Mark
0
Stoich
Telerik team
answered on 13 Jan 2011, 10:42 PM
Hello Jan Mark,
     I can assure you that this works because I created a small test and tried it while I was compiling the answer I gave you - it worked perfectly. 

I want to perform some diagnostics. Please change your coded step to this:
Log.WriteLine("Item count is"+Convert.ToString(Pages.Tiger.SilverlightApp.TaxCodeComboBoxRadcombobox.Items.Count));
int i=0;
Log.WriteLine("Text to find:"+textToFind);
 
foreach(Telerik.WebAii.Controls.Xaml.RadComboBoxItem item in Pages.Tiger.SilverlightApp.TaxCodeComboBoxRadcombobox.Items)
{
Log.WriteLine("Item "+Convert.ToString(i)+":"+item.Content.ToString());
 
    if (item.Content.ToString().Equals(textToFind))
    {
        found = true;
        break;
    }
i++;
}
 
Assert.IsTrue(found);
Run the coded step like this and paste the output of the Log after the test finishes. It's the same code - I just added some WriteLines to make things more transparent. 

Since you said that you've added the "open drop-down" step in the right place my next hunch is that this:
item.Content.ToString().Equals(textToFind)
isn't doing what it's supposed to. Maybe it will need to be changed to 
item.Content.ToString().Contains(textToFind)
I will able to tell you with 100% certainty once you give me the log output from the modified coded step.

Would it be also possible for you to send me the actual test you're working on or at least a screenshot?

Hope to hear from you soon!

Kind regards,
Stoich
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
Tags
General Discussions
Asked by
Jan Mark P.
Top achievements
Rank 1
Answers by
Stoich
Telerik team
Jan Mark P.
Top achievements
Rank 1
Share this question
or