【发布时间】:2017-05-27 14:49:18
【问题描述】:
我正在为我的 iOS 应用程序实现 UITests。 到目前为止,我已经能够进行一些简单的测试,但是我来到了一个 tableView,其中有两个部分。每个部分都有一个 sectionHeaderView 包含静态文本,例如。 “SECTION 1”和“SECTION 2”,采用普通 sectionHeader 样式。
当执行app.tables.staticTexts["SECTION 1"].exists 时,它返回true。这是第一部分,当视图加载时在最顶部可见。
执行相同操作时,但对于“SECTION 2”,它返回false。此部分的 sectionHeaderView 此时在视图之外,所以我认为这是问题所在,但事实证明不是..
我尝试了app.swipeUp(),它成功地将第二部分带入了屏幕。在 swipeUp 之后,我睡了几秒钟让视图稳定下来,然后我执行了相同的检查,但它根本找不到第二个 sectionView。
向下滚动后,我尝试打印出 app.tables.staticTexts.debugDescription 以查看它可以找到什么,它只显示第一部分以及我在最底部的 tableFooterView表格视图。
当我执行app.tables.staticTexts["SECTION 2"].exists 时,我可以在模拟器上看到“SECTION 2”文本。然而它不存在于测试中。
为什么我的第二个 sectionHeaderView 对 XCTest 完全不可见?是不是我特别在这个视图上禁用了某种可访问性变量?我什么都找不到。。
编辑,输出:
t = 32.25s Find: Descendants matching type Table
t = 32.26s Find: Descendants matching type StaticText
t = 32.26s Find: Elements matching predicate '"SECTION 1" IN identifiers'
Found SECTION 1. Will scroll down to find Section 2.
t = 32.26s Swipe up Target Application 0x6080000bbf60
t = 32.26s Wait for app to idle
t = 32.30s Find the Target Application 0x6080000bbf60
t = 32.30s Snapshot accessibility hierarchy for my.bundle.identifier
t = 33.09s Wait for app to idle
t = 33.14s Synthesize event
t = 33.42s Wait for app to idle
Slept for 3 seconds. Have scrolled down. SECTION 2 in view now.
t = 38.86s Snapshot accessibility hierarchy for my.bundle.identifier
t = 39.64s Find: Descendants matching type Table
t = 39.65s Find: Descendants matching type StaticText
t = 39.65s Find: Elements matching predicate '"SECTION 2" IN identifiers'
t = 39.66s Assertion Failure: MyUITests.swift:347: XCTAssertTrue failed - SECTION 2 does not exist
t = 39.66s Tear Down
【问题讨论】:
-
当您查找第二部分标题时,输出是否说它正在使用缓存的快照/层次结构?
-
@Oletha No.。请参阅更新后的问题以了解其内容。
-
您解决了这个问题吗?我也面临这个问题,滚动后我的sectionheader信息完全消失了
-
@anoop4real 不,我放弃了。不过,这是一年半前的事了,所以现在也许还有其他方法可以解决这个问题。如果您找到解决方案,请告诉我。
-
我在 11.4 中尝试过创建简单的 tableview 应用程序,正确使用标识符,一旦某个部分超出范围,然后重新出现,所有可访问性特征都会丢失。当我们使用 customheader 视图时会观察到这一点。我使用的一种解决方法是将标识符直接添加到自定义标题的 UIView 而不是其中似乎保留的标签....但仍然想知道根本原因,我认为这是 XCTest 的问题
标签: ios ui-automation xctest xcode-ui-testing