gpt4 book ai didi

ios - XCUITest 意外行为

转载 作者:行者123 更新时间:2023-11-28 15:56:34 26 4
gpt4 key购买 nike

我有一个带有 tableView 和细节 vc 的简单项目。 tableView 显示带有“cell (n)”文本的 20 行,详细 View 显示带有按下单元格的标签。我想断言,只要点击一个单元格,我就会在详细 vc 标签的 tableView 中找到文本。因此,例如,如果我点击包含“cell 3”的单元格 3,我想获取此文本,而不是对其进行硬编码,并断言我可以在详细信息 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

最佳答案

问题是您试图在点击单元格后获取单元格的文本。这意味着单元格不再出现在屏幕上(新屏幕已经出现)。您需要做的就是更改行 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)
}

关于ios - XCUITest 意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41649638/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com