swift - iOS UI 自动化:文本字段的断言错误(以红色突出显示)通过 CTAssertTrue
问题描述
在电子邮件更改大小写的自动化过程中,元素“ 文本字段以红色突出显示”的断言存在问题。 你能给出一些建议来断言这个元素吗?
我们是如何尝试解决问题的:
- 通过函数“waitForText”:
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
}
- 通过函数“waitForTextShort”:
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:
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()
解决方案
已解决:只需要求您的开发人员向所需元素添加一些标识符 - 并轻松声明它:)
推荐阅读
- html - Ruby:在 Nokogiri HTML 构建器中包含原始 HTML
- python - 我目前正在用 Python 创建一个计算器,当我执行代码时,按钮位于错误的位置
- android - SQLite 需要具有唯一约束(Android Room 注释)
- javascript - React中的继承反转遍历整个树
- python - 字典python中的顺序如何使键和值相乘
- javascript - 将 setAttribute 反应到 .map 数组中的特定元素
- c# - 链接任务并返回结果
- java - 按下按钮后等待点击输入 Java Fx
- python - 如何使用 Python 块读取文件
- python - python编程使用codeskulptor:使用simplegui的简单计算器