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

Salesforce lightning is not supporting in cypress #18935

Closed
satish151994 opened this issue Nov 16, 2021 · 13 comments
Closed

Salesforce lightning is not supporting in cypress #18935

satish151994 opened this issue Nov 16, 2021 · 13 comments

Comments

@satish151994
Copy link

satish151994 commented Nov 16, 2021

Current behavior

I tried some of the workarounds to open salesforce lightning in cypress, but not success. Could anyone please help or guide is there any configuration setting is needed in salesforce or how i can login into salesforce lightning using cypress script.

Desired behavior

No response

Test code to reproduce

Cypress.Commands.add('login', () => {
    const loginUrl = Cypress.env("salesforce").loginUrl
    const username = Cypress.env("salesforce").username
    const password = Cypress.env("salesforce").password
    cy.request('https://test.salesforce.com/[email protected]&pw="---"&startURL=%2F001')
    .then(() => {
    cy.visit('https://test.salesforce.com/[email protected]&pw=""')
    })
    })

Cypress Version

Cypress package version: 7.4.0 Cypress binary version: 7.4.0 Electron version: 12.0.0-beta.14 Bundled Node version: 14.15.1

Other

No response

@bahunov
Copy link

bahunov commented Nov 17, 2021

@satish151994 - is the login connected to some microsoft login? (AAD) ?

If not then there are several options:

  • in some cases you need to save down some localStorage data after cy.request e.g:
cy.request({
      url: 'your-end-point',
      method: 'POST',
      headers: {
        'content-type': 'application/json'
      },
      body: {
      login:"user@name",
      key:"password",
    },
    }).then((resp) => {
      window.localStorage.setItem('some-auth-tokens', `{"authToken":"${resp.body.data.key}"}`);
    });
  • second option is to login simply through the UI

@tit
Copy link

tit commented Apr 27, 2022

@satish151994 use next code for login

cy.request({
      body: {
        display: 'page',
        hasRememberUn: true,
        height: '1080',
        local: '',
        locale: '',
        login: '',
        loginType: '',
        loginURL: '',
        lt: 'standard',
        oauth_callback: '',
        oauth_token: '',
        pw: Cypress.env('password'),
        qs: '',
        serverid: '',
        startURL: '',
        un: Cypress.env('email'),
        useSecure: true,
        username: Cypress.env('email'),
        width: '2560',
      },
      form: true,
      method: 'POST',
      url: 'https://login.salesforce.com',
    })

    cy.visit('https://org-name.lightning.force.com/')

@lucascruz9494
Copy link

@satish151994 use next code for login

cy.request({
      body: {
        display: 'page',
        hasRememberUn: true,
        height: '1080',
        local: '',
        locale: '',
        login: '',
        loginType: '',
        loginURL: '',
        lt: 'standard',
        oauth_callback: '',
        oauth_token: '',
        pw: Cypress.env('password'),
        qs: '',
        serverid: '',
        startURL: '',
        un: Cypress.env('email'),
        useSecure: true,
        username: Cypress.env('email'),
        width: '2560',
      },
      form: true,
      method: 'POST',
      url: 'https://login.salesforce.com',
    })

    cy.visit('https://org-name.lightning.force.com/')

could you explain how this works? why there are parameters in blank? why do uou use this url https://login.salesforce.com ?

@AtofStryker
Copy link
Contributor

@satish151994 can you check out #24290 (comment) and see if it might solve your issue? You should be able to log in with the API/SOAP programmatically or with cy.origin() on the login page. I also pushed up some sample tests here

@manuelfernandez90
Copy link

manuelfernandez90 commented Jan 20, 2023

