This tutorial discusses ways to find UIElement for UI Testing.
Check demo code at Github:
https://github.com/Sylvia-YiyinShen/FindElementForUITests
Easiest way is using the XCode built-in recording functionality
Tap the red Record button, XCode will build and run the app. Every gesture/interaction such as dragging, tapping, scrolling... will be automatically captured into code. Tap the Record button again when you want to end this mode.
Note: sometimes you may find the Record button is disabled. Make sure that you cursor is within the scope of your testing function.
Find element by text
element.exists will work for static element, check async function utilities?.waitForElementToAppear in my demo for dynamically populated element
You will find .staticTexts[""] doesn't work for other element, such as UIButton, NavigationBar...
You have to specify the corresponding element type.
What if the text on label, button and title is dynamic? Now let's look at another approach
Find UIElement by indentifier
1. Specify the Identifier under Accessibility section in Identity Inspector
Or by code
2. Find it by identifier in UITests
Tricks to find identifier and check why it is can not be found be identifier - Right click XCode and open Accessibility Inspector
Select the right simulator and tap Start Inspection
Next focus or tap an element in simulator, Accessibility Inspector will tell you the type of the element and wether it has an identifier.
No comments:
Post a Comment