0
0
iOS Swiftmobile~20 mins

UI testing with XCUITest in iOS Swift - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
XCUITest Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
ui_behavior
intermediate
2: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
Afalse
Btrue
CCompilation error
DRuntime crash
Attempts:
2 left
💡 Hint
The button identifier matches an existing UI element.
lifecycle
intermediate
1: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?
ABefore each test method runs
BAfter all test methods have run
COnly once before all tests start
DAfter each test method runs
Attempts:
2 left
💡 Hint
Think about preparing the app state for every test.
📝 Syntax
advanced
2: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?
ATimeout error waiting for element
BRuntime error: Element not found exception
CNo error, test passes
DCompilation error: Missing import
Attempts:
2 left
💡 Hint
XCUITest waits for elements before interacting.
navigation
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)
ADoes not tap button, only checks label existence, returns false
BTaps "Next" button but does not wait for label, returns false
CTaps "Next" button and waits for "Welcome" label to appear, returns true if found
DTaps "Next" button and immediately asserts label without waiting, may fail
Attempts:
2 left
💡 Hint
Waiting for elements after navigation is important.
🔧 Debug
expert
3: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?
AThe button identifier "Load Data" is incorrect
BXCTAssertTrue is used incorrectly
CThe app.launch() call is missing
DThe table may not be loaded immediately after tapping, causing the assertion to run too soon
Attempts:
2 left
💡 Hint
Consider asynchronous UI updates after tapping buttons.