Challenge - 5 Problems
XCUITest Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
What is the result of this XCUITest code snippet?
Given the following Swift XCUITest code, what will be the value of
button.exists after running?iOS Swift
let app = XCUIApplication() app.launch() let button = app.buttons["Submit"] // Assume the Submit button is present in the UI let exists = button.exists
Attempts:
2 left
💡 Hint
The button identifier matches an existing UI element.
✗ Incorrect
The
button.exists property returns true if the UI element is found in the app's UI hierarchy after launch.❓ lifecycle
intermediate1:30remaining
When is the
setUp() method called in an XCUITest class?In XCUITest, at what point during the test execution is the
setUp() method called?Attempts:
2 left
💡 Hint
Think about preparing the app state for every test.
✗ Incorrect
The
setUp() method is called before each test method to prepare the environment fresh for every test.📝 Syntax
advanced2:00remaining
What error does this XCUITest code produce?
Consider this code snippet in an XCUITest class:
let app = XCUIApplication() app.buttons["Login"].tap()What error will occur if the "Login" button is not present in the UI?
Attempts:
2 left
💡 Hint
XCUITest waits for elements before interacting.
✗ Incorrect
If the element is missing, XCUITest waits until timeout and then throws a timeout error.
advanced
2:30remaining
How to navigate to a new screen in XCUITest?
Which code snippet correctly taps a button to navigate to a new screen and verifies the new screen's label exists?
iOS Swift
let app = XCUIApplication() app.launch() // Navigate to new screen app.buttons["Next"].tap() // Verify new screen label let label = app.staticTexts["Welcome"] let exists = label.waitForExistence(timeout: 5)
Attempts:
2 left
💡 Hint
Waiting for elements after navigation is important.
✗ Incorrect
Waiting for the label ensures the new screen loaded before asserting its presence.
🔧 Debug
expert3:00remaining
Why does this XCUITest fail intermittently?
This test sometimes fails with a timeout error:
let app = XCUIApplication() app.launch() app.buttons["Load Data"].tap() let table = app.tables["DataTable"] XCTAssertTrue(table.exists)What is the most likely cause?
Attempts:
2 left
💡 Hint
Consider asynchronous UI updates after tapping buttons.
✗ Incorrect
The test does not wait for the table to appear after tapping, so the assertion may run before the UI updates.