wix / Detox

Gray box end-to-end testing and automation framework for mobile apps
https://wix.github.io/Detox/
MIT License
11.21k stars 1.92k forks source link

WaitFor fails for web element #4522

Open alexandravychytill opened 4 months ago

alexandravychytill commented 4 months ago

What happened?

await waitFor(web.element(by.web.xpath("//a[@class='pcc-client-content-feed__panel-wrapper-title-link' and contains(text(), 'Following')]"))).toBeVisible().withTimeout(5000);

--> [object Object] is not a Detox matcher. More about Detox matchers here: https://wix.github.io/Detox/docs/api/matchers

What was the expected behaviour?

Waiter function should work and not through bug

Was it tested on latest Detox?

Did your test throw out a timeout?

Help us reproduce this issue!

No response

In what environment did this happen?

Detox version: 20.20.1 React Native version: 0.72.0 Has Fabric (React Native's new rendering system) enabled: yes Node version: >=16 Device model: iPhone 15 iOS version: 17.2 macOS version: 14.4 Xcode version: 15.2 Test-runner (select one): jest

Detox logs

Detox logs ``` [object Object] is not a Detox matcher. More about Detox matchers here: https://wix.github.io/Detox/docs/api/matchers ```

Device logs

Device logs ``` paste your device.log here! ```

More data, please!

No response

alexandravychytill commented 4 months ago

Is there any other method to wait for element till it exist? Or can this be fixed for web view elements, to work as well with waitfor() ?

asafkorem commented 3 months ago

Hey @alexandravychytill, unfortunately there's no wait-for API for Web elements in Detox, this is not valid API usage (however.. contributions are welcome!) You can do some async-await sleep before the action (await new Promise(r => setTimeout(r, 2000));)

MadSandwich commented 1 month ago

@alexandravychytill - You may use such function, to wait for web elements. I use such and work pretty fine for me: It uses basic timeout function + detox element check state: toExist()

  static async pause(value: number = 30000) {
    return new Promise(resolve => {
      setTimeout(resolve, value)
    })
  }
private async waitForWebElement(webElement: Detox.IndexableMaybeSecuredWebElement & Detox.SecuredWebElementFacade, maxWaitTime = 30000) {
    const startTime = Date.now()

    while (Date.now() - startTime < maxWaitTime) {
      try {
        await expect(webElement).toExist()
        await Helper.pause(1000)
        return
      } catch (error) {
        if (Date.now() - startTime >= maxWaitTime) {
          throw error
        }
        await Helper.pause(100)
      }
    }
  }
    const loginInput = web.element(by.web.id('Login'))
    await this.waitForWebElement(loginInput)
github-actions[bot] commented 3 weeks ago

Hello! We appreciate you bringing this issue to our attention. It looks like this could be a valuable addition or fix to our project. We believe that this feature would benefit greatly from contributions from the community, even from first-time contributors.

If you're interested in contributing to this feature, please take a look at our contribution guide. It has all the information you need to know about how to submit a pull request and contribute to our project.

You're also welcome to join our Discord server and discuss this feature with the collaborators or other contributors under the channel 'contributions'.

Please feel free to reach out to us if you have any questions, or need help with anything. We appreciate your feedback and look forward to working with you!