首页 > 解决方案 > iOS UI 自动化:文本字段的断言错误(以红色突出显示)通过 CTAssertTrue

问题描述

在电子邮件更改大小写的自动化过程中,元素“ 文本字段以红色突出显示”的断言存在问题。 你能给出一些建议来断言这个元素吗?

我们是如何尝试解决问题的:

func waitForText(name: String) {
        waitForElementToAppear(app.staticTexts[name])
    }

“waitForText”函数是“waitForElementToAppear”实现的简写形式:

func waitForElementToAppear(_ element: XCUIElement) -> Bool{
    let predicate = NSPredicate(format: "exists == true")
    let expectat = expectation(for: predicate, evaluatedWith: element, handler: nil)
    let result = XCTWaiter().wait(for: [expectat], timeout: 20)
    return result == .completed
} 
func waitForTextShort(name: String) {
        waitForElementToAppearShort(app.staticTexts[name])
    }

“waitForTextShort”函数是“waitForElementToAppearShort”实现的简写形式:

func waitForElementToAppearShort(_ element: XCUIElement) -> Bool{
        let predicate = NSPredicate(format: "exists == true")
        let expectat = expectation(for: predicate, evaluatedWith: element, handler: nil)
        let result = XCTWaiter().wait(for: [expectat], timeout: 5)
        return result == .completed
    }
CTAssertTrue (app.staticTexts.element (match: .any, id: "Enter your email address"). exists)

使用 UI 测试记录器查找项目仅显示输入字段,而不显示必填字段。

在测试的运行时通过po app.staticTexts卸载元素也不会给出预期的结果:

 StaticText, {{16.0, 130.0}, {288.0, 16.5}}, tag: "Enter your email address"

使用的定位器:

app.tables/*@START_MENU_TOKEN@*/.staticTexts["Enter your email address"]/*[[".cells.staticTexts[\"Enter your email address\"]",".staticTexts[\"Enter your email address\"]"],[[[-1,1],[-1,0]]],[0]]@END_MENU_TOKEN@*/.tap()

标签: swiftui-automationassertios-ui-automation

解决方案


已解决:只需要求您的开发人员向所需元素添加一些标识符 - 并轻松声明它:)


推荐阅读