仅排毒测试启动画面
Detox only testing Splash Screen
我正在 运行 排毒我的 React-Native 项目,只能测试启动画面。初始屏幕转到登录屏幕,但排毒代码不允许我测试此元素。
测试代码:
describe('Splash', () => {
beforeEach(async () => {
await device.reloadReactNative();
});
it('should have splash screen', async () => {
await expect(element(by.id('splash'))).toBeVisible();
await expect(element(by.id('login'))).toBeVisible();
});
});
给出的错误:
● Splash › should have splash screen
Failed: [Error: Error: Cannot find UI Element.
Exception with Assertion: {
"Assertion Criteria": "assertWithMatcher:matcherForSufficientlyVisible(>=0.750000)",
"Element Matcher": "((!(kindOfClass('RCTScrollView')) && (respondsToSelector(accessibilityIdentifier) && accessibilityID('login'))) || (((kindOfClass('UIView') || respondsToSelector(accessibilityContainer)) && parentThatMatches(kindOfClass('RCTScrollView'))) && ((kindOfClass('UIView') || respondsToSelector(accessibilityContainer)) && parentThatMatches((respondsToSelector(accessibilityIdentifier) && accessibilityID('login'))))))",
"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"
}
]
第一个测试在不测试登录组件时通过
在屏幕上呈现项目需要时间。您可以使用 detox 提供的waitFor
属性。
In most cases, tests should be automatically synchronized with the app. When synchronization doesn't work, you have a fail-safe by using waitFor.
您可以在 documentation 中阅读有关使用 waitFor
的更多信息。
NOTE: Every waitFor call must set a timeout using withTimeout(). Calling waitFor without setting a timeout will do nothing.
NOTE: waitFor will not throw when reaching timeout, instead it will just continue to the next line. To make sure your tests work as you expect them to add expect() at the following line.
因此,根据文档中的示例,您应该将测试更新为
it('should show login screen', async () => {
await expect(element(by.id('splash'))).toBeVisible()
await waitFor(element(by.id('login'))).toBeVisible().withTimeout(2000);
await expect(element(by.id('login'))).toBeVisible()
});
我正在 运行 排毒我的 React-Native 项目,只能测试启动画面。初始屏幕转到登录屏幕,但排毒代码不允许我测试此元素。
测试代码:
describe('Splash', () => {
beforeEach(async () => {
await device.reloadReactNative();
});
it('should have splash screen', async () => {
await expect(element(by.id('splash'))).toBeVisible();
await expect(element(by.id('login'))).toBeVisible();
});
});
给出的错误:
● Splash › should have splash screen
Failed: [Error: Error: Cannot find UI Element.
Exception with Assertion: {
"Assertion Criteria": "assertWithMatcher:matcherForSufficientlyVisible(>=0.750000)",
"Element Matcher": "((!(kindOfClass('RCTScrollView')) && (respondsToSelector(accessibilityIdentifier) && accessibilityID('login'))) || (((kindOfClass('UIView') || respondsToSelector(accessibilityContainer)) && parentThatMatches(kindOfClass('RCTScrollView'))) && ((kindOfClass('UIView') || respondsToSelector(accessibilityContainer)) && parentThatMatches((respondsToSelector(accessibilityIdentifier) && accessibilityID('login'))))))",
"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"
}
]
第一个测试在不测试登录组件时通过
在屏幕上呈现项目需要时间。您可以使用 detox 提供的waitFor
属性。
In most cases, tests should be automatically synchronized with the app. When synchronization doesn't work, you have a fail-safe by using waitFor.
您可以在 documentation 中阅读有关使用 waitFor
的更多信息。
NOTE: Every waitFor call must set a timeout using withTimeout(). Calling waitFor without setting a timeout will do nothing.
NOTE: waitFor will not throw when reaching timeout, instead it will just continue to the next line. To make sure your tests work as you expect them to add expect() at the following line.
因此,根据文档中的示例,您应该将测试更新为
it('should show login screen', async () => {
await expect(element(by.id('splash'))).toBeVisible()
await waitFor(element(by.id('login'))).toBeVisible().withTimeout(2000);
await expect(element(by.id('login'))).toBeVisible()
});