★ Get Application
let app = XCUIApplication()
★ accessibilityIdentifier
by code
@IBOutlet weak var button: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
button.accessibilityIdentifier = "Button"
}
★ Setting the device orientation
XCUIDevice.shared().orientation = .faceUp
★ Pressing the home button of the device
XCUIDevice.shared().press(XCUIDeviceButton.home)
★ Manipulate the volume of the device
// Raise the volume
XCUIDevice.shared().press(XCUIDeviceButton.volumeUp)
// Lower the volume
XCUIDevice.shared().press(XCUIDeviceButton.volumeDown)
★ Get UIButton object
let button = app.buttons["identifier"]
★ Tap on UIButton
// Single tap
app.buttons["identifier"].tap()
// Double tap
app.buttons["identifier"].doubleTap()
★ UIButton's title test
let title = app.buttons["Button"].label
XCTAssertEqual(title, "button")
★ Get Navigation's BarButtonItem
let barbutton = app.navigationBars["UITestingViewController.View"].buttons["identifier"]
★ Tap of Navigation's Back button
app.navigationBars["UIView"].children(matching: .button).matching(identifier: "Back").element(boundBy: 0).tap()
★ Compare UITextField's text
let textFieldText = app.textFields["VCTextField"].value as? String
XCTAssertEqual(textFieldText, "0")
★ Tap the TextField to display the keyboard
let textField = element.children(matching: .textField).element
textField.tap()
★ Enter characters in UITextField
// I can not input without displaying the keyboard
let textField = app.textFields["identifier"]
textField.tap()
// input text
textField.typeText("text")
★ Change the value of UISlider
let slideridSlider = XCUIApplication().sliders["SliderID"]
slideridSlider.adjust(toNormalizedSliderPosition: 0)
slideridSlider.adjust(toNormalizedSliderPosition: 0.5)
slideridSlider.adjust(toNormalizedSliderPosition: 1)
// Tap Slider
slideridSlider.tap()
★ switch switching when ID of Switch is not specified
app.switches["1"].tap()
app.switches["0"].tap()
★ Switch when Switch ID is specified
let switchObj = XCUIApplication().switches["Identifier"]
switchObj.tap()
switchObj.tap()
switchObj.tap()
★ Tap the table cell
let app = XCUIApplication()
let cell = app.tables.cells.element(boundBy: 4)
// tap cell
cell.tap()
// When the ID of the cell is specified
XCUIApplication().tables.cells.matching(identifier: "CellID").element(boundBy: 4).tap()
// ID and textLabel? .text specified
XCUIApplication().tables.cells.matching(identifier: "CellID").staticTexts[textLabel?.text].tap()
// When only textLabel? .text is specified 1
XCUIApplication().tables.cells.staticTexts[textLabel?.text].tap()
// When only textLabel? .text is specified 2
XCUIApplication().tables.staticTexts[textLabel?.text].tap()
★ Test the number of UITableView cells
let app = XCUIApplication()
XCTAssertEqual(5, app.tables.cells.count)
★ XCUIElementTypeQueryProvider