|
|
import { Locator, Page, Response } from 'playwright'; |
|
|
import { getCalypsoURL } from '../../data-helper'; |
|
|
|
|
|
const selectors = { |
|
|
continue: 'button:text("Continue"),a:text("Continue")', |
|
|
loginWithAnotherAccount: ':text("another account")', |
|
|
useUsernamePasswordInstead: 'button:text("Use username and password instead")', |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export class LoginPage { |
|
|
private page: Page; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor( page: Page ) { |
|
|
this.page = page; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async visit( { path }: { path: string } = { path: '' } ): Promise< Response | null > { |
|
|
const targetUrl = path ? `log-in/${ path }` : 'log-in'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this.page.route( '**/cspreport', ( route ) => { |
|
|
route.fulfill( { |
|
|
status: 200, |
|
|
} ); |
|
|
} ); |
|
|
return await this.page.goto( getCalypsoURL( targetUrl ) ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async logInWithCredentials( username: string, password: string ): Promise< void > { |
|
|
await this.fillUsername( username ); |
|
|
await this.clickSubmit(); |
|
|
await this.fillPassword( password ); |
|
|
await Promise.all( [ |
|
|
this.page.waitForNavigation( { timeout: 20 * 1000 } ), |
|
|
this.clickSubmit(), |
|
|
] ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async submitVerificationCode( code: string ): Promise< void > { |
|
|
await this.fillVerificationCode( code ); |
|
|
await Promise.all( [ this.page.waitForNavigation(), this.clickSubmit() ] ); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async fillUsername( value: string ): Promise< Locator > { |
|
|
const locator = await this.page.locator( 'input[name="usernameOrEmail"]' ); |
|
|
await locator.fill( value ); |
|
|
|
|
|
return locator; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async fillPassword( value: string ): Promise< Locator > { |
|
|
const locator = await this.page.locator( 'input#password' ); |
|
|
await locator.fill( value ); |
|
|
|
|
|
return locator; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async fillVerificationCode( value: string ): Promise< Locator > { |
|
|
const locator = await this.page.locator( 'input[name="twoStepCode"]' ); |
|
|
await locator.fill( value ); |
|
|
|
|
|
return locator; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickSubmit(): Promise< Locator > { |
|
|
const locator = await this.page.locator( 'button[type="submit"]' ); |
|
|
await locator.click(); |
|
|
|
|
|
return locator; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickLoginWithGoogle(): Promise< Page > { |
|
|
const locator = this.page.getByRole( 'button', { name: 'Continue with Google' } ); |
|
|
|
|
|
await locator.waitFor(); |
|
|
|
|
|
|
|
|
|
|
|
const [ page ] = await Promise.all( [ this.page.waitForEvent( 'popup' ), locator.click() ] ); |
|
|
|
|
|
return page; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickLoginWithApple(): Promise< Locator > { |
|
|
const locator = await this.page.locator( ':text-is("Continue with Apple")' ); |
|
|
await locator.click(); |
|
|
|
|
|
return locator; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickLoginWithGitHub(): Promise< Locator > { |
|
|
const locator = await this.page.locator( ':text-is("Continue with GitHub")' ); |
|
|
await locator.click(); |
|
|
|
|
|
return locator; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickCreateNewAccount(): Promise< Locator > { |
|
|
const locator = this.page.getByRole( 'link', { name: 'Create an account' } ); |
|
|
await locator.waitFor(); |
|
|
await locator.click(); |
|
|
|
|
|
return locator; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickSendMagicLink(): Promise< Locator > { |
|
|
const locator = await this.page.locator( ':text-is("Email me a login link")' ); |
|
|
await locator.click(); |
|
|
|
|
|
return locator; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickRetrievePassword(): Promise< Locator > { |
|
|
const locator = await this.page.locator( ':text-is("Lost your password?")' ); |
|
|
await locator.click(); |
|
|
|
|
|
return locator; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickChangeAccount(): Promise< Locator > { |
|
|
const locator = await this.page.locator( '#loginAsAnotherUser' ); |
|
|
await locator.click(); |
|
|
|
|
|
return locator; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickSignUp(): Promise< Locator > { |
|
|
const locator = await this.page.locator( ':text-is("Sign Up")' ); |
|
|
await locator.click(); |
|
|
|
|
|
return locator; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickContinue(): Promise< Locator > { |
|
|
const locator = await this.page.locator( selectors.continue ); |
|
|
await locator.click(); |
|
|
|
|
|
return locator; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickLoginWithAnotherAccount(): Promise< Locator > { |
|
|
const locator = await this.page.locator( selectors.loginWithAnotherAccount ); |
|
|
await locator.click(); |
|
|
|
|
|
return locator; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async clickUseUsernamePasswordInstead(): Promise< Locator > { |
|
|
const locator = await this.page.locator( selectors.useUsernamePasswordInstead ); |
|
|
|
|
|
|
|
|
return locator; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async validateContinueAsYourself( username: string, email: string ) { |
|
|
await this.page.waitForSelector( selectors.continue ); |
|
|
await this.page.waitForSelector( `text='${ username }'` ); |
|
|
await this.page.waitForSelector( `text='${ email }'` ); |
|
|
await this.page.waitForSelector( selectors.loginWithAnotherAccount ); |
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
|