Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swipeUp() on XCUIApplication breaks the XCUIApplication in UITest

We got a test where we need to swipeUp to see a cell inside of a tableView. After the swipeUp we cant event print out the app.tables. If we do not swipe everything works as expected.

  • So what has changed in Swift 3 compared to Swift 2 here?
  • How do we fix that issue?

Example:

func testSomethingInApp() {
   let app = XCUIApplication()
   app.launch()
   app.swipeUp() //after this we cant get app.tables anymore. Befor everything is fine
   XCTAssertEqual(app.tables.cells.elementBoundByIndex(5), "something") //something like this
}
like image 362
BennX Avatar asked Sep 30 '16 11:09

BennX


2 Answers

Try to access your element directly... app.staticText["something"]

When I wrote my UITests, I had some issues like these. I searched for the elements, putting breakpoints, and reading the output.

Print app in console using po app command.


enter image description here


Read the output, search for the element you want, see its type (if is a staticText, button, otherElements, whatever...)


enter image description here


See that all the elements available are displayed in output. The first word of each line in output is the type of each element.

In your code, access the type using: app.buttons to buttons, app.staticTexts to labels, etc...

JLU

like image 155
Mendigo dos Bytes Avatar answered Sep 17 '22 13:09

Mendigo dos Bytes


Xcode 9 and Swift 4.0 does fix this issue. app.swipeUp() doesn't clear the tableview queried elements anymore.

like image 30
BennX Avatar answered Sep 18 '22 13:09

BennX