Check a control property in Ui-Test?

I want to check the 'ItemSource' property of a 'ListView' element in a Ui-Test.

var ItemSourceOfmyListView = App.Query(e => e.Marked("MyListView").Invoke("ItemsSource"));

The ListView has the AutomationId "MyListView". The element will be found. But the method "Invoke" seems to work only for methods not for properties.

Is there another way to access a properties of an element in a Ui-test???

Thanks in advance :)

Answers

  • Hi,

    Am able to access the property via the below code. Check whether it helps

    app.WaitForElement(c => c.Id(elementName).Property("text").Like(textToCompare))

    -Kumaran

  • FreefragFreefrag USMember ✭✭

    It only works for 'string' properties. This approuch does not work for complex datatypes.

  • AllanTeagueAllanTeague USMember

    Did you find a way of doing this @Freefrag ? I am having the same issue

  • FreefragFreefrag USMember ✭✭

    Hi, no sorry, I know no way to solve it.

  • fonix232fonix232 USMember ✭✭

    Not sure how actual this question is, but you can check simple types' values with the Property() method of AppQuery object, e.g.:

    app.WaitForElement(c => c.{{query your objects}}.Index(0).Property("Enabled", false));

    This line will wait for the first element of the query to have its Enabled property set to false. You can pop this in a try-catch loop and proceed accordingly.

    This can be used for both immediate and waited tasks (so e.g. if you load a list of items of the same class locally, then query a server for their state, this can be used to check).

    To further said scenario, say you have a list of languages, with all items disabled before a new list is loaded from a web server. This could be solved two ways:

    app.WaitForElement(c => c.All("LanguageListItem").Property("Enabled", true));

    or

    app.WaitForNoElement(c => c.All("LanguageListItem").Property("Enabled", false));

    This will check all (not just on-screen!) instances of the LanguageListItem class, and wait the default 15s for them to be all enabled.

  • pranartdechpokketpranartdechpokket THMember ✭✭

    I use library named "FormsTest" (https://github.com/pranart/FormsTest)
    This library will let you get almost every property value from Xamarin.Forms Controls.

Sign In or Register to comment.