Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Xamarin.UITest

LukasBLukasB Member ✭✭

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.

Best Answer

  • LukasBLukasB Member ✭✭
    Accepted Answer

    this one solved it:

            var result = app.Query(x => x.Marked("Egen sygdom").Sibling("Platform_DefaultRenderer"));
    
            NUnit.Framework.Assert.IsTrue(result.Count() == 2);
    

Answers

  • RaghadSyRaghadSy Member ✭✭

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

  • LukasBLukasB Member ✭✭

    @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 :(

  • RaghadSyRaghadSy Member ✭✭
    edited July 8

    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.

  • LukasBLukasB Member ✭✭

    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.

  • LukasBLukasB Member ✭✭
    Accepted Answer

    this one solved it:

            var result = app.Query(x => x.Marked("Egen sygdom").Sibling("Platform_DefaultRenderer"));
    
            NUnit.Framework.Assert.IsTrue(result.Count() == 2);
    
  • JarvanJarvan Member, Xamarin Team Xamurai

    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.

Sign In or Register to comment.