Javascript 排毒只测试启动屏幕
我正在React原生项目上运行detox,只能测试启动屏幕。启动屏幕转到登录屏幕,但解毒代码不允许我测试此元素 测试代码:Javascript 排毒只测试启动屏幕,javascript,ios,react-native,jestjs,detox,Javascript,Ios,React Native,Jestjs,Detox,我正在React原生项目上运行detox,只能测试启动屏幕。启动屏幕转到登录屏幕,但解毒代码不允许我测试此元素 测试代码: describe('Splash', () => { beforeEach(async () => { await device.reloadReactNative(); }); it('should have splash screen', async () => { await expect(element(by.id('
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"
}
]
第一个测试在运行时通过,不测试登录组件在屏幕上呈现项目需要时间。您可以使用解毒提供的
waitFor
属性
在大多数情况下,测试应该自动与应用程序同步。当同步不起作用时,您可以使用waitFor进行故障保护
您可以在中阅读有关使用waitFor
的更多信息
注意:每个waitFor调用都必须使用withTimeout()设置超时。调用waitFor而不设置超时将不会起任何作用
注意:waitFor在到达超时时不会抛出,而是继续到下一行。为了确保测试按预期工作,请在下面一行添加expect()
因此,根据文档中的示例,您应该将测试更新为
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()
});
尝试一下,看看这是否有效,因为当Detock检查视图层次结构时,您的
登录名可能不可见。像这样吗?它('should have splash screen',async()=>{wait expect(element(by.id('splash'))).tobeviible();waitFor expect(element(by.id('login'))).tobeviible();是的,当我将expect改为waitFor谢谢你时,它起作用了