加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何在XCode7 iOS9中断言TextView值?

发布时间:2020-12-14 19:35:43 所属栏目:百科 来源:网络整理
导读:我正在进行UI单元测试.在图片里. 它们是UILabel,除了长描述是UITextView. 在我想要做的页面断言测试答案中的值. 对于UILabels的答案很好.我可以关注 Xcode UI Test example 只需点击元素并将方法从.tap()更改为.exist()然后通过assert()将其括起来,该方法非
我正在进行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);
}

UI with scrollbar

解决方法

如果其他人发现这个问题,我可以通过使用获得UITextView的文本

app.textViews.element.value as? String

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读