我在尝试编写一个使用后退按钮的测试时遇到了一些障碍,希望有人能用这个给我指出正确的方向。
我的 View 非常标准,我有一个 UINavigation Controller 作为我的根 View Controller ,我将它推到一个点,然后需要返回。
我试图制作一个匹配器,可以在导航栏中找到后退按钮,但没有成功。
我尝试使用标签、id 和值,在后退按钮项上设置可访问性标识符并没有导致匹配,即使它适用于我的其他界面元素。
[self.navigationItem.backBarButtonItem setAccessibilityIdentifier
"Back"];
// Press the back button
id<GREYMatcher> backMatcher =
grey_allOf(grey_accessibilityID(@"Back"), grey_sufficientlyVisible(), nil);
[[EarlGrey selectElementWithMatcher:backMatcher] performAction:grey_tap()];
// Press the back button
id<GREYMatcher> backMatcher =
grey_allOf(grey_accessibilityID(@"Back"), grey_sufficientlyVisible(), nil);
[[EarlGrey selectElementWithMatcher:backMatcher] performAction:grey_tap()];
问题是您需要一个更具体的匹配器来获取 Back
来自 UINavigationController
的按钮.如果您查看在测试失败时转储的 ui 层次结构,您会注意到不止一个元素具有可访问性标签 Back
.因此,您需要使用 grey_accessibilityTrait
进一步缩小搜索范围。像这样的匹配器:
id<GREYMatcher> matcherForBackButton =
grey_allOf(grey_accessibilityLabel(@"Back"),
grey_accessibilityTrait(UIAccessibilityTraitButton),
nil);
[[EarlGrey selectElementWithMatcher:matcherForBackButton]
performAction:grey_tap()];
关于ios - 使用 EarlGrey 按下导航栏上的后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35929632/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |