0
0
iOS Swiftmobile~10 mins

UI testing with XCUITest in iOS Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Aopen
Brun
Claunch
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using start() or run() which do not exist in XCUIApplication.
Forgetting to launch the app before tests.
2fill in blank
medium

Complete 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'
AnextButton
BloginButton
CcancelButton
DsubmitButton
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.
3fill in blank
hard

Fix 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'
AWelcome
BHello
CStart
DHome
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different text string that does not exist.
Ignoring case sensitivity in the text.
4fill in blank
hard

Fill 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'
AloginButton
BsubmitButton
C5
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong button identifiers.
Setting timeout too high or too low.
5fill in blank
hard

Fill 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'
AusernameField
Bhello
CReturn
DsubmitButton
Attempts:
3 left
💡 Hint
Common Mistakes
Typing text into the wrong field.
Not dismissing the keyboard after typing.