使用disableSynchroniztion

时间:2019-07-02 17:48:45

标签: ios react-native testing mobile detox

我有一个使用WebView登录到应用程序的测试(通过使用带有按钮+ injectedJavaScript的文本输入来以骇客的方式完成,因为不支持WebView工具)。

出现问题是因为WebView内部的登录操作异步发生并中断了Detox同步,因此我必须自己使用disableSynchronizationenableSynchronization手动进行管理。 登录后,我有一个堆栈过渡动画(从react-navigation转到新屏幕),并且需要按该屏幕上的按钮才能继续。但是,“排毒”仍然无法与该屏幕同步,因此我正在使用水龙头在禁用同步的情况下按下按钮。

这是问题发生的地方,轻击并不总是起作用,并且在disableSynchronization调用之后执行的任何操作都在50%的时间内失败并超时。这使测试变得不稳定并且几乎没有用

任何人都可以推荐解决方法或知道问题出在哪里吗?

环境 排毒:12.10.3。 React Native:0.59.8 节点:v11.7.0 设备:iOS模拟器(iPhone 8) 操作系统:iOS

我尝试在点击按钮之前和之后禁用和启用同步,但是这样做没有帮助,实际上使测试失败并带有超时。

我的登录方法的代码:

export const loginAs = async (userID) => {
  await element(by.id('introLoginBtn')).tap();
  await expect(element(by.id('loginScreen'))).toBeVisible();

  const userIdInput = element(by.id('testUserIdInput'));
  await userIdInput.tap();
  await userIdInput.typeText(userID);
  await element(by.id('testLoginBtn')).tap();

  // NOTE: WebView login breaks synchronization see 
  // https://github.com/wix/Detox/blob/master/docs/Troubleshooting.Synchronization.md
  await device.disableSynchronization();

  // Waiting for the element to be visible
  await waitFor(element(by.id('acceptTermsBtn'))).toBeVisible().withTimeout(9000);

  // This does not work consistently
  await element(by.id('acceptTermsBtn')).tap();

  await device.enableSynchronization();
};

使用--debug-synchronization 200进入调试控制台时:

detox[33941] INFO:  [actions.js] Sync Timer: Tracking Timer <__NSCFTimer: 0x600003e6de00>
detox[33941] INFO:  [actions.js] Sync Timed: performSelector @selector(removeInactiveFingerTips) on DTXTouchVisualizerWindow
detox[33941] INFO:  [actions.js] Sync Timed: animateWithDuration:delay:options:animations:completion:
detox[33941] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[33941] INFO:  [actions.js] Sync App State: undefined
detox[33941] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[33941] INFO:  [actions.js] Sync Timed: performSelector @selector(removeFromSuperview) on COSTouchSpotView
detox[33941] INFO:  [actions.js] Sync Timed: animateWithDuration:delay:options:animations:completion:
detox[33941] INFO:  [actions.js] Sync Timed: performSelector @selector(removeInactiveFingerTips) on DTXTouchVisualizerWindow
detox[33941] INFO:  [actions.js] Sync Timed: animateWithDuration:delay:options:animations:completion:
detox[33941] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[33941] INFO:  [actions.js] Sync App State: undefined
detox[33941] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[33941] INFO:  [actions.js] Sync Timed: performSelector @selector(removeInactiveFingerTips) on DTXTouchVisualizerWindow
detox[33941] INFO:  [actions.js] Sync Timed: performSelector @selector(removeFromSuperview) on COSTouchSpotView
detox[33941] INFO:  [actions.js] Sync Timed: animateWithDuration:delay:options:animations:completion:
detox[33941] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[33941] INFO:  [actions.js] Sync App State: undefined
detox[33941] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[33941] INFO:  [actions.js] Sync Timed: performSelector @selector(removeInactiveFingerTips) on DTXTouchVisualizerWindow
detox[33941] INFO:  [actions.js] Sync Timed: performSelector @selector(removeFromSuperview) on COSTouchSpotView
detox[33941] INFO:  [actions.js] Sync WXAnimatedDisplayLinkIdlingResource: undefined
detox[33941] INFO:  [actions.js] Sync App State: undefined
detox[33941] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[33941] INFO:  [actions.js] Sync Timed: performSelector @selector(removeInactiveFingerTips) on DTXTouchVisualizerWindow
detox[33941] INFO:  [actions.js] Sync WXAnimatedDisplayLinkIdlingResource: undefined
detox[33941] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[33941] INFO:  [actions.js] Sync WXAnimatedDisplayLinkIdlingResource: undefined
detox[33941] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[33941] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[33941] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[33941] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[33941] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[33941] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers
detox[33941] INFO:  [actions.js] Sync Dispatch Queue: com.apple.main-thread
detox[33941] INFO:  [actions.js] Sync JavaScript Timers: Javascript Timers

最后三行重复直到测试超时。

并使用launchArgs: { 'detoxPrintBusyIdleResources': 'YES' }启动并运行xcrun simctl spawn booted log stream --level debug --style compact --predicate "category=='EarlGreyStatistics'"后:

Error from getpwuid_r: 0 (Undefined error: 0)
Filtering the log data using "category == "EarlGreyStatistics""

1 个答案:

答案 0 :(得分:0)

我遇到的问题确实是由动画所引起的,该动画在无限循环中运行,如Leo Nathan所述。

我有一个屏幕安装在react-navigation的堆栈导航器中的当前屏幕下方。使用reset卸载堆栈(以及无尽的动画屏幕)解决了该问题。