Reputation: 139
I am trying to simplify my UITest code. At this time I have hundreds of lines of code for checking up to eight table rows each with three text fields. This will not only reduce the number of lines of code that I have, but it will reduce the erros that are caused by the copy/paste/edit process.
I am getting a "Cannot call value of non-function type 'XCUIElement'" error on the three lines in the checkRow function.
If I replace the 'thisRow' variable in the three lines with an integer, the code will compile.
Here is the before and after.
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)
}
into
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)
}
This compiles, but defeated most of the benefit...
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)
}
Upvotes: 3
Views: 3399
Reputation: 15377
The function signature of the element(...
function looks like:
func element(boundBy index: UInt) -> XCUIElement
The compiler is interpreting your 0
literal as the appropriate type for the context, which when passed directly is UInt
. However, when passing 0 into checkRow
, it interprets it as an Int
since that is the type you specified for thisRow
.
My guess is that you need to change the type of your thisRow
parameter to UInt
:
func checkRow(thisRow: UInt, thisAward: String, thisPoints: String, thisDefeated: String) {
thisRow
to UInt
like:
XCTAssert(app.tables.cells.element(boundBy: UInt(thisRow)).staticTexts[thisAward].exists)
Upvotes: 9