locked
Coded UI Test Issue with Assertions

    Question

  • I have tried using the assert functionality but find it very limiting.  How do I create an assert statement for a single item in a combo box (collection).  When I try using the cross-hairs it only allows me to select the entire box and not a specific item within the combo box 

    To add more on this, once we select an item in the combo box, how do we validate the item. For example if the value i am expecting is 'test' and actual value is 'test12' the Assertion should fail i.e it should validate the item and fail the Coded UI test. 

    This could either be a text box or Drop down value or any other control value.

    Any MSFT guys ?

    Thanks in Advance.

    Thursday, November 18, 2010 2:26 PM

Answers

  • I guess you are trying to validate on an item which is going to be selected. i.e., you want to validate the clicked item before actually clicking it.

    Try doing focus on the item before clicking and validate the value of the focussed item

    Get the reference of the combobox item using crosshair and do focus on it. and later validate the value of it and then perform click action


    ---Mark this post if this Answers or Helps---
    Cheers
    FunnyFox
    Friday, August 19, 2011 7:12 AM

All replies

  • Current Situation : I am able to assert on the first value of the combo box which is default and the UI map shows the SelectedItem Property value on the first item(in my case its "Select All"). Only when i select a value in the combo box and then the corresponding changes occured in my UI, I can then point the cross hair to the combox box selected Item and assert on the specific selected value. 

    Here are my combo box values: Select All, test, test1, test2 etc.

    When i select "test 2" the page gets the content related to "test 2" and displays below.

    I am trying to assert "test 2" before actually selecting it, and as soon i point cross hair on the combo box.

    Thanks,

    Srinath. 

    Thursday, November 18, 2010 2:30 PM
  • 1. Validating the item inside combobox: Launch Coded UI Test builder. Put your mouse on the list item and do Win+I to select it. You'll see the control selected in Coded UI Test builder. You can add assertions after that. If you have located the combobox, navigating to its children in Coded UI Test Builder can also help you to achieve the same.

    2. Validating the Combobox value: Locate the combobox using Coded UI Test builder and SelectedItem property can be used to assert on the combobox value.

    Thanks.

    Thursday, November 18, 2010 2:33 PM
  • Hi Deepak,

    How do we locate a specific item(suppose its id is 3) in combobox for asserting it. I was able to assert only the first item in the combobox at any time.If the page loads after selecting an item 3, there is no point in asserting as my situation is to assert before the page loads for that item.I am kind of new to codedUI and in case i found the particular item to assert, which is the best comparator to validate the item. Are equal ?

    Sample code would be appreciated.

    Thanks,

    Srinath

    Thursday, November 18, 2010 6:14 PM
  • Hi Srinath,

    According to me your problem is you want to Assert for a particular value in the combo box.

    Your Combo-box has values: Select All , test , test1 , test2 and Select All is selected by default and you have to search whether test2 is present inside the combo box before selecting it.

    If this is your problem then the solution will be:

    Using the cross hair you can identify the particular combo box with its properties and then use the Assert statement as follows:

    HtmlComboBox cbx = new HtmlComboBox(container);

    cbx.SearchProperties.Add("Property","Value");

    // Once the combo box is identified use (Searchin test2 in combo box before selecting it)

    Assert.IsTrue(cbx.InnerText.Contains("test2"));

     

    Regards,

    nk812

    • Proposed as answer by nk812 Monday, July 16, 2012 12:31 PM
    Thursday, August 11, 2011 6:48 PM
  • Hello, 

     

    My problem is not that I want to assert for a particular value in the combo box. My problem is that I want to assert for weather the item's in the combo box are disabled or not disabled. 

    How would one do that? Example the web page has a combo box. It has about 5 items in it. 2 of which are disabled. How can I do an assert on that? When I run a coded UI and click on the individual items in the combo box they get recorded as an HTMLCell.. 

     

    Please help

     

    Regards

    bjm3819

    Thursday, August 18, 2011 11:11 PM
  • I guess you are trying to validate on an item which is going to be selected. i.e., you want to validate the clicked item before actually clicking it.

    Try doing focus on the item before clicking and validate the value of the focussed item

    Get the reference of the combobox item using crosshair and do focus on it. and later validate the value of it and then perform click action


    ---Mark this post if this Answers or Helps---
    Cheers
    FunnyFox
    Friday, August 19, 2011 7:12 AM