cypress-io / cypress

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

Salesforce lightning is not supporting in cypress #18935

Closed satish151994 closed 1 year ago

satish151994 commented 2 years ago

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/?un=satish.mundiganal@gmail.com.sit&pw="---"&startURL=%2F001')
    .then(() => {
    cy.visit('https://test.salesforce.com/?un=satish.mundiganal@gmail.com.sit&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 commented 2 years ago

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

If not then there are several options:

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}"}`);
    });
tit commented 2 years ago

@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 commented 2 years ago

@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 commented 1 year ago

@satish151994 can you check out https://github.com/cypress-io/cypress/issues/24290#issuecomment-1376214221 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 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

Ainda não consigo fazer rodar

AtofStryker commented 1 year ago

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

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

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

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

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.....................