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

Unable to access Salesforce Lightning elements by default #29294

Open
alexsch01 opened this issue Apr 9, 2024 · 11 comments
Open

Unable to access Salesforce Lightning elements by default #29294

alexsch01 opened this issue Apr 9, 2024 · 11 comments
Labels
stage: needs investigating Someone from Cypress needs to look at this type: bug

Comments

@alexsch01
Copy link
Contributor

alexsch01 commented Apr 9, 2024

UPDATE

See #29294 (comment) for workaround

Current behavior

image

Test code to reproduce

git clone https://github.com/alexsch01/cypress-repro-salesforce
cd cypress-repro-salesforce
npm install
npx cypress run --headed --no-exit

Cypress Version

13.7.0

Node version

v18.13.0

Operating System

Windows 10.0.19045.4170

Other

Repo for Cypress test: https://github.com/alexsch01/cypress-repro-salesforce

@alexsch01
Copy link
Contributor Author

Same issue on [email protected]

@jennifer-shehane jennifer-shehane added the topic: shadow dom Issues when testing shadow dom label Jun 18, 2024
@jennifer-shehane
Copy link
Member

I confirmed this is happening and reproducible given the example. There's this call, where we call into jquery with the selection and the 'scope', where it's failing within jquery in that call. https://github.com/cypress-io/cypress/blob/remove-json-lint/packages/driver/src/cy/commands/querying/querying.ts#L198

Screenshot 2024-06-18 at 1 12 15 PM

I have a hunch that maybe we're not finding all the shadow dom to pass through the scope here? We're using a pretty old version of jquery here also that may not be helping.

@kathleennaughton
Copy link

I am also struggling with not being able to access Salesforce Lightning elements from my Cypress tests. I can interact with the elements within the Cypress test runner but any method and configuration I've tried, I get "timeout" because the element is not found. Is there any hope that this will be addressed soon?

@alexsch01
Copy link
Contributor Author

@jennifer-shehane
I just confirmed this still happens with Cypress 13.13.1

  • it updated "jquery from 3.1.1 to 3.4.1"

@alexsch01
Copy link
Contributor Author

alexsch01 commented Sep 10, 2024

@jennifer-shehane @kathleennaughton

This actually gets around the issue

// Do the login to salesforce above the fix

cy.then(() => {
    const doc = top.document.querySelectorAll(`iframe[id="Your project: 'Test Project'"]`)[0].contentDocument
    doc.querySelector = document.querySelector.bind(doc)
    doc.querySelectorAll = document.querySelectorAll.bind(doc)
})
cy.get('[title="Controller"]').click()

More fixes - #29294 (comment)

^ I also notice that includeShadowDom: true can be removed from cypress.config.js and it still works!

@alexsch01
Copy link
Contributor Author

@jennifer-shehane @kathleennaughton

Can confirm that the above fix actually works on a real Salesforce page

@kathleennaughton
Copy link

kathleennaughton commented Sep 17, 2024 via email

@alexsch01 alexsch01 changed the title Unable to access Salesforce Lightning elements even with {includeShadowDom: true} Unable to access Salesforce Lightning elements by default Sep 17, 2024
@alexsch01
Copy link
Contributor Author

Please remove topic: shadow dom - this isn't really that

@alexsch01
Copy link
Contributor Author

alexsch01 commented Sep 18, 2024

fixSalesforce() {
        // Workaround for Salesforce breaking "cy.get" with most lightning elements
        cy.document().then(doc => {
            doc.querySelector = document.querySelector.bind(doc)
            doc.querySelectorAll = document.querySelectorAll.bind(doc)
            doc.getElementById = document.getElementById.bind(doc)
            doc.getElementsByClassName = document.getElementsByClassName.bind(doc)
            doc.getElementsByName = document.getElementsByName.bind(doc)
            doc.getElementsByTagName = document.getElementsByTagName.bind(doc)
            doc.getElementsByTagNameNS = document.getElementsByTagNameNS.bind(doc)
            doc.getRootNode = document.getRootNode.bind(doc)
        })
    }

@maortiz21
Copy link

Any update on this? I have struggling with this for so long

@jennifer-shehane
Copy link
Member

@alexsch01 This workaround makes a lot of sense to me. Salesforce does the absolute strangest things we have ever seen on a website. Nearly overwriting all default methods. So many things don’t function right when querying into their website.

@jennifer-shehane jennifer-shehane added type: bug and removed topic: shadow dom Issues when testing shadow dom labels Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: needs investigating Someone from Cypress needs to look at this type: bug
Projects
None yet
Development

No branches or pull requests

4 participants