Swift 3 - 不能调用非功能类型的值' XCUIElement'

时间:2016-08-05 20:59:17

标签: xcode compiler-errors coded-ui-tests swift3

我正在尝试简化我的UITest代码。这时我有数百行代码,用于检查最多八个表行,每行有三个文本字段。这不仅会减少我拥有的代码行数,而且还会减少复制/粘贴/编辑过程引起的错误。

我得到了一个"无法调用非功能类型的值' XCUIElement'" checkRow函数中三行的错误。

如果我更换了这个' 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)
}

1 个答案:

答案 0 :(得分:9)

detail函数的函数签名如下:

element(...

编译器将您的func element(boundBy index: UInt) -> XCUIElement 文字解释为上下文的适当类型,直接传递时为0。但是,当将0传递给UInt时,它会将其解释为checkRow,因为这是您为Int指定的类型。

我的猜测是,您需要将thisRow参数的类型更改为thisRow

UInt

<小时/> 或者,将func checkRow(thisRow: UInt, thisAward: String, thisPoints: String, thisDefeated: String) { 转换为thisRow,例如:

UInt