【发布时间】:2019-07-19 09:40:18
【问题描述】:
我在我的 React-Native 项目上运行 detox,只能测试启动画面。初始屏幕转到登录屏幕,但排毒代码不允许我测试此元素。
测试代码:
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,看看它是否有效,因为当 detox 检查视图层次结构时,您的
login可能不可见。 -
这样? it('应该有启动画面', async () => { await expect(element(by.id('splash'))).toBeVisible(); waitFor expect(element(by.id('login'))) .toBeVisible();
-
是的,当我改变期望等待时,这有效,谢谢
-
没有排毒有什么方法可以测试吗?或者我们如何使用 JEST 进行测试?
标签: javascript ios react-native jestjs detox