3
我想简化我的UITest代码。此时,我有数百行代码用于检查最多八个表格行,每行都有三个文本字段。这不仅会减少我拥有的代码行数,而且还会减少由复制/粘贴/编辑过程导致的错误。Swift 3 - 不能调用非函数类型的值'XCUIElement'
我在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)
}
也做了工作,感谢名单!我还有很多要学习! –
刚刚更新到Swift 4并开始再次获得相同的错误,没有更改代码。我不得不删除Uint(xxx)。我们可以通过下面的例子来说明这个问题:XCTAssertFalse(app.tables.cells.element(boundBy:thisRow).exists) –
好像苹果用'Swift 4'将签名从'UInt'改为'Int'。'func element(boundBy index:Int) - > XCUIElement ' – d4Rk