我在尝试编写一个使用后退按钮的测试时遇到了一些障碍,希望有人能用这个为我指明正确的方向。
我的视图非常标准,我有一个 UINavigation 控制器作为我的根视图控制器,我将其推到某个点,然后需要返回。
我尝试制作一个匹配器来查找导航栏中的后退按钮,但没有取得任何成功。我尝试使用标签、id 和值,在后退按钮项上设置可访问性标识符并未导致匹配,即使它适用于我的其他界面元素。
[self.navigationItem.backBarButtonItem setAccessibilityIdentifier:@"Back"];
Run Code Online (Sandbox Code Playgroud)
在我的测试中我有以下内容:
// Press the back button
id<GREYMatcher> backMatcher =
grey_allOf(grey_accessibilityID(@"Back"), grey_sufficientlyVisible(), nil);
[[EarlGrey selectElementWithMatcher:backMatcher] performAction:grey_tap()];
Run Code Online (Sandbox Code Playgroud)
我使用断点和PO进行更深入的研究,发现后退按钮的accessibilityLabel确实设置为@“Back”,但它与以下代码也不匹配。
// Press the back button
id<GREYMatcher> backMatcher =
grey_allOf(grey_accessibilityID(@"Back"), grey_sufficientlyVisible(), nil);
[[EarlGrey selectElementWithMatcher:backMatcher] performAction:grey_tap()];
Run Code Online (Sandbox Code Playgroud) 我开始尝试使用EarlGrey一点点,现在已经使用XCUITest进行了UI测试.我遇到了无法解除系统警报的经典问题,这很奇怪,因为看起来Google实现了一个名为grey_systemAlertViewShown()的系统警报匹配器.我正在尝试使用GREYCondition检测系统警报.这是我尝试过的:
- (void)waitForAndDismissSystemAlertForSeconds:(NSInteger)seconds {
GREYCondition *interactableCondition = [GREYCondition conditionWithName:@"isInteractable" block:^BOOL{
// Fails if element is not interactable
NSError *error;
[[EarlGrey selectElementWithMatcher:grey_systemAlertViewShown()] assertWithMatcher:grey_interactable() error:&error];
if (error) {
return NO;
} else {
NSError *allowButtonError;
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Allow")] assertWithMatcher:grey_notNil() error:&allowButtonError];
if (!allowButtonError) {
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Allow")] performAction:grey_tap()];
}
return YES;
}];
[interactableCondition waitWithTimeout:seconds];
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过使用这里描述的addUIInterruptionMonitorWithDescription(但是使用EarlGrey代码来完成我在上面的中断监视器中所做的事情):Xcode 7 UI测试:如何在代码中解除一系列系统警报
两种方法都不奏效.我的GREYCondition中的非错误情况不会触发断点,并且中断监视器也不会解除我的警报.
有人知道EarlGrey是否支持解雇系统警报?
看来EarlGrey在测试我们的APP时不能使用等待APP空闲的好功能。在每个屏幕上出现此错误:
EarlGrey 尝试等待 5.0 秒让应用程序达到空闲状态,但没有成功。EarlGrey 现在被迫清理状态跟踪器,因为测试 -[EGT testLogin] 可能导致 UI 线程无限期地处于非空闲状态
现在我禁用了该功能并且一切正常,但无法理解此类问题的原因是什么。我在 Xcode 7 UI 自动化上遇到了同样的问题,但仅在整个应用程序的 1 个屏幕上(因为一些大量数据获取器)而不是在欢迎页面上。
这是 AppStateTracker 的状态:
Waiting for a draw/layout pass to complete
Waiting for root UIViewController to appear
Run Code Online (Sandbox Code Playgroud) 假设您有一个 tableView 或 fileListView,并且您想对其执行拉动刷新操作。尝试通过滑动和滚动执行,最初没有结果。
我在使用EarlGrey的同步功能时遇到了问题.我正在尝试为我的应用程序创建一个简单的测试示例,它基本上会检查登录按钮是否显示.
func testExample() {
let success = GREYCondition(name: "Wait for action view controller", block: { () -> Bool in
if let rootVC = UIApplication.shared.keyWindow?.rootViewController, rootVC is ValuePropsViewController {
return true
}
else {
return false
}
}).wait(withTimeout: 10)
GREYAssertTrue(success, reason: "Action view controller should appear within 5 seconds")
EarlGrey.select(elementWithMatcher: grey_accessibilityID("loginButton")).assert(grey_sufficientlyVisible())
}
Run Code Online (Sandbox Code Playgroud)
但是,它总是超时,我收到以下错误消息.我检查屏幕截图,正确的屏幕显示失败.
Exception Name: AssertionFailedException
Exception Reason: Timed out while waiting to perform assertion.
Exception with Assertion: {
"Assertion Criteria" : "assertWithMatcher: matcherForSufficientlyVisible(>=0.750000)",
"Element Matcher" : "(respondsToSelector(accessibilityIdentifier) && accessibilityID('loginButton'))"
} …Run Code Online (Sandbox Code Playgroud)