仅排毒测试启动画面 [英] Detox only testing Splash Screen

查看:100
本文介绍了仅排毒测试启动画面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在React-Native项目上运行排毒,并且只能测试启动屏幕.初始屏幕转到登录屏幕,但排毒代码不允许我测试此元素.

I am running detox on my React-Native project and can only test the splash screen. The splash screen goes to a Login Screen but the detox code will not allow me to test this element.

测试代码:

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"
      }
    ]

运行不测试登录组件时,第一个测试通过

The first test passes when it runs not testing the login component

推荐答案

在屏幕上渲染需要花费时间.您可以使用排毒提供的waitFor属性.

It takes time items to render on the screen. You can use the waitFor property that detox provides.

在大多数情况下,测试应与应用程序自动同步.当同步无法正常工作时,您可以使用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.

您可以在中阅读有关使用waitFor的更多信息.文档.

You can read more about using waitFor in the documentation.

注意:每个waitFor调用都必须使用withTimeout()设置超时.调用waitFor而不设置超时将无济于事.

NOTE: Every waitFor call must set a timeout using withTimeout(). Calling waitFor without setting a timeout will do nothing.

注意:到达超时时,waitFor不会抛出,而是继续到下一行.为了确保您的测试能够按预期工作,请在以下行中添加Expect().

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.

因此,根据文档中的示例,您应该将测试更新为

So based on the example in the documentation you should update your test to be

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()
});

这篇关于仅排毒测试启动画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