Skip to content

Instantly share code, notes, and snippets.

@kevinold
Created August 31, 2021 15:52
Show Gist options
  • Save kevinold/ed35b3203f9fcccddb85a97898ce61e1 to your computer and use it in GitHub Desktop.
Save kevinold/ed35b3203f9fcccddb85a97898ce61e1 to your computer and use it in GitHub Desktop.
const { SF_username, SF_password, SF_login_url } = Cypress.env()
describe('Programmatically log in to SF app', () => {
it('makes XHR req & loads dashboard', () => {
Cypress.log({name: 'loginViaOAuth'});
cy.request({
method: 'POST',
url: SF_login_url,
body: {
un: SF_username,
pw: SF_password,
},
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:89.0) Gecko/20100101 Firefox/89.0'
}
}).then((resp) => {
/* we then make this GET req for reference, so parse out what we need-
https://mindful-koala-78jg04-dev-ed.my.salesforce.com/secur/frontdoor.jsp?sid=00D5e000004gjXb%21AQ4AQKUVRjtYzF4KZ3TxMZHKzwUAhccCRLqiyy_ASet8kvcGvpYLwpnIBqxJkO95cjZ8gSXGKy4GPO3Ndp0GSX7LHAzfbgTU&apv=1&allp=1&cshc=e000006atmje000004gjXb&display=page */
const locationParam = resp.allRequestResponses[0]['Response Headers'].location
const parsedUrlObj = new URL(locationParam);
const { sid, cshc } = parsedUrlObj.searchParams
const frontdoorOptions = {
method: 'GET',
url: 'https://mindful-koala-78jg04-dev-ed.my.salesforce.com/secur/frontdoor.jsp',
headers: {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:89.0) Gecko/20100101 Firefox/89.0'
},
qs: {
sid,
cshc,
apv: 1,
allp: 1,
display: 'page',
}
}
cy.request(frontdoorOptions)
})
cy.visit('https://mindful-koala-78jg04-dev-ed.lightning.force.com/lightning/setup/SetupOneHome/home')
cy.get('.slds-truncate').first().should('contain', 'Setup')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment