UNPKG

qe-fe-automation

Version:
104 lines (98 loc) 3.05 kB
import { Interception } from 'cypress/types/net-stubbing'; const rightArrow = String.fromCodePoint(9654); const leftArrow = String.fromCodePoint(9664); export class Logs { static cypressResponseLog(logType: string, xhr: Interception, expectedStatusCode = 200) { const response: any = xhr.response?.body; const status: any = xhr.response?.statusCode; const statusCode = JSON.stringify(status); cy.allure().logStep( `${logType}` + ' ' + rightArrow + rightArrow + rightArrow + rightArrow + ' ' + rightArrow + rightArrow + ' ' + 'STATUS CODE RECEIVED ' + ' ' + rightArrow + rightArrow + rightArrow + ' ' + statusCode + ' ' + ' ' + leftArrow + leftArrow + leftArrow + JSON.stringify(response) + ' ' + leftArrow + leftArrow + leftArrow + leftArrow + ' ' ); cy.log(JSON.stringify(response)); cy.log(JSON.stringify(statusCode)); //expect(statusCode).to.include(expectedStatusCode); } static cypressRequestLog(logType: string, xhr: Interception, expectedStatusCode = 200) { const request: any = xhr.request?.body; const status: any = xhr.response?.statusCode; const statusCode = JSON.stringify(status); cy.log(JSON.stringify(request)); cy.allure().logStep( `${logType}` + ' ' + rightArrow + rightArrow + rightArrow + rightArrow + ' ' + rightArrow + rightArrow + ' ' + 'STATUS CODE RECEIVED ' + ' ' + rightArrow + rightArrow + rightArrow + ' ' + statusCode + ' ' + ' ' + leftArrow + leftArrow + leftArrow + JSON.stringify(request) + ' ' + leftArrow + leftArrow + leftArrow + leftArrow + ' ' ); // expect(statusCode).to.include(expectedStatusCode); } static logResponseStatusAndBody(xhr: Cypress.Response<any>): Cypress.Chainable<Cypress.Response<any>> { return cy.log(`Response code: ${xhr.status} \n body: ${JSON.stringify(xhr.body)}`).then(() => xhr); } static hideResponseFromLogsAndTestRunners() { //! skipped showing unwanted intercept cy.intercept('POST', new RegExp(`/bam.nr-data.net`), { log: false }); cy.intercept('GET', new RegExp(`api/v1/user/promotions/`), { log: false }); cy.intercept('POST', new RegExp(`/m.stripe.com/6`), { log: false }); cy.intercept('GET', new RegExp(`/app/user2/assets/`), { log: false }); cy.intercept('GET', new RegExp(`/api/user`), { log: false }); cy.intercept('GET', new RegExp(`analytics.tripactions.com`), { log: false }); } static logToCypressAndAllure(message: string) { cy.log(message); cy.allure().logStep(message); } }