- 您无需从位于同一目标的不同文件夹中导入文件。它们可以直接使用而无需导入。
- 请参阅使用 Swift 读取 JSON 文件以读取 json 文件。
用于页面对象设计
AppNameUITests/Screens/Screen1.swift
class Screen1 {
var app: XCUIApplication
init(app: XCUIApplication) {
self.app = app
}
var element1: XCUIElement {
return app.buttons.firstMatch
}
var element2: [XCUIElement] {
return app.textFields.allElementsBoundByIndex
}
func method1() -> Int {
element1.click()
return element2.count
}
}
AppNameUITests/Tests/TestSuite1.swift
class TestSuite1: XCTestCase {
override func setUp() {
// launch application and pre-conditions for the test case
}
override func tearDown() {
// clean up steps and terminate the application
}
func testMethod1() {
let app = XCUIApplication()
let screen1Obj = Screen1(app: app)
XCTAssertTrue(screen1Obj.method1() == 5, "Test failed.")
}
}