【发布时间】:2016-08-05 20:59:16
【问题描述】:
我正在尝试简化我的 UITest 代码。目前,我有数百行代码用于检查最多八个表格行,每个表格行包含三个文本字段。这不仅会减少我拥有的代码行数,而且会减少由复制/粘贴/编辑过程引起的错误。
我在 checkRow 函数的三行中收到“无法调用非函数类型 'XCUIElement' 的值”错误。
如果我将三行中的“thisRow”变量替换为整数,代码将编译。
这是之前和之后。
func testAkcCh() {
navConfig.tap()
pickCD.adjust(toPickerWheelValue: "4")
pickCB.adjust(toPickerWheelValue: "5")
pickSD.adjust(toPickerWheelValue: "3")
pickSB.adjust(toPickerWheelValue: "2")
XCTAssert(app.tables.cells.count == 8)
XCTAssert(app.tables.cells.element(boundBy: 0).staticTexts["Best of Breed"].exists)
XCTAssert(app.tables.cells.element(boundBy: 0).staticTexts[p5].exists)
XCTAssert(app.tables.cells.element(boundBy: 0).staticTexts[d13].exists)
XCTAssert(app.tables.cells.element(boundBy: 1).staticTexts["Best of Opposite Sex"].exists)
XCTAssert(app.tables.cells.element(boundBy: 1).staticTexts[p5].exists)
XCTAssert(app.tables.cells.element(boundBy: 1).staticTexts[d06].exists)
}
进入
func checkRow(thisRow: Int, thisAward: String, thisPoints: String, thisDefeated: String) {
XCTAssert(app.tables.cells.element(boundBy: thisRow).staticTexts[thisAward].exists)
XCTAssert(app.tables.cells.element(boundBy: thisRow).staticTexts[thisPoints].exists)
XCTAssert(app.tables.cells.element(boundBy: thisRow).staticTexts[thisDefeated].exists)
}
func testAkcCh() {
navConfig.tap()
pickCD.adjust(toPickerWheelValue: "4")
pickCB.adjust(toPickerWheelValue: "5")
pickSD.adjust(toPickerWheelValue: "3")
pickSB.adjust(toPickerWheelValue: "2")
XCTAssert(app.tables.cells.count == 8)
checkRow(0, "Best of Breed", p5, d13)
checkRow(1, "Best of Opposite Sex", p5, d06)
}
这可以编译,但破坏了大部分好处......
func checkRow(thisRow: Int, thisAward: String, thisPoints: String, thisDefeated: String) {
XCTAssert(app.tables.cells.element(boundBy: 0).staticTexts[thisAward].exists)
XCTAssert(app.tables.cells.element(boundBy: 0).staticTexts[thisPoints].exists)
XCTAssert(app.tables.cells.element(boundBy: 0).staticTexts[thisDefeated].exists)
}
【问题讨论】:
标签: xcode compiler-errors coded-ui-tests swift3