Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to launch the app in the UI test setup method.
iOS Swift
override func setUp() {
super.setUp()
let app = XCUIApplication()
app.[1]()
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using start() or run() which do not exist in XCUIApplication.
Forgetting to launch the app before tests.
✗ Incorrect
The correct method to start the app in XCUITest is launch().
2fill in blank
mediumComplete the code to tap a button with accessibility identifier "submitButton".
iOS Swift
let app = XCUIApplication() app.buttons["[1]"].tap()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong identifier that does not match the button.
Trying to tap a label or other UI element instead of a button.
✗ Incorrect
To tap the submit button, use its accessibility identifier "submitButton".
3fill in blank
hardFix the error in the assertion to check if a label with text "Welcome" exists.
iOS Swift
let app = XCUIApplication() XCTAssertTrue(app.staticTexts["[1]"].exists)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different text string that does not exist.
Ignoring case sensitivity in the text.
✗ Incorrect
The label text to check is "Welcome", so the identifier must match exactly.
4fill in blank
hardFill both blanks to wait for a button with identifier "loginButton" to appear with a timeout of 5 seconds.
iOS Swift
let app = XCUIApplication() let loginButton = app.buttons["[1]"] let exists = loginButton.waitForExistence(timeout: [2]) XCTAssertTrue(exists)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong button identifiers.
Setting timeout too high or too low.
✗ Incorrect
Use the correct button identifier "loginButton" and a timeout of 5 seconds for waiting.
5fill in blank
hardFill all three blanks to enter text "hello" into a text field with identifier "usernameField" and then dismiss the keyboard.
iOS Swift
let app = XCUIApplication() let textField = app.textFields["[1]"] textField.tap() textField.typeText("[2]") app.keyboards.buttons["[3]"].tap()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Typing text into the wrong field.
Not dismissing the keyboard after typing.
✗ Incorrect
The text field identifier is "usernameField", the text to type is "hello", and the keyboard button to dismiss is "Return".