【发布时间】:2018-04-03 12:10:35
【问题描述】:
我已经开始将 detox 集成到我的 React Native 应用程序中,用于一些 e2e testing。
到目前为止效果很好,但是我遇到了一个障碍。我正在尝试测试成功登录,并且流程有效:
- 用户输入正确的凭据
- Redux 将:
- 将用户对象存储在异步存储中
- 向对讲机注册用户
- 触发成功操作
- 将用户重定向到主屏幕 -
navigateToHomeScreen() - 使用用户凭据更新 Sentry
navigateToHomeScreen:
const navigateToHomeScreen = () => dispatch =>
dispatch(
NavigationActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'Home' })],
})
);
在我的Home 屏幕中,我有这个作为我的渲染函数:
<View style={styles.screen} testID="home">
<Header
onMenuPress={navigationMenu.toggle}
onFilterPress={filterMenu.toggle}
/>
<Feed {...{ navigation }} />
<IntercomButton visible={!isActive} />
<Search />
</View>
在我的排毒测试中,我遇到了这种情况,但失败了:
it('should trigger a login', async () => {
const loginFormEmail = element(by.id('login-form-email'));
const loginFormPassword = element(by.id('login-form-password'));
const loginButton = element(by.id('login-button'));
await expect(loginFormEmail).toBeVisible();
await expect(loginFormPassword).toBeVisible();
await expect(element(by.id('login-activity-spinner'))).toBeNotVisible();
await loginFormEmail.replaceText('xxx');
await loginFormPassword.replaceText('xxx');
await loginButton.tap();
await expect(element(by.id('home'))).toBeVisible();
});
我收到以下错误,提示找不到testID="home":
Error: Cannot find UI Element.
Exception with Assertion: {
"Assertion Criteria" : "assertWithMatcher:matcherForSufficientlyVisible(>=0.750000)",
"Element Matcher" : "(((respondsToSelector(accessibilityIdentifier) && accessibilityID('home')) && !(kindOfClass('RCTScrollView'))) || (kindOfClass('UIScrollView') && ((kindOfClass('UIView') || respondsToSelector(accessibilityContainer)) && ancestorThatMatches(((respondsToSelector(accessibilityIdentifier) && accessibilityID('home')) && kindOfClass('RCTScrollView'))))))",
"Recovery Suggestion" : "Check if the element exists in the UI hierarchy printed below. If it exists, adjust the matcher so that it accurately matches element."
}
Error Trace: [
{
"Description" : "Interaction cannot continue because the desired element was not found.",
"Error Domain" : "com.google.earlgrey.ElementInteractionErrorDomain",
"Error Code" : "0",
"File Name" : "GREYElementInteraction.m",
"Function Name" : "-[GREYElementInteraction matchedElementsWithTimeout:error:]",
"Line" : "124"
}
]
【问题讨论】:
-
这对您来说仍然是个问题还是您已经设法解决了?
-
我无法修复它,但 E2E 测试(在旧项目上)被取消了。我仍然想知道怎么做@Andrew
-
在您的应用中点击登录按钮后会发生什么?是进行网络调用,然后在短暂等待后登录并移至主页,还是立即移至主页?
-
它发出一个网络请求,然后在成功后,它移动到主页@Andrew
-
这可能是两个可能的问题:首先,testID 没有正确设置。您应该检查view hierarchy 以查看它是否存在。如果它已正确设置并且您确定它存在,则可能是时间问题并且在主页可见之前调用测试。您可以使用
waitFor()和.withTimeout()来尝试正确捕获它。你可以看到更多的细节here@Dan
标签: detox