How to Test an SharePoint site Page with Cypress

Rahil Machchhar 21 Reputation points
2022-03-17T05:52:50.213+00:00

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:
183955-111.png

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,300 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,810 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,597 questions
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 33,641 Reputation points Microsoft Vendor
    2022-03-17T06:45:14.09+00:00

    Hi @Rahil Machchhar ,
    Since our support scope is about SharePoint. You could raise a ticket in Cypress support for more professional advice.

    Microsoft provides third-party contact information to help you find technical support. This contact information may change without notice. Microsoft does not guarantee the accuracy of this third-party contact information.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments

0 additional answers

Sort by: Most helpful