locked
Xamarin.UITest RRS feed

  • Question

  • User395396 posted

    Hi All,

    is there a way how to verify in UI test that for example only three elements are on screen.

    So for example I have something like this:

    I want to verify that only those three options are on screen. So for example when there would be 4th option there test would fail.

    Thank you.

    Wednesday, July 8, 2020 9:25 AM

Answers

  • User395396 posted

    this one solved it:

            var result = app.Query(x => x.Marked("Egen sygdom").Sibling("Platform_DefaultRenderer"));
    
            NUnit.Framework.Assert.IsTrue(result.Count() == 2);
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, July 8, 2020 11:54 AM

All replies

  • User394000 posted

    you can execute a query like this NUnit.Framework.Assert.IsTrue(App.Query(x => x.Id("NoResourceEntry-101").Child()).Count() == 3);

    Wednesday, July 8, 2020 10:09 AM
  • User395396 posted

    @RaghadSy

    Thank you for your answer. I tried that, but I am not sure that I can rely on Id, seems like it is being generated and might not be unique. However When I use it it is giving me only one result (which is not even an option on screen)

    I was trying to go through "Sibling()" of one of the options, which should give me two elements. But that seems like not working as well. It is giving me two elements which I want, but also third, which I have no idea where it is coming from :(

    Wednesday, July 8, 2020 10:28 AM
  • User394000 posted

    try to use app.flash its really helpful to locate the required element. also if you have access to the code use automationId attribute It makes it easier to reach the element you want.

    Wednesday, July 8, 2020 10:33 AM
  • User395396 posted

    Yeah, I tried app.Flash(). It seems like it is taking those two options, and also container ....I guess I have to check with our devs.

    Thank you.

    Wednesday, July 8, 2020 10:36 AM
  • User395396 posted

    this one solved it:

            var result = app.Query(x => x.Marked("Egen sygdom").Sibling("Platform_DefaultRenderer"));
    
            NUnit.Framework.Assert.IsTrue(result.Count() == 2);
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, July 8, 2020 11:54 AM
  • User382871 posted

    You could also use the following code to get the elements' count. ``` var result = app.Query(x => x.Marked("layout").Child()).Length;

    NUnit.Framework.Assert.IsTrue(result == 3); ```

    this one solved it: If you've solved the issue, please mark your solution as the answer. It'll help others who face the similar problem.

    Wednesday, July 8, 2020 3:37 PM