我已开始将detox
集成到我的React Native应用程序中以获取某些e2e testing
。
到目前为止效果很好,但是我遇到了障碍。我正在尝试测试成功登录,并且流程是有效的:
navigateToHomeScreen()
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"
}
]
答案 0 :(得分:0)
我遇到一个我试图测试的登录流程的问题。我正在使用react-navigation,根据文档,您可以将testID传递给选项卡栏,但是由于某些原因,用户登录后检测到导航控件(标题,底部的选项卡栏)时,它确实很不稳定。因此,我只是添加了一个testID到我控制的元素,而不必担心它是被设置还是被设置为顺序。在主屏幕上,我在主屏幕上的View标记上设置了一个testID,它可以正常工作而不会超时。尽量不要在您无法控制的内容上设置testID。
await expect(element(by.id('homeScreenViewTag'))).toBeVisible();