testing-library / webdriverio-testing-library

🕷️ Simple and complete WebdriverIO DOM testing utilities that encourage good testing practices.
16 stars 14 forks source link

WebdriverIO cannot refetch selected elements #11

Closed ohaibbq closed 3 years ago

ohaibbq commented 3 years ago

Our tests fail when trying to click elements that need to be re-fetched as a result of stale element exceptions. WebdriverIO attempts to build a list of selectors to re-locate the element, but elements selected by @testing-library/webdriverio have no selectors associated.

Here is a failing test-case that is borrowed from WebdriverIO:

  it('can refetch an element', async () => {
    const {getByText} = setupBrowser(browser)

    const button = await getByText('Unique Button Text');

    expect(JSON.stringify(button)).toBe(JSON.stringify(await refetchElement(button, "click")))
  })
[chrome 90.0.4430.212 mac os x #0-1] 1) queries can refetch an element
[chrome 90.0.4430.212 mac os x #0-1] invalid selector: No selector specified
  (Session info: chrome=90.0.4430.212)
olivierwilkinson commented 3 years ago

Hi there, sorry for not responding sooner!

I have been working on this in the background and have raised a PR that I hope will fix the problem. It adds SimmerJS to the project to create a unique selector for the elements found by dom-testing-library, then those selectors can be used to create a WebdriverIO.Element instead of using WebElement JSONs directly. This seems to be a fairly reliable solution that is being employed by nigthwatch-testing-library.

Let me know if it fixes your tests also and then I'll close this issue 😄

Edit: the fix has been released in v2.1.2. Since it was passing the failing test-case I figured it was a safe bet but I'm going to leave the issue open so you can let me know if you are still having problems. 👍

olivierwilkinson commented 3 years ago

I'm going to close this issue since I think it's resolved. @ohaibbq let me know if you are still finding problems and I will reopen it 😄