Does cypress support SharePoint site E2E testing? How to run E2E testing using cypress for SharePoint Sites
Below I have mentioned the code for generating access tokens using client id secret value. I have stored the token in local storage but after that, it was not opening any SharePoint site it's open the Microsoft sign In page.
Commands.js
Cypress.Commands.add('generateToken', () => {
let resource = '';
cy.request({
// Given: I send auth request
url: 'https://login.microsoftonline.com/${tenantID}/oauth2/token',
method: "POST",
header: {
"cache-control": "no-cache",
"Content-Type": "application/x-www-form-urlencoded"
},
form: true,
body: {
grant_type: 'password',
tenant: '',
client_id: '',
client_secret: '',
resource: '',
username: '',
password: ''
}
}).its('body')
.then((body) => {
// When: I get a token
cy.log('token......', body.access_token);
const expires = body.expires_on;
window.sessionStorage.setItem("access_token", body.access_token);
window.sessionStorage.setItem(`adal.expiration.key${resource}`, expires);
window.sessionStorage.setItem("refresh_token", body.refresh_token);
});
});
Below I have mentioned the tests case which I have created.
import '../../support/commands';
describe('example to-do app', () => {
it('Visits the site as logged in user', () => {
cy.generateToken();
cy.wait(3000);
cy.visit('https://onlinesharepoints.sharepoint.com/sites/abcdev/Pages/test-Angular.aspx');
})
})
Below mention a screenshot of cypress results: