Xcode UI测试-用addSubview添加的Uiview对UI测试是完全不可见的 [英] Xcode UI testing - Uiviews added with addSubview are completely invisible to the UI tests

查看:244
本文介绍了Xcode UI测试-用addSubview添加的Uiview对UI测试是完全不可见的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试XCode 7.3上的新UI测试,发现了对我来说似乎是个错误的东西.

I've been giving a try to the new UI tests on XCode 7.3 and I've found what it seems a bug to me.

问题在于,通过" addSubview "方法添加的视图对于UI测试系统而言似乎是完全不可见的.

The problem is that views added through the "addSubview" method seems to be completely invisibles to the UI test system.

我有这个观点:

此UIview创建代码:

And this UIview creating code:

    let container = UIView(frame: CGRectMake(0, 0, 375, 200))
    container.backgroundColor = UIColor.orangeColor()
    container.isAccessibilityElement = false
    let label = UILabel(frame: CGRectMake(0, 100, 375, 20))
    label.backgroundColor = UIColor.yellowColor()
    label.textAlignment = NSTextAlignment.Center
    label.accessibilityIdentifier = "labelIdentifier"
    label.text = "I am a label"
    container.addSubview(label)

这个简单的UI测试:

func testExample() {

    let final  = XCUIApplication().staticTexts.containingType(.StaticText, identifier: "labelIdentifier").element
    XCTAssertEqual(final.label, "I am a label")
}

问题在于,根据我如何附加橙色视图,测试未找到标签.如果我这样做:

The problem is that, depending on how I attach the orange view, the test doesn't find the label. If I do a:

    self.tableView.tableHeaderView = container

测试通过完全没有问题,但附加以下内容:

Test pass without any problem at all but attaching it with:

    self.tableView.addSubview(container)

引发下一个错误:

在论坛中进行了简单的研究后,我已经测试了所有推荐的设置,例如设置为false的容器" isAccessibilityElement "属性等等,但似乎无济于事.

After digging a little in the forums I've already tested all recommended settings like setting to false the container "isAccessibilityElement" property and such, but nothing seems to work.

长话短说. ¿有人尝试使用添加" addSubview "方法将元素附加到其他UIView吗?

Long story made short. ¿Anyone have tried to get an element attached to other UIView with the add "addSubview" method?

推荐答案

您好,我用tableView和您的容器创建了一个示例项目

Hello I craete a sample project with tableView and your container

并将容器添加到tableView

and add container to tableView

尝试以下示例:)

app.tables.staticTexts ["labelIdentifier"]

app.tables.staticTexts["labelIdentifier"]

这篇关于Xcode UI测试-用addSubview添加的Uiview对UI测试是完全不可见的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