mardi 2 juillet 2019

tap behaviour not consistent on iOS with disableSynchroniztion

I have a test which uses a WebView to login to the application (done in a hacky way by using a text input with a button + injectedJavaScript as WebView instrumentation is not supported).

The problem appears because the login operation inside the WebView happens asynchronously and breaks the Detox synchronization, so I have to synchronize myself manually with disableSynchronization and enableSynchronization. After the login I have a stack transition animation to a new screen (from react-navigation) and I need to press a button on that screen to go further. However Detox still fails to synchronize with that screen so I am using tap to press on the button with synchronization disabled.

This is where the problem happens, the tap doesn't always work, and in 50% of the time just fails with a timeout for any action done after the disableSynchronization call. This makes the tests flaky and pretty much useless

Can anyone recommend a workaround or knows what the problem is?

Environment Detox: 12.10.3. React Native: 0.59.8 Node: v11.7.0 Device: iOS Emulator (iPhone 8) OS: iOS

I tried disabling and enabling the synchronization before and after the tap on the button but it did not help, and in fact made the test fail with a timeout.

The code of my login method:

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

Aucun commentaire:

Enregistrer un commentaire