XCUIApplication上的swipeUp()打破了UITest中的XCUIApplication

时间:2016-09-30 11:25:49

标签: ios swift swift3 xctest

我们需要swipeUp进行测试,以查看tableView内的单元格。 swipeUp我们无法打开app.tables后的事件。如果我们不刷卡一切按预期工作。

  • 那么Swift 3与Swift 2相比有什么变化呢?
  • 我们如何解决这个问题?

示例:

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
}

2 个答案:

答案 0 :(得分:1)

尝试直接访问您的元素... app.staticText["something"]

当我写UITests时,我遇到了一些问题。 我搜索了元素,放置了断点,并读取了输出。

使用app命令在控制台中打印po app

enter image description here

读取输出,搜索所需的元素,查看其类型(如果是staticText,button,otherElements,等等......)

enter image description here

看到所有可用元素都显示在输出中。 输出中每行的第一个单词是每个元素的类型。

在您的代码中,使用以下内容访问该类型:app.buttons至按钮,app.staticTexts至标签等...

JLU

答案 1 :(得分:0)

Xcode 9和Swift 4.0确实解决了这个问题。 app.swipeUp()不再清除tableview查询的元素。