【发布时间】:2015-09-09 07:12:00
【问题描述】:
我正在做一个 UI 单元测试。在图片里。
它们是 UILabel,除了长描述是 UITextView。
在我想要断言的页面中测试答案中的值。
对于 UILabels 中的答案很好。我可以关注Xcode UI Test example
该方法很容易理解,只需点击元素并将方法从.tap()更改为.exist(),然后用assert()括起来;
我的问题是UITextView 比UILabel 更复杂。
如何获取UITextView 的值以便进行断言检查?
func testG(){
let app = XCUIApplication()
app.launch();
app.buttons["Enter"].tap()
app.tables.staticTexts["Bee"].tap()
assert(app.scrollViews.staticTexts["Name :"].exists);
assert(app.scrollViews.staticTexts["Age :"].exists);
assert(app.scrollViews.staticTexts["Specialty :"].exists);
assert(app.scrollViews.staticTexts["Description :"].exists);
assert(app.scrollViews.staticTexts["Bee"].exists);
assert(app.scrollViews.staticTexts["11"].exists);
assert(app.scrollViews.staticTexts["Sky Diver"].exists);
let text = "Bees are flying insects closely related to wasps and ants, known for their role in pollination and, in the case of the best-known bee species, the European honey bee, for producing honey and beeswax. Bees are a monophyletic lineage within the superfamily Apoidea, presently considered as a clade Anthophila. There are nearly 20,000 known species of bees in seven to nine recognized families,[1] though many are undescribed and the actual number is probably higher. They are found on every continent except Antarctica, in every habitat on the planet that contains insect-pollinated flowering plants.EOF";
assert(app.scrollViews.childrenMatchingType(.TextView).element.exists);
}
【问题讨论】:
-
您是否尝试阅读
value? masilotti.com/xctest-documentation/Protocols/… -
@dasdom。感谢你的回复。我根据您的回答设置了价值。现在我可以通过
XCTAssertEqual(app.scrollViews.childrenMatchingType(.TextView).element.value as? String, text)进行断言 -
这应该被添加为这个问题的答案。它对我有用。
标签: ios xcode swift unit-testing xcode-ui-testing