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

Selector regression with upgrade from 3.5.8 to 3.5.11 #4139

Closed
cjhille opened this issue Jan 15, 2024 · 16 comments · Fixed by #4141
Closed

Selector regression with upgrade from 3.5.8 to 3.5.11 #4139

cjhille opened this issue Jan 15, 2024 · 16 comments · Fixed by #4141
Labels

Comments

@cjhille
Copy link
Contributor

cjhille commented Jan 15, 2024

I encountered several regressions when trying to upgrade codeceptjs from 3.5.8 to 3.5.11. Selector that worked with 3.5.8 do not work with 3.5.11.

What do you get instead?

ERROR! Unsupported pseudo :last-of-type. Example selector that is now broken:

lastInputRow: '[data-testid="field-definitions-container"] > *:last-of-type',

I looked through the dependencies. The dependency convert-cssxpath/src/converter.js: throws the error. Likely the same issue as mentioned in slack.

`locator.all: DOMException: Failed to execute 'evaluate' on 'Document': The string '[contains(., 'Delete')]' is not a valid XPath expression. The selector is:

  deleteModal: {
    deleteButton: locate(".p-confirm-popup:last-of-type button").withText("Delete")
  },

Once I remove :last-of-type: the selector works again, so this may just be the same as the first with a different point of failure.

locator.all: DOMException: Failed to execute 'evaluate' on 'Document': The string '//li[@role="option"]//*[@data-testid="date"][ancestor::]' is not a valid XPath expression.. Locator is:

locate(`li[role="option"] [data-testid="${type}"]`).inside('[data-testid="field-definitions-container"] > *:last-of-type')

Likely also the same issue, but I can't fully verify because this is needed for the suite to continue.

@kobenguyent
Copy link
Collaborator

hi @cjhille thanks for your report! We made a bold move to replace the current lib with https://www.npmjs.com/package/csstoxpath?activeTab=explore for css to xpath convertion as you could see right here #4101

may you help try with 3.x branch to see if issues still occur?

@cjhille
Copy link
Contributor Author

cjhille commented Jan 15, 2024

@kobenguyent could you tag an alpha (or nightly) release for npm? i'll happily take it for a test drive. :)

@kobenguyent
Copy link
Collaborator

@cjhille
Copy link
Contributor Author

cjhille commented Jan 16, 2024

Thank you very much! @kobenguyent. Is "last-of-type" somewhat cursed for xpath conversion? Now i'm getting this:

Error: Could not include object examplePo from module '/dev-local/e2e_tests/pageObjects/examplePo.js'
*-of-type pseudos require a tag context
SyntaxError: *-of-type pseudos require a tag context
image

Selector is still

  deleteModal: {
    deleteButton: locate('.p-confirm-popup:last-of-type button').withText('Delete')
  },

@kobenguyent
Copy link
Collaborator

So @cjhille that is unfortunately one of the limitations of the lib https://www.npmjs.com/package/csstoxpath?activeTab=explore#limitations

@cjhille
Copy link
Contributor Author

cjhille commented Jan 16, 2024

@kobenguyent Oh, I see. Thank you for pointing me toward this.

Sadly, this is not the only caveat of the new library. 🥲 Tracking back the issue, I see that the reason for switching was #3563. It is great to have that fixed, but I don't think the benefit of this outweighs the drawbacks introduced regressions (and future limitations) by the new library. Would you consider a rollback? I assume that not too many projects are upgrading to the latest codeceptjs version right away, and many more projects will find their selectors broken in the coming weeks.

@kobenguyent
Copy link
Collaborator

hey @cjhille thinking of a hybrid solution for this.
I hope that would resolve our issue
Test build: https://www.npmjs.com/package/codeceptjs/v/3.5.12-beta.2
PR: #4141

@cjhille
Copy link
Contributor Author

cjhille commented Jan 16, 2024

@kobenguyent Nice, wouldn't have thought of that ^^

Oddly, it still goes down the code path to the new lib for this locator:

deleteButton: locate('.p-confirm-popup:last-of-type button').withText('Delete')

Leading to:
SyntaxError: *-of-type pseudos require a tag context

@kobenguyent
Copy link
Collaborator

@kobenguyent Nice, wouldn't have thought of that ^^

Oddly, it still goes down the code path to the new lib for this locator:


deleteButton: locate('.p-confirm-popup:last-of-type button').withText('Delete')

Leading to:

SyntaxError: *-of-type pseudos require a tag context

I'm curious if that is the locator before the lib changed? Cause I remembered the old lib doesn't work with hyphen in locator.

@cjhille
Copy link
Contributor Author

cjhille commented Jan 16, 2024

Yes, that locator works with 3.5.8.

@kobenguyent
Copy link
Collaborator

So that locator didn't have the issue #3563?

@cjhille
Copy link
Contributor Author

cjhille commented Jan 16, 2024

yes, just tested this in isolation
image

@kobenguyent
Copy link
Collaborator

Thank you for your input. I understood the problem now. Thinking a nice solution for now.

@kobenguyent
Copy link
Collaborator

Soooo, another try, I hope we could resolve this this time. I could not think of any better solution right now but this hybrid approach would be a cheap and fast way right now.

We will check the locator and load either the old one which is being used until 3.5.8 css-to-xpath or the new one csstoxpath.

css-to-xpath: old lib, which works perfectly unless you have hyphen in locator. (#3563)
csstoxpath: new lib, to solve the issue locator with hyphen

Test build: https://www.npmjs.com/package/codeceptjs/v/3.5.12-beta.3

@cjhille
Copy link
Contributor Author

cjhille commented Jan 19, 2024

After some layer 8 errors on my side, I'm positively certain that this PR fixes the regression. Thank you, @kobenguyent, for your patience.

@Horsty80
Copy link
Contributor

Soooo, another try, I hope we could resolve this this time. I could not think of any better solution right now but this hybrid approach would be a cheap and fast way right now.

We will check the locator and load either the old one which is being used until 3.5.8 css-to-xpath or the new one csstoxpath.

css-to-xpath: old lib, which works perfectly unless you have hyphen in locator. (#3563) csstoxpath: new lib, to solve the issue locator with hyphen

Test build: https://www.npmjs.com/package/codeceptjs/v/3.5.12-beta.3

I confirm the beta 3.5.12 fix issue on selector that appears in 3.5.10

In 3.5.9 simple action like I.click("My anwesome link") is working

With 3.5.10 & 3.5.11 this action doesn't work.

Fixed with beta, hope it can be release soon 🤞

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

Successfully merging a pull request may close this issue.

3 participants