iOS:两次运行相同测试后出现 Earlgrey/Detox 错误

Posted

技术标签:

【中文标题】iOS:两次运行相同测试后出现 Earlgrey/Detox 错误【英文标题】:iOS: Earlgrey/Detox error after running the same test twice 【发布时间】:2018-05-06 18:00:09 【问题描述】:

两次运行相同的测试第二次失败。

复制步骤:

此测试通过:

describe('Login', () => 
  beforeEach(async () => 
    await device.reloadReactNative();
  );

  it('should not login', async () => 
    await waitFor(element(by.id('welcome')))
      .toBeVisible()
      .withTimeout(5000);

    await element(by.id('EmailField')).clearText();
    await element(by.id('EmailField')).typeText('wronggmail.com');
    await element(by.id('PasswordField')).clearText();
    await element(by.id('PasswordField')).typeText('wrongpass');

    await element(by.id('LoginButton')).tap();

    await waitFor(element(by.id('Home')))
      .toBeNotVisible()
      .withTimeout(10000);
  );
);

这失败了:

describe('Login', () => 
  beforeEach(async () => 
    await device.reloadReactNative();
  );

  it('should not login', async () => 
    await waitFor(element(by.id('welcome')))
      .toBeVisible()
      .withTimeout(5000);

    await element(by.id('EmailField')).typeText('wronggmail.com');
    await element(by.id('PasswordField')).typeText('wrongpass');

    await element(by.id('LoginButton')).tap();

    await waitFor(element(by.id('Home')))
      .toBeNotVisible()
      .withTimeout(10000);
  );

  it('should not login', async () => 
    await waitFor(element(by.id('welcome')))
      .toBeVisible()
      .withTimeout(5000);

    await element(by.id('EmailField')).typeText('wronggmail.com');
    await element(by.id('PasswordField')).typeText('wrongpass');

    await element(by.id('LoginButton')).tap();

    await waitFor(element(by.id('Home')))
      .toBeNotVisible()
      .withTimeout(10000);
  );
);

Detox、Node、Device、Xcode 和 macOS 版本

$ yarn list --depth=0 | grep 'detox@\| jest@'
├─ detox@5.10.0
├─ jest@21.2.1

$ node --version
v8.9.0

$ xcodebuild -version
Xcode 9.1
Build version 9B55

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.12.6
设备:iPhone 6 ios 11.1(模拟器)

设备和详细排毒日志

$ npm run test-e2e

> myRN@0.0.1 test-e2e /Users/gianfranco/temp/myRN
> jest e2e --setupTestFrameworkScriptFile=./e2e/init.js --bail

 server listening on localhost:51830...
 : Launching ...
6: The stdout and stderr logs were recreated, you can watch them with:
        tail -F $HOME/Library/Developer/CoreSimulator/Devices/C8A0B6F9-5751-4C97-8069-0288C7F928B8/data/tmp/detox.last_launch_app_log.out,err
 FAIL  e2e/Login.spec.js (15.641s)
  Login
    ✓ should not login (7616ms)
    ✕ should not login (1639ms)

  ● Login › should not login

    Error: An action failed. Please refer to the error trace below.
    Exception with Action: 
      "Action Name" : "Clear text",
      "Element Matcher" : "(((respondsToSelector(accessibilityIdentifier) && accessibilityID('EmailField')) && !(kindOfClass('RCTScrollView'))) || (kindOfClass('UIScrollView') && ((kindOfClass('UIView') || respondsToSelector(accessibilityContainer)) && ancestorThatMatches(((respondsToSelector(accessibilityIdentifier) && accessibilityID('EmailField')) && kindOfClass('RCTScrollView'))))))"
    

    Error Trace: [
      
        "Description" : "First responder [F] of element [E] does not conform to UITextInput protocol.",
        "Description Glossary" :     
          "F" : "<RCTRootView: 0x7fd5b7c13d90; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x60800003da40>>",
          "E" : "<RCTUITextField: 0x7fd5b8876000; baseClass = UITextField; frame = (0 0; 375 36); text = 'hello@gmail.com'; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x600000241bf0>; layer = <CALayer: 0x608000238080>>"
        ,
        "Error Domain" : "com.google.earlgrey.ElementInteractionErrorDomain",
        "Error Code" : "2",
        "File Name" : "GREYActions.m",
        "Function Name" : "+[GREYActions grey_actionForTypeText:atUITextPosition:]_block_invoke",
        "Line" : "547"
      
    ]

      at Client._callee8$ (node_modules/detox/lib/client/Client.js:58:19)
      at tryCatch (node_modules/regenerator-runtime/runtime.js:63:40)
      at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:337:22)
      at Generator.prototype.(anonymous function) [as throw] (node_modules/regenerator-runtime/runtime.js:96:21)
      at step (node_modules/detox/lib/client/Client.js:1:836)
      at node_modules/detox/lib/client/Client.js:1:1035
      at tryCallOne (node_modules/promise/lib/core.js:37:12)
      at node_modules/promise/lib/core.js:123:15
      at flush (node_modules/asap/raw.js:50:29)
      at _combinedTickCallback (internal/process/next_tick.js:131:7)
      at process._tickCallback (internal/process/next_tick.js:180:9)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 passed, 2 total
Snapshots:   0 total
Time:        15.713s
Ran all test suites matching /e2e/i.

关于可能是什么问题的任何想法?

【问题讨论】:

不太确定这个但是如何等待该字段在失败的测试中可见:await expect(element(by.id('EmailField'))).toBeVisible();或者在使用 .typeText() 之前尝试使用 .tap()。 @Nemoverflow 就是这样!键盘做了一些奇怪的事情。在typeText() 工作之前做.tap()!非常感谢:) @Nemoverflow 您介意将其发布为答案以便解决此问题吗? 【参考方案1】:

按照要求以答案形式发布此问题。抱歉耽搁了。

在使用 .typeText() 之前尝试使用 .tap()。

[...]
await expect(element(by.id('EmailField'))).toBeVisible();
await element(by.id('EmailField')).tap();
[...]

【讨论】:

【参考方案2】:

确保您已激活键盘 我遇到了这个问题。

在模拟器上点击时,在输入点击时切换键盘。

command + k

【讨论】:

以上是关于iOS:两次运行相同测试后出现 Earlgrey/Detox 错误的主要内容,如果未能解决你的问题,请参考以下文章

Google推出iOS功能性UI测试框架EarlGrey

[转] Google 开源 iOS 应用测试工具:EarlGrey

Google推出iOS功能性UI测试框架EarlGrey

EarlGrey 故障 - “退出第一响应者状态后键盘没有消失”

使用 EarlGrey 2.0 和 Swift 敲击系统警报

在 EarlGrey 中随机选择