我有一个简单的项目与一个tableView和细节vc。tableView显示20行"cell (n)“文本,详细视图显示一个按下单元格的标签。我想断言,如果点击一个单元格,我会得到在detail vc标签的tableView中找到的文本。例如,如果我点击包含"cell 3“的单元格3,我希望获得此文本,而不是对其进行硬编码,并断言我可以在detail vc中找到此文本。
func testCanNavigateToDetailVCWithTheTextFromCell() {
let labelInTableView = app.staticTexts["cell 3"]
labelInTableView.tap()
let labelInDetailVC = app.staticTexts[labelInTableView.label]
XCTAssertTrue(labelInDetailVC.exists)
}这似乎起作用了。但我想这么做:
func testCanNavigateToDetailVCWithTheTextFromCellV2() {
let cell = app.tables.element.cells.element(boundBy: 3) //Get the third cell of the unique tableView
cell.tap()
let textFromPreviousCell = cell.staticTexts.element(boundBy: 0).label //Since is a "Basic" cell it only has one label.
//I will also want to set an accessilibtyIdentifier to the label and access it via cell.staticTexts["id"].label
let labelInDetailVC = app.staticTexts[textFromPreviousCell]
XCTAssertTrue(labelInDetailVC.exists)
}我用这个问题here设置了一个项目
发布于 2017-01-14 21:12:33
问题是您试图在点击后获取单元格的文本。这意味着该单元格不再显示在屏幕上(新屏幕已经出现)。您所需要做的就是更改cell.tap()和let textFromPreviousCell = cell.staticTexts.element(boundBy: 0).label行的顺序。请参阅下面的新函数:
func testCanNavigateToDetailVCWithTheTextFromCellV2() {
let cell = app.tables.element.cells.element(boundBy: 3) //Get the third cell of the unique tableView
let textFromPreviousCell = cell.staticTexts.element(boundBy: 0).label //Since is a "Basic" cell it only has one label.
cell.tap()
let labelInDetailVC = app.staticTexts[textFromPreviousCell]
XCTAssertTrue(labelInDetailVC.exists)
}https://stackoverflow.com/questions/41649638
复制相似问题