我已经开始将detox
一些 e2e 集成到我的 React Native 应用程序中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"
}
]