简体   繁体   English

在XCTest中的UI测试中从TextView获取文本

[英]Getting text from TextView in UI test in XCTest

I'm trying XCode for iOS UI testing. 我正在尝试使用XCode进行iOS UI测试。 My test application has UITextView element with accessibility identifire displayTextView . 我的测试应用程序有UITextView元素,可访问性标识displayTextView

I tried simple test that taps this element, types some text it and then check the result the following way: 我尝试了简单的测试,点击这个元素,键入一些文本,然后检查结果如下:

XCUIElement *textView = app.textViews[@"displayTextView"];
[textView tap];
[textView typeText:@"9.9"];

It works. 有用。 But then I can't get the typed text from the text view. 但后来我无法从文本视图中获取键入的文本。 I tried to do it by the following: 我尝试通过以下方式做到这一点:

XCTAssertEqual([textView.accessibilityValue isEqualToString:@"9.9"]);

But it seems it is incorrect, because textView.accessibilityValue is null. 但它似乎不正确,因为textView.accessibilityValue为null。 What method would be appropriate to get the typed text? 获取打字文本的方法是什么?

I found the answer. 我找到了答案。 The correct way is: 正确的方法是:

XCTAssert([textView.value isEqualToString:@"9.9"]);

or let text = textView.value as! String 或者let text = textView.value as! String let text = textView.value as! String

I used: 我用了:

let expectedValue = "Hello World!"
XCTAssert(app.staticTexts[expectedValue].isHittable)

Using this approach, we look for labels displaying expectedValue , and verify if it is visible... 使用这种方法,我们查找显示expectedValue标签,并验证它是否可见......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM