-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Screenshot Tests
Stefan Arentz edited this page Mar 2, 2016
·
15 revisions
The most reliable way to find a button in a UI Test is by using the accessibilityIdentifier
on elements.
Please give the accessibilityIdentifier
a name that looks like ClassName.componentName
.
For example, the button to toggle private mode now has a accessibilityIdentifier
named "TabTrayController.togglePrivateMode"
. This is long, but it makes it very clear what the button is. It leaves no room for ambiguity or confusion.
Then you can simply use code like this:
func test04PrivateBrowsingTabsEmptyState() {
let app = XCUIApplication()
app.buttons["URLBarView.tabsButton"].tap() // Open tabs tray
app2.buttons["TabTrayController.togglePrivateMode"] // Switch to private mode
snapshot("PrivateBrowsingTabsEmptyState-01")
app2.buttons["TabTrayController.togglePrivateMode"] // Switch back from private mode
app.collectionViews.cells.elementBoundByIndex(0).tap() // Close tabs tray by selecting first tab
}
- You can set enviroinment variables in the
setUp()
method. Currently onlyMOZ_SKIP_WHATSNEW
andMOZ_WIPE_PROFILE
exist. - The
setUp()
function is called before every test runs? IS THIS CORRECT? - Create separate test functions to capture managable units. For example do not combine screenshots for many parts of the app in a single test. Instead create multiple tests.
- The order of the tests is very important. Xcode runs the tests sorted by name. This is why the tests are currently numbered like
func test01Intro()
andfunc test02SettingsScreen()
.