【问题标题】:iOS tests fails in Release but works in DebugiOS 测试在 Release 中失败,但在 Debug 中有效
【发布时间】:2019-07-25 20:06:24
【问题描述】:

我刚刚为我的react-native 应用程序做了一小部分测试,它们在iOS - Debug 模式下测试时运行良好。但是当我尝试在iOS - Release 中运行它时,它就失败了,说找不到组件。

我知道需要更多信息,但我不知道如何实际前进。 笔记: - 所有testID 都在<View /> - 我尝试在模拟器打开的情况下运行,应用程序实际上打开了 - 进行了跟踪并且没有太多有用的数据(但层次结构显示没有accessibilityIDtestID

遵循层次结构:

        Cannot find UI Element.
        Exception with Assertion: {
          "Assertion Criteria":  "assertWithMatcher:matcherForSufficientlyVisible(>=0.750000)",
          "Element Matcher":  "((!(kindOfClass('RCTScrollView')) && (respondsToSelector(accessibilityIdentifier) && accessibilityID('WelcomeScreen_Contents'))) || (((kindOfClass('UIView') || respondsToSelector(accessibilityContainer)) && parentThatMatches(kindOfClass('RCTScrollView'))) && ((kindOfClass('UIView') || respondsToSelector(accessibilityContainer)) && parentThatMatches((respondsToSelector(accessibilityIdentifier) && accessibilityID('WelcomeScreen_Contents'))))))",
          "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"
          }
        ]

        Hierarchy: <UIWindow:0x7fb2a5622f30; AX=N; AX.frame={{0, 0}, {414, 896}}; AX.activationPoint={207, 448}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 896}}; opaque; alpha=1>
          |--<RCTRootView:0x7fb2a5620e70; AX=N; AX.frame={{0, 0}, {414, 896}}; AX.activationPoint={207, 448}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 896}}; opaque; alpha=1>
          |  |--<RCTRootContentView:0x7fb2a57c5200; AX=N; AX.label='Welcome! Let's go! Sign in'; AX.frame={{0, 0}, {414, 896}}; AX.activationPoint={207, 448}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 896}}; opaque; alpha=1>
          |  |  |--<RCTView:0x7fb2a558c7a0; AX=N; AX.label='Welcome! Let's go! Sign in'; AX.frame={{0, 0}, {414, 896}}; AX.activationPoint={207, 448}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 896}}; opaque; alpha=1>
          |  |  |  |--<RCTView:0x7fb2a55baaf0; AX=N; AX.label='Welcome! Let's go! Sign in'; AX.frame={{0, 0}, {414, 896}}; AX.activationPoint={207, 448}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 896}}; opaque; alpha=1>
          |  |  |  |  |--<RCTView:0x7fb2a55a6f50; AX=N; AX.label='Welcome! Let's go! Sign in'; AX.frame={{0, 0}, {414, 896}}; AX.activationPoint={207, 448}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 896}}; opaque; alpha=1>
          |  |  |  |  |  |--<RCTView:0x7fb2a5517b40; AX=N; AX.label='Welcome! Let's go! Sign in'; AX.frame={{0, 0}, {414, 896}}; AX.activationPoint={207, 448}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 896}}; opaque; alpha=1>
          |  |  |  |  |  |  |--<RCTView:0x7fb2a5791380; AX=N; AX.label='Welcome! Let's go! Sign in'; AX.frame={{0, 0}, {414, 896}}; AX.activationPoint={207, 448}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 896}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |--<RCTView:0x7fb2a5791070; AX=N; AX.label='Welcome! Let's go! Sign in'; AX.frame={{0, 0}, {414, 896}}; AX.activationPoint={207, 448}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 896}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a5790d60; AX=N; AX.label='Welcome! Let's go! Sign in'; AX.frame={{0, 0}, {414, 896}}; AX.activationPoint={207, 448}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 896}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a5790a50; AX=N; AX.frame={{0, 0}, {414, 88}}; AX.activationPoint={207, 44}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 88}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a5790740; AX=N; AX.frame={{-414, 0}, {414, 88}}; AX.activationPoint={-207, 44}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{-414, 0}, {414, 88}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a579d570; AX=N; AX.frame={{-414, 0}, {414, 88}}; AX.activationPoint={-207, 44}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 88}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a579d260; AX=N; AX.frame={{-414, 44}, {414, 43.5}}; AX.activationPoint={-207, 65.75}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 44}, {414, 43.5}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a578a1b0; AX=N; AX.label='Welcome! Let's go! Sign in'; AX.frame={{0, 0}, {414, 896}}; AX.activationPoint={207, 448}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 896}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a5593d10; AX=N; AX.label='Welcome! Let's go! Sign in'; AX.frame={{0, 0}, {414, 896}}; AX.activationPoint={207, 448}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 896}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a55a5c90; AX=N; AX.label='Welcome! Let's go! Sign in'; AX.frame={{0, 0}, {414, 896}}; AX.activationPoint={207, 448}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 896}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a55d0c60; AX=N; AX.label='Welcome! Let's go! Sign in'; AX.frame={{0, 0}, {414, 896}}; AX.activationPoint={207, 448}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 896}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a55d92f0; AX=N; AX.label='Welcome! Let's go! Sign in'; AX.frame={{0, 44}, {414, 818}}; AX.activationPoint={207, 453}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 44}, {414, 818}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a55d0950; AX=N; AX.label='Sign in'; AX.frame={{0, 816}, {414, 36}}; AX.activationPoint={207, 834}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 772}, {414, 36}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a55cd670; AX=Y; AX.id='Touchable'; AX.label='Sign in'; AX.frame={{0, 816}, {414, 36}}; AX.activationPoint={207, 834}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 36}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |--<RCTTextView:0x7fb2a55b3040; AX=Y; AX.label='Sign in'; AX.frame={{0, 816}, {414, 36.5}}; AX.activationPoint={207, 834.25}; AX.traits='UIAccessibilityTraitStaticText'; AX.focused='N'; frame={{0, 0}, {414, 36.5}}; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a55cd360; AX=N; AX.label='Welcome! Let's go!'; AX.frame={{0, 44}, {414, 772}}; AX.activationPoint={207, 430}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {414, 772}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a55cd050; AX=N; AX.frame={{207, 500}, {0, 316}}; AX.activationPoint={207, 658}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{207, 456}, {0, 316}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a55ccd40; AX=N; AX.label='Let's go!'; AX.frame={{147, 460}, {120, 40}}; AX.activationPoint={207, 480}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{147, 416}, {120, 40}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a55cca30; AX=Y; AX.id='Touchable'; AX.label='Let's go!'; AX.frame={{147, 460}, {120, 40}}; AX.activationPoint={207, 480}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 0}, {120, 40}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |--<RCTTextView:0x7fb2a55cc800; AX=Y; AX.label='Let's go!'; AX.frame={{164, 471}, {86, 18.5}}; AX.activationPoint={207, 480.25}; AX.traits='UIAccessibilityTraitStaticText'; AX.focused='N'; frame={{17, 11}, {86, 18.5}}; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |--<RCTTextView:0x7fb2a55cc210; AX=Y; AX.label='Answer two quick questions to get started.'; AX.frame={{68, 379.5}, {278, 50.5}}; AX.activationPoint={207, 404.75}; AX.traits='UIAccessibilityTraitStaticText'; AX.focused='N'; frame={{68, 335.5}, {278, 50.5}}; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a55cbd20; AX=N; AX.label='Welcome to '; AX.frame={{97.5, 44}, {219, 336}}; AX.activationPoint={207, 212}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{97.5, 0}, {219, 336}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |--<RCTView:0x7fb2a55cba10; AX=N; AX.label='Welcome to '; AX.frame={{97.5, 327}, {219, 33}}; AX.activationPoint={207, 343.5}; AX.traits='UIAccessibilityTraitNone'; AX.focused='N'; frame={{0, 283}, {219, 33}}; opaque; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |--<RCTImageView:0x7fb2a55cb730; AX=N; AX.id='/Users/.../Library/Developer/CoreSimulator/Devices/4FF22CAE-8C08-4FA8-8CB7-DEC31EB77737/data/Containers/Data/Application/608DC539-4BB6-4C2D-934E-98C4863ED4D1/Library/Application Support/CodePush/76158f1b9b351e2881c905cc31e6f30ea33a2e52829f92e0b092dcc45be9cfde/CodePush/assets/app/assets/images/logo@2x.png'; AX.frame={{258.5, 333}, {58, 21}}; AX.activationPoint={287.5, 343.5}; AX.traits='UIAccessibilityTraitImage'; AX.focused='N'; frame={{161, 6}, {58, 21}}; alpha=1>
          |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |--<RCTTextView:0x7fb2a55cb500; AX=Y; AX.label='Welcome to '; AX.frame={{97.5, 327}, {162, 33.5}}; AX.activationPoint={178.5, 343.75}; AX.traits='UIAccessibilityTraitStaticText'; AX.focused='N'; frame={{0, 0}, {162, 33.5}}; alpha=1>

           9 |
          10 |   it('WelcomeScreen: Loaded', async () => {
        > 11 |     await expect(element(by.id('WelcomeScreen_Contents'))).toBeVisible();
             |                                                            ^
          12 |   });

