cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
47.45k stars 3.2k forks source link

Unable to access Salesforce Lightning elements by default #29294

Open alexsch01 opened 7 months ago

alexsch01 commented 7 months ago

UPDATE

See https://github.com/cypress-io/cypress/issues/29294#issuecomment-2341558523 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 commented 6 months ago

Same issue on cypress@13.9.0

jennifer-shehane commented 5 months ago

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 commented 4 months ago

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 commented 4 months ago

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

alexsch01 commented 2 months ago

@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 - https://github.com/cypress-io/cypress/issues/29294#issuecomment-2358509846

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

alexsch01 commented 2 months ago

@jennifer-shehane @kathleennaughton

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

kathleennaughton commented 2 months ago

I will try this in the next couple of days. I have project commitments I want to get completed before I get to this.

Regards, Kathleen


From: Alex Schwartz @.> Sent: Monday, September 16, 2024 12:02 PM To: cypress-io/cypress @.> Cc: Kathleen Naughton @.>; Mention @.> Subject: Re: [cypress-io/cypress] Unable to access Salesforce Lightning elements even with {includeShadowDom: true} (Issue #29294)

@jennifer-shehanehttps://github.com/jennifer-shehane @kathleennaughtonhttps://github.com/kathleennaughton

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

— Reply to this email directly, view it on GitHubhttps://github.com/cypress-io/cypress/issues/29294#issuecomment-2353567803, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BI5MBTEBN3UX2AKQOUY2KH3ZW4MKJAVCNFSM6AAAAABF7CGR22VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNJTGU3DOOBQGM. You are receiving this because you were mentioned.Message ID: @.***>

alexsch01 commented 2 months ago

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

alexsch01 commented 2 months ago
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)
        })
    }