|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { LoginPage, SecretsManager, GoogleLoginPage, TOTPClient } from '@automattic/calypso-e2e'; |
|
|
import { Page, Browser } from 'playwright'; |
|
|
|
|
|
declare const browser: Browser; |
|
|
|
|
|
describe( 'Authentication: Google', function () { |
|
|
const credentials = SecretsManager.secrets.testAccounts.googleLoginUser; |
|
|
|
|
|
let page: Page; |
|
|
let googlePopupPage: Page; |
|
|
let loginPage: LoginPage; |
|
|
let googleLoginPage: GoogleLoginPage; |
|
|
|
|
|
const totpClient = new TOTPClient( credentials.totpKey as string ); |
|
|
let code: string; |
|
|
|
|
|
describe( 'WordPress.com', function () { |
|
|
beforeAll( async () => { |
|
|
page = await browser.newPage(); |
|
|
} ); |
|
|
|
|
|
it( 'Navigate to /login', async function () { |
|
|
loginPage = new LoginPage( page ); |
|
|
await loginPage.visit(); |
|
|
|
|
|
await page.waitForURL( /log-in/ ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await page.waitForLoadState( 'networkidle' ); |
|
|
} ); |
|
|
|
|
|
it( 'Click on "Continue with Google" button', async function () { |
|
|
googlePopupPage = await loginPage.clickLoginWithGoogle(); |
|
|
await googlePopupPage.waitForURL( /accounts\.google\.com/ ); |
|
|
} ); |
|
|
|
|
|
it( 'Enter Google username', async function () { |
|
|
await googlePopupPage.waitForURL( /identifier/ ); |
|
|
|
|
|
googleLoginPage = new GoogleLoginPage( googlePopupPage ); |
|
|
await googleLoginPage.enterUsername( credentials.username ); |
|
|
await googleLoginPage.clickButton( 'Next' ); |
|
|
} ); |
|
|
|
|
|
it( 'Enter Google password', async function () { |
|
|
await googlePopupPage.waitForURL( /challenge/ ); |
|
|
|
|
|
await googleLoginPage.enterPassword( credentials.password ); |
|
|
await googleLoginPage.clickButton( 'Next' ); |
|
|
} ); |
|
|
|
|
|
it( 'Enter 2FA challenge if required - Challenge 1', async function () { |
|
|
code = totpClient.getToken(); |
|
|
|
|
|
await googleLoginPage.enter2FACode( code ); |
|
|
await googleLoginPage.clickButton( 'Next' ); |
|
|
} ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it( 'Enter 2FA challenge if required - Challenge 2', async function () { |
|
|
await page.waitForLoadState( 'networkidle' ); |
|
|
|
|
|
const isSecondChallengePresent = await googleLoginPage.isVisible( 'text="Verify it’s you"' ); |
|
|
|
|
|
if ( ! isSecondChallengePresent ) { |
|
|
return; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
while ( totpClient.getToken() === code ) { |
|
|
console.log( |
|
|
`Google Authentication: second 2FA challenge encountered, waiting for TOTP code to change from ${ code }` |
|
|
); |
|
|
await new Promise( ( resolve ) => setTimeout( resolve, 1000 ) ); |
|
|
} |
|
|
|
|
|
code = totpClient.getToken(); |
|
|
|
|
|
await googleLoginPage.enter2FACode( code ); |
|
|
await googleLoginPage.clickButton( 'Next' ); |
|
|
} ); |
|
|
|
|
|
it( 'Click the "Continue" button in the login confirmation screen', async function () { |
|
|
const googlePopupPageClosePromise = googlePopupPage.waitForEvent( 'close' ); |
|
|
|
|
|
await googleLoginPage.clickButton( 'Continue' ); |
|
|
|
|
|
|
|
|
await googlePopupPageClosePromise; |
|
|
} ); |
|
|
|
|
|
it( 'Redirected to /home upon successful login', async function () { |
|
|
await page.waitForURL( /.*\/home\/.*/ ); |
|
|
} ); |
|
|
} ); |
|
|
|
|
|
describe( 'WooCommerce', function () { |
|
|
beforeAll( async () => { |
|
|
page = await browser.newPage(); |
|
|
} ); |
|
|
|
|
|
it( 'Navigate to /login', async function () { |
|
|
loginPage = new LoginPage( page ); |
|
|
await loginPage.visit( { |
|
|
path: SecretsManager.secrets.wooLoginPath, |
|
|
} ); |
|
|
|
|
|
await page.waitForURL( /log-in/ ); |
|
|
|
|
|
|
|
|
await page.waitForLoadState( 'networkidle' ); |
|
|
} ); |
|
|
|
|
|
it( 'Click on "Continue with Google" button', async function () { |
|
|
googlePopupPage = await loginPage.clickLoginWithGoogle(); |
|
|
await googlePopupPage.waitForURL( /accounts\.google\.com/ ); |
|
|
} ); |
|
|
|
|
|
it( 'Enter Google username', async function () { |
|
|
await googlePopupPage.waitForURL( /identifier/ ); |
|
|
|
|
|
googleLoginPage = new GoogleLoginPage( googlePopupPage ); |
|
|
await googleLoginPage.enterUsername( credentials.username ); |
|
|
await googleLoginPage.clickButton( 'Next' ); |
|
|
} ); |
|
|
|
|
|
it( 'Enter Google password', async function () { |
|
|
await googlePopupPage.waitForURL( /challenge/ ); |
|
|
|
|
|
await googleLoginPage.enterPassword( credentials.password ); |
|
|
await googleLoginPage.clickButton( 'Next' ); |
|
|
} ); |
|
|
|
|
|
it( 'Enter 2FA challenge if required - Challenge 1', async function () { |
|
|
|
|
|
|
|
|
while ( totpClient.getToken() === code ) { |
|
|
console.log( |
|
|
`Google Authentication: second 2FA challenge encountered, waiting for TOTP code to change from ${ code }` |
|
|
); |
|
|
await new Promise( ( resolve ) => setTimeout( resolve, 1000 ) ); |
|
|
} |
|
|
|
|
|
code = totpClient.getToken(); |
|
|
|
|
|
await googleLoginPage.enter2FACode( code ); |
|
|
await googleLoginPage.clickButton( 'Next' ); |
|
|
} ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it( 'Enter 2FA challenge if required - Challenge 2', async function () { |
|
|
|
|
|
const isSecondChallengePresent = await googleLoginPage.isVisible( 'text="Verify it’s you"' ); |
|
|
|
|
|
if ( ! isSecondChallengePresent ) { |
|
|
return; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
while ( totpClient.getToken() === code ) { |
|
|
console.log( |
|
|
`Google Authentication: second 2FA challenge encountered, waiting for TOTP code to change from ${ code }` |
|
|
); |
|
|
await new Promise( ( resolve ) => setTimeout( resolve, 1000 ) ); |
|
|
} |
|
|
|
|
|
await googleLoginPage.enter2FACode( totpClient.getToken() ); |
|
|
await googleLoginPage.clickButton( 'Next' ); |
|
|
} ); |
|
|
|
|
|
it( 'Click the "Continue" button in the login confirmation screen', async function () { |
|
|
const googlePopupPageClosePromise = googlePopupPage.waitForEvent( 'close' ); |
|
|
|
|
|
await googleLoginPage.clickButton( 'Continue' ); |
|
|
|
|
|
|
|
|
await googlePopupPageClosePromise; |
|
|
} ); |
|
|
|
|
|
it( 'Redirected to woo.com upon successful login', async function () { |
|
|
await page.waitForURL( /.*woo\.com*/ ); |
|
|
} ); |
|
|
} ); |
|
|
} ); |
|
|
|