我还尝试了一些其他值:

        <View
          style={styles.contents}
          testID="WelcomeScreen_Contents1"
          accessibilityHint="WelcomeScreen_Contents2"
          accessibilityLabel="WelcomeScreen_Contents3"
        >

还有以下测试:

  it('WelcomeScreen: Loaded 1', async () => {
    await expect(element(by.id('WelcomeScreen_Contents1'))).toBeVisible();
  });

  it('WelcomeScreen: Loaded 2', async () => {
    await expect(element(by.id('WelcomeScreen_Contents2'))).toBeVisible();
  });

  it('WelcomeScreen: Loaded 3', async () => {
    await expect(element(by.id('WelcomeScreen_Contents3'))).toBeVisible();
  });

package.json 中的排毒配置

  "detox": {
    "configurations": {
      "iphonexr": {
        "binaryPath": "ios/build/xxx/Build/Products/Release-iphonesimulator/xxx.app",
        "build": "RCT_NO_LAUNCH_PACKAGER=1 xcodebuild -quiet -workspace ios/xxx.xcworkspace -UseNewBuildSystem=NO -configuration Release -scheme xxx -derivedDataPath ios/build/xxx -sdk iphonesimulator",
        "type": "ios.simulator",
        "name": "iPhone Xʀ"
      },
      "iphonese": {
        "binaryPath": "ios/build/xxx/Build/Products/Release-iphonesimulator/xxx.app",
        "build": "RCT_NO_LAUNCH_PACKAGER=1 xcodebuild -quiet -workspace ios/xxx.xcworkspace -UseNewBuildSystem=NO -configuration Release -scheme xxx -derivedDataPath ios/build/xxx -sdk iphonesimulator",
        "type": "ios.simulator",
        "name": "iPhone SE"
      }
    },
    "test-runner": "jest"
  }
  }

