如何断言 XCode7 iOS9 中的 TextView 值?

How to Assert TextView value in XCode7 iOS9?

我正在进行 UI 单元测试。在图片里。
它们是 UI 标签,但长描述除外 UITextView。
在我要断言的页面中测试答案中的值。

对于UI标签中的答案即可。我可以关注
该方法非常容易遵循,只需点击元素并将方法从 .tap() 更改为 .exist() 然后用 assert();

将其括起来 我的问题是 UITextViewUILabel.
更复杂 如何获取 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);
}

XCTAssert(app.scrollViews.staticTexts[text].exists, "Didn't find the text!")

不相信您可以获得此处的值,因此您只需要断言它就在那里。如果它是一个文本字段,那么是的,获得 value 将是一个很好的方法。

如果其他人发现这个问题,我可以使用

获取 UITextView 的文本
app.textViews.element.value as? String

这假设当时屏幕上只有一个文本视图。