android – Xamarin ui test not all rows have each piece of data id-ThrowExceptions

Exception or error:

Hey trying to work out how to write a Xamarin UI test that checks the index of an ID is the same as the primary row ID index.

EG data looks like this on phone screen

Movie name = id(“PrimaryText”) -> always present

Movie runtime = id(“SecondaryText”) -> always present

Movie releaseDate = id(“OptionialText”) -> not always present, no reference on that row is not there

I can have 10 movies on the page and all have a name and runtime, however not all have a release date so the movies at index 0 & 1 have release dates but 2 & 3 don’t.

So when I write my test for index 4 it looks like this

            Assert.AreEqual("", application.Query(x => x.Id("PrimaryText"))[0].Text);
            Assert.AreEqual("", application.Query(x => x.Id("SecondaryText"))[0].Text);
            Assert.AreEqual("", application.Query(x => x.Id("OptionalText"))[0].Text);

            Assert.AreEqual("", application.Query(x => x.Id("PrimaryText"))[1].Text);
            Assert.AreEqual("", application.Query(x => x.Id("SecondaryText"))[1].Text);
            Assert.AreEqual("", application.Query(x => x.Id("OptionalText"))[1].Text);

            Assert.AreEqual("", application.Query(x => x.Id("PrimaryText"))[2].Text);
            Assert.AreEqual("", application.Query(x => x.Id("SecondaryText"))[2].Text); 

            Assert.AreEqual("", application.Query(x => x.Id("PrimaryText"))[3].Text);
            Assert.AreEqual("", application.Query(x => x.Id("SecondaryText"))[3].Text); 

            Assert.AreEqual("", application.Query(x => x.Id("PrimaryText"))[4].Text);
            Assert.AreEqual("", application.Query(x => x.Id("SecondaryText"))[4].Text);
            Assert.AreEqual("", application.Query(x => x.Id("OptionalText"))[2].Text);

As you can see index 4 has a reference for index 2 for OpetionalText as it is the 3rd occurrence on the page, is there a different way to do this or is it the best way?

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *