Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't wait for multiple conditions concurrently due to "Detox has detected multiple interactions taking place simultaneously" #4627

Open
1 task
reuben opened this issue Oct 30, 2024 · 1 comment

Comments

@reuben
Copy link

reuben commented Oct 30, 2024

What happened?

Our end-to-end test has some intermittent issues with downloads failing due to temporary network outages. We want to add mitigation to the E2E test which checks for the download failure and retries it a couple of times, to reduce manual intervention for transient errors. We tried to do the following:

await Promise.race([
  waitFor(element(by.id('retry-download-button'))).toBeVisible().withTimeout(10 * 1000),
  waitFor(element(by.id('home-screen'))).toBeVisible().withTimeout(10 * 1000),
])

if (download button is visible) {
  retry
}

The goal being to handle the success and failure cases cleanly. But this triggers the following error introduced in #3003:

Detox has detected multiple interactions taking place simultaneously. Have you forgotten to apply an await over one of the Detox actions in your test code?

What was the expected behaviour?

First waitFor call to timeout settles the Promise.race call, mitigation only gets applied if needed. Maybe the error message should only be checking for actual interactions, and not expectations such as waitFor().toBeVisible().

Was it tested on latest Detox?

  • I have tested this issue on the latest Detox release and it still reproduces.

Help us reproduce this issue!

No response

In what environment did this happen?

Detox version: 20.22.2
React Native version: 0.69.4
Has Fabric (React Native's new rendering system) enabled: no
Node version: v18
Test-runner (select one): jest

Detox logs

No response

Device logs

No response

More data, please!

No response

@DigitalZebra
Copy link

This is expected behavior and I doubt Detox will change to support parallel assertions like this.
There's other approaches you can take, though. Due to Detox network synchronization you probably don't need the wait(...) - you could instead check if the retry download button is visible in a try/catch and loop accordingly:

async function homeLoaded() {
  try {
    await expect(element(by.id('home-screen'))).toBeVisible()
    return true
  }
  catch {
    await expect(element(by.id('retry-download-button'))).toBeVisible()
    return false
  }
}

// somewhere in a test or utility function
let count = 0;
let result = await homeLoaded()

while (!result && count < 3) {
  await element(by.id('retry-download-button')).tap()
  result = await homeLoaded()
  count++;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants