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

WaitFor fails for web element #4522

Open
2 tasks done
alexandravychytill opened this issue Jul 4, 2024 · 4 comments
Open
2 tasks done

WaitFor fails for web element #4522

alexandravychytill opened this issue Jul 4, 2024 · 4 comments

Comments

@alexandravychytill
Copy link

alexandravychytill commented Jul 4, 2024

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?

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

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
Copy link
Author

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
Copy link
Contributor

asafkorem commented Jul 10, 2024

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
Copy link

@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)

Copy link

github-actions bot commented Oct 9, 2024

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!

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

4 participants