【问题讨论】:

  • 你能从 package.json 分享你的排毒配置吗?
  • @vk.4884 抱歉耽搁了,刚刚更新了信息。问题似乎有点断断续续...
  • 这很奇怪,因为我也尝试了“by.label”,但它也失败了!
  • 看看你的层次结构。那里不存在任何可访问性值。这意味着要么它们正在被 RN 优化,要么你的应用程序中存在某种错误。
  • 也可能是 RN 正在做一些视图扁平化:twitter.com/shergin/status/1058393187079704576“视图”不是你通常会测试的东西。也许尝试测试内容,而不是包装视图。

标签: detox


【解决方案1】:

经过几个小时的调试,我发现问题是: - CodePush 覆盖我的更改 - RN 的视图扁平化 (https://twitter.com/shergin/status/1058393187079704576)

我添加了一个小检查,以便我可以禁用 CodePush for Test 构建,它现在可以正常工作。

【讨论】:

  • 请注意,Apple 一直在打击使用 CodePush 和类似技术的应用程序。我建议不要使用它。
  • @LeoNatan 我不确定你从哪里得到的信息,但它不正确。 Apple 开发者协议第 3.3.2 节明确允许 CodePush 和其他解释代码部署技术。
  • 您能否发布您的小支票以及您如何禁用代码推送以进行测试构建?
  • 我创建了一个CodePushify 组件。在 E2E 上,它不添加 CodePush。 @BoKKeR
猜你喜欢
  • 1970-01-01
  • 2019-05-18
  • 2019-12-28
  • 1970-01-01
  • 2020-08-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多