gpt4 book ai didi

swift - 用于分段控件的 UITesting Swift

转载 作者:行者123 更新时间:2023-11-30 11:45:24 24 4
gpt4 key购买 nike

我有一个标签指示所选片段文本。

默认情况下,label.text =“时间表”

加载片段时,我将使用选定的片段文本更新此标签文本。

在我的 UITestCase 中,我有以下代码:-

func testTargetMotionSettings() {
let app = XCUIApplication() // root of tree of UI elements
// app.segmentedControls.buttons["Settings"].tap()

let outputLabel = app.staticTexts.matching(identifier: "Stimulus motion type").element

// app.buttons["Departures"].tap()
XCTAssertEqual((outputLabel.value as! String), "Departures")

app.buttons["Arrivals"].tap()
XCTAssertEqual((outputLabel.value as! String), "Arrivals")

}

因此“刺激运动类型”是赋予标签的标识符 enter image description here

但它失败了,并显示“XCTAssertEqual failed: ("") is not equal to ("Departures") - "

请帮忙

最佳答案

只要您没有指定自定义辅助功能标签,UILabel 就会自动回退到辅助功能标签的文本值。这意味着您可以使用 XCUIElement.label 而不是 XCUIElement.value 访问标签文本:

func testTargetMotionSettings() {
let app = XCUIApplication()
let outputLabel = app.staticTexts["Stimulus motion type"]

app.buttons["Departures"].tap()
XCTAssertEqual(outputLabel.label, "Departures")

app.buttons["Arrivals"].tap()
XCTAssertEqual(outputLabel.label, "Arrivals")
}

关于swift - 用于分段控件的 UITesting Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48888468/

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