Frank Anderson
Frank Anderson

Reputation: 135

How can I save text on a screen to a string with Xamarin.UI tests?

I am testing a page where you see information about yourself, then you can update that information. I cannot find a way to compare a string to text that is displayed on the screen.

For example:

Name: John Doe

I edit (through another class and method), giving the name "Jane Deer"

editName("Jane Deer");

Now I want to check that the display on the app updates to "Jane Deer".

How can I read text from a view and make it a string in my program?

Upvotes: 0

Views: 208

Answers (1)

matisse
matisse

Reputation: 133

When you query for an element you will get back an array of AppResult. You can get the first element from this array and get the Text property from that like so:

var name = app.Query(x => x.Id("myElement")).First().Text;
Assert.AreEqual("Jane Deer", name);

Upvotes: 2

Related Questions