loud-dinner-94998
02/17/2023, 2:43 PMbefore() hook that does the following:
before(() => {
cy.restoreLocalStorage();
cy.loginAndRedirect();
cy.saveLocalStorage();
This is `loginAndRedirect()`:
Cypress.Commands.add('loginAndRedirect', () => {
Cypress.log({ name: 'log in with Auth0' })
const authVariables = getAuth0Variables();
const username = authVariables.username;
const password = authVariables.password;
const audience = authVariables.audience;
const scope = 'openid profile email'
const client_id = authVariables.client_id;
const client_secret = authVariables.client_secret;
return cy.request({
method: 'POST',
url: `${authVariables.url.replace(/\/+$/, "")}/oauth/token`,
body: {
grant_type: 'password',
username,
password,
audience,
scope,
client_id,
client_secret,
},
}).then(({ body: { access_token, expires_in, id_token } }) => {
localStorage.setItem('access_token', access_token);
localStorage.setItem(`@@auth0spajs@@::${client_id}::${audience}::${scope}`, JSON.stringify({
body: {
client_id,
access_token,
id_token,
scope,
expires_in,
decodedToken: {
user: jwt_decode(id_token),
},
},
expiresAt: Math.floor(Date.now() / 1000) + expires_in,
}))
return cy.visit('/?cypress');
});
});loud-dinner-94998
02/17/2023, 2:47 PMdescribe('Check if blablabla', () => {
const hubPage = new HubPage();
const companyProductPage = new CompanyProductPage();
it('Loads Hub page and clicks on company product', () => {
hubPage.waitForHubToLoad();
hubPage.goToProductPageFromGrid(ProductNames.companyProduct);
console.log(localStorage.getItem('access_token'))
mapperPage.waitUntilLoaded();
mapperPage.configureAuthority(specSettings.authorityId);
});
The spec fails. After it clicks the company product from the product grid it visits hub.com/productname but the Auth0 login page appears!
I have no idea how to fix this. It should just load the product without asking for authentication again.
What I have tried so far:
1. Set testIsolation to false
2. Logged the access_token after in the spec file to ensure the access token persists