@satish151994 To login through the API you can do it by creating a custom command in "commands.js" where you first execute an sfdx command line to get the instanceUrl and the accessToken, and then call the API with these values. You can only do this with an "admin" user and you must have previously installed sfdx-cli (https://www.npmjs.com/package/sfdx-cli).

image

Then you can use cy.login() in your test

@AtofStryker
Copy link
Contributor

I believe this issue is solved with the release of 12.4.0 with the support of experimentalSkipDomainInjection. I am going to close this issue as resolved, but if there are still issues, please let us know!

@Braholka
Copy link

Ainda não consigo fazer rodar

@AtofStryker
Copy link
Contributor

Ainda não consigo fazer rodar (I still can't get it to run)

@Braholka would you be able to share some type of reproduction repository so we can diagnose the issue to see what is happening?

@thsrv
Copy link

thsrv commented Jul 17, 2024

I believe this issue is solved with the release of 12.4.0 with the support of experimentalSkipDomainInjection. I am going to close this issue as resolved, but if there are still issues, please let us know!

@AtofStryker Include it in the cypress config, but I can log in but the test does not advance to the next step. The execution is stuck on a "new url" this problem only happens in Chrome, in Electron it runs normally. It is a requirement in my organization that the tests be in Chrome.

image

@thsrv
Copy link

thsrv commented Jul 17, 2024

I believe this issue is solved with the release of 12.4.0 with the support of experimentalSkipDomainInjection. I am going to close this issue as resolved, but if there are still issues, please let us know!

@AtofStryker Include it in the cypress config, but I can log in but the test does not advance to the next step. The execution is stuck on a "new url" this problem only happens in Chrome, in Electron it runs normally. It is a requirement in my organization that the tests be in Chrome.

image

You can see that it is not redirecting

@AtofStryker
Copy link
Contributor

I believe this issue is solved with the release of 12.4.0 with the support of experimentalSkipDomainInjection. I am going to close this issue as resolved, but if there are still issues, please let us know!

@AtofStryker Include it in the cypress config, but I can log in but the test does not advance to the next step. The execution is stuck on a "new url" this problem only happens in Chrome, in Electron it runs normally. It is a requirement in my organization that the tests be in Chrome.
image

You can see that it is not redirecting

@thsrv I am unable to see that image. Are you able to help me with a reproduction so I can reproduce the issue?

@thsrv
Copy link

thsrv commented Jul 18, 2024

I believe this issue is solved with the release of 12.4.0 with the support of experimentalSkipDomainInjection. I am going to close this issue as resolved, but if there are still issues, please let us know!

@AtofStryker Include it in the cypress config, but I can log in but the test does not advance to the next step. The execution is stuck on a "new url" this problem only happens in Chrome, in Electron it runs normally. It is a requirement in my organization that the tests be in Chrome.
image

You can see that it is not redirecting

@thsrv I am unable to see that image. Are you able to help me with a reproduction so I can reproduce the issue?

@AtofStryker Sorry, the flow I'm testing is that I access Salesforce in the test sandbox, when I enter the username and password, it logs in successfully, but in the log it shows a new url but the redirection does not happen. Execution gets stuck and does not advance to the next step, the test does not fail and remains in a loop. This only happens with Chrome, in the Electron browser it successfully performs all the steps.

![image]Sem título

config

`e2e: {
    baseUrl: process.env.baseUrl,
    experimentalModifyObstructiveThirdPartyCode: true,
    experimentalSkipDomainInjection: ['*.salesforce.com', '*.force.com','*.sandbox.lightning.force.com', '*file.force.com'],
    numTestsKeptInMemory: 0,
    supportFile: "cypress/support/e2e.js",
    experimentalMemoryManagement: true,
    chromeWebSecurity: false,`

method login

`

accessAndLoginSalesforce(user, password){
    cy.visit('/');
    cy.document().its('readyState').should('equal', 'complete');
    cy.get(loginMap.usernameInput).type(user);
    cy.get(loginMap.passwordInput).type(password,{log:false});
    cy.wait(1000);
    cy.get(loginMap.buttonLogin).should('be.visible').click(); 
}

`

next step

   //is accessing an object in the navigation bar
   acessMenuNavBar(item){
        cy.xpath(`//*[@role='navigation']//a[@title='${item}']`).should('be.visible').click({force: true});
        cy.wait(2000);
    }

URL https://xxxx--test.sandbox.my.salesforce.com
new URL of redirection https://ORGXXX--test.sandbox.file.force.com/secur/contentDoor?startURL=https%3A%2F%2ORGXXX--test.sandbox.my.salesforce.com%2.....................

@jennifer-shehane
Copy link
Member

This experimental flag will be made default behavior in Cypress 14 with injectDocumentDomain being false. #30770

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

No branches or pull requests

9 participants