UNPKG

qe-fe-automation

Version:
60 lines (48 loc) 2.17 kB
import { impersonationPageSelectors } from '@travelxen-lib/selectors/impersonation'; export class TravelxenImpersonationPage { static checkIfCanImpersonate(isAdmin = false) { let impersonationURL = ''; const expectedURL = isAdmin ? '/app/admin2' : '/app/user2/home'; const expectedButtonText = 'Logged in as'; cy.window().then((win) => { cy.stub(win, 'open').as('windowOpen'); }); isAdmin ? cy.get(impersonationPageSelectors.impersonateAdminButton).click() : cy.get(impersonationPageSelectors.impersonateUserButton).click(); cy.get('@windowOpen').should('be.calledOnce'); cy.get('@windowOpen').then((stub: any) => { impersonationURL = stub.args[0][0]; cy.visit(impersonationURL); cy.url().should('include', expectedURL); isAdmin ? cy .get(impersonationPageSelectors.adminMenuButton) .should('be.visible') .should('contain.text', expectedButtonText) .should('contain.text', 'Admin Navan') : cy .get(impersonationPageSelectors.userMenuButton) .should('be.visible') .should('contain.text', expectedButtonText); }); } static checkUsersTrips() { cy.get(impersonationPageSelectors.tripsButton).click(); cy.get(impersonationPageSelectors.tripsCard).should('be.visible'); } static loginIntoUsersApp(userName: string, password: string) { cy.visit('/app/user2'); cy.get(impersonationPageSelectors.usersEmailField).type(userName); cy.get(impersonationPageSelectors.continueWithEmailButton).click(); cy.get(impersonationPageSelectors.usersPasswordField).type(password, { log: false }); cy.get(impersonationPageSelectors.continueWithPasswordButton).click(); cy.url().should('include', '/app/user2/home'); } static loginToTravelxen(userName: string, password: string) { cy.get(impersonationPageSelectors.txEmailField).type(userName); cy.get(impersonationPageSelectors.submitButton).click(); cy.get(impersonationPageSelectors.txPasswordField).type(password, { log: false }); cy.get(impersonationPageSelectors.submitButton).click(); } }