webdriverio / webdriverio

Next-gen browser and mobile automation test framework for Node.js
http://webdriver.io
MIT License
9.04k stars 2.5k forks source link

[πŸ› Bug]: <title>The locator "someTag"="SomeTxt" is not working since @wdio/local-runner version 8.6.2 (last working version) #10067

Closed alek75 closed 1 year ago

alek75 commented 1 year ago

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

8.6.8

Node.js Version

16.14.0

Mode

Standalone Mode

Which capabilities are you using?

No response

What happened?

Example "div=SomeTxt" or "div*=someTxt" are not working after wdio/local-runner version 8.6.2 (last working version). This is applicable to all tags >>> h1, a, span etc.

The other packages I am using are: "@wdio/cli": "8.6.8", "@wdio/cucumber-framework": "8.6.8", "@wdio/spec-reporter": "8.6.8", "@wdio/local-runner": "8.6.2", "wdio-chromedriver-service": "8.1.1", "wdio-intercept-service": "4.4.0",

As you can see the only downgraded package is "@wdio/local-runner". If I can help you with some other info, please let me know...

UPDATE: In the version 8.6.9 it looks like the case $(h1=someTxt) is fixed but I still have issues using $(h1=someTxt) Also in the following example it looks like none of the locators ("h1=someTxt" or "h1=someTxt") are working properly... var obj1 = $("div") var obj2 = obj1.$("h1*=someTxt")

What is your expected behavior?

No response

How to reproduce the bug.

Just use the locator div=someTxt You can use it with any tags, not only with div...

wdio/local-runner version 8.6.2 (last working version)

Relevant log output

Error: element ("a*=Test Queue 4") still not existing after 15000ms
[chrome 111.0.5563.111 windows #0-0] Error: element ("a*=Test Queue 4") still not existing after 15000ms

Code of Conduct

Is there an existing issue for this?

christian-bromann commented 1 year ago

Duplicate of #10040

alek75 commented 1 year ago

@christian-bromann Since you closed the ticket "as completed" I've expected the issue to be fixed in the newer version... but i guess that's not the case > the issue still persist in "8.6.9"

christian-bromann commented 1 year ago

Based on your description my assumption was that the issue described in #10040 is the same as described in here. If that is not the case please provide a reproducible example, thank you!

alek75 commented 1 year ago

@christian-bromann I've checked #10040. Indeed "h1=someTxt" is fixed, but did you check searching by partial txt? > "h1*=someTxt" < I still have issues with it

Also, we are using these locators not only as this >>> $(h1=someTxt) but also like the following example: var obj1 = $("div") var obj2 = obj1.$("h1=someTxt")

In this case it seems that neither "h1=someTxt" or "h1*=someTxt" are working properly

Thanks

christian-bromann commented 1 year ago

In this case it seems that neither "h1=someTxt" or "h1*=someTxt" are working properly

Do you have a reproducible example?

alek75 commented 1 year ago

Will see what i can do...

Cheers

gjvoosten commented 1 year ago

@christian-bromann While 8.6.9 (through #10046) does indeed solve some of the selector issues that were introduced, we still have failing tests that search for e.g. $("td*=Latitude") so that needs to be addressed. Reproducible example: add this test to webdriverio:

diff --git a/e2e/browser-runner/lit.test.js b/e2e/browser-runner/lit.test.js
index 792007069..db8c74cff 100644
--- a/e2e/browser-runner/lit.test.js
+++ b/e2e/browser-runner/lit.test.js
@@ -138,6 +138,14 @@ describe('Lit Component testing', () => {
             expect(await $('div*=me').getHTML(false)).toBe('Find me')
         })

+        it('fetches inner element by content correctly', async () => {
+            render(
+                html`<div><div><span>Find me</span></div></div>`,
+                document.body
+            )
+            expect(await $('div*=me').getText()).toBe('Find me')
+        })
+
         it('fetches the parent element by content correctly', async () => {
             render(
                 html`<button><span>Click Me!</span></button>`,

go to the e2e directory, run npm run test:browser:lit and watch the test fail.

[Edit: Just for fun, I ran this test against v8.6.0 and there it passes.]

christian-bromann commented 1 year ago

@gjvoosten thanks for providing this great example. I was able to reproduce it. I was able to find $('div=Find me') but not $('div*=me') while it was possible to find $('span*=me'). We could change the selector to:

- .//div[contains(text(), "me")]
+ .//div[contains(text(), "me") or contains(., "me")]

Which could come with other issues, e.g. if you have a lot of nested divs, it will take the most outer div element which can end up not being the element you are looking for. I rather have a more stricter working selector than a loose one.

gjvoosten commented 1 year ago

Hi @christian-bromann! Seeing as this is still part of a patch release (not minor or even major), and the behaviour has changed, many people might be surprised why their tests suddenly started failing with this new webdriverio version. So the safest bet would be to make it behave the same as before. Now if the former behaviour was ill-defined or under-documented, it's okay to change it, but be sure to mark this clearly in the release notes / changelog, as we don't want to make people search for relevant issues to find out what happened (and/or how to fix it).

christian-bromann commented 1 year ago

@gjvoosten make sense, I will add a note to the release notes

gjvoosten commented 1 year ago

@christian-bromann In any case, aside from documenting which exact element gets matched, the main problem is of course that currently the test I described above doesn't find the element at all, so that still needs to be fixed. (And maybe this issue should be reopened until it is?)

Edit: And as per #9992 the preference is for finding the innermost matching element, that test is probably better written as:

diff --git a/e2e/browser-runner/lit.test.js b/e2e/browser-runner/lit.test.js
index 792007069..19161a072 100644
--- a/e2e/browser-runner/lit.test.js
+++ b/e2e/browser-runner/lit.test.js
@@ -138,6 +138,14 @@ describe('Lit Component testing', () => {
             expect(await $('div*=me').getHTML(false)).toBe('Find me')
         })

+        it('fetches inner element by content correctly', async () => {
+            render(
+                html`<div><div><span>Find me</span></div></div>`,
+                document.body
+            )
+            expect(await $('div*=me').getHTML(false)).toBe('<span>Find me</span>')
+        })
+
         it('fetches the parent element by content correctly', async () => {
             render(
                 html`<button><span>Click Me!</span></button>`,

to make this fact clear.

christian-bromann commented 1 year ago

Raised another PR with fixes for this.

alek75 commented 1 year ago

wdio - 8.7.0

HTML example:

<div>
    <span>Test me</span>
</div>

wdio example:

let sample = await $('div=Test') console.log('>>>> ', await sample.getHTML()) Error: Can't call getHTML on element with selector "div=Test" because element wasn't found

@christian-bromann Is this example reproducible? Thanks...

christian-bromann commented 1 year ago

The PR mentioned above is not released yet.