File size: 3,021 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
/**
* @group authentication
*/
import { DataHelper, LoginPage, SecretsManager, TOTPClient } from '@automattic/calypso-e2e';
import { Page, Browser } from 'playwright';
declare const browser: Browser;
describe( DataHelper.createSuiteTitle( 'Authentication: TOTP' ), function () {
const credentials = SecretsManager.secrets.testAccounts.totpUser;
let page: Page;
let loginPage: LoginPage;
describe( 'WordPress.com', function () {
beforeAll( async () => {
page = await browser.newPage();
} );
// This spec intentionally manually calls individual
// methods from LoginPage to separate out the steps that
// are bundled together in the TestAccount class.
it( 'Navigate to Login page', async function () {
// Test redirect to full URL.
await page.goto(
DataHelper.getCalypsoURL(
`log-in?site=${ credentials.primarySite }&redirect_to=%2Fplans%2F${ credentials.primarySite }`
)
);
} );
it( 'Enter username', async function () {
loginPage = new LoginPage( page );
await loginPage.fillUsername( credentials.username );
await loginPage.clickSubmit();
} );
it( 'Enter password', async function () {
await loginPage.fillPassword( credentials.password );
} );
it( 'Submit form', async function () {
await Promise.all( [ page.waitForNavigation(), loginPage.clickSubmit() ] );
} );
it( 'Enter 2FA code', async function () {
const totpClient = new TOTPClient( credentials.totpKey as string );
const code = totpClient.getToken();
await loginPage.submitVerificationCode( code );
} );
it( 'User is redirected to Settings > General Settings', async function () {
const redirectedURL = DataHelper.getCalypsoURL( '/plans' );
await page.waitForURL( `${ redirectedURL }/${ credentials.primarySite }` );
} );
afterAll( async () => {
await page.close();
} );
} );
describe( 'WooCommerce', function () {
beforeAll( async () => {
page = await browser.newPage();
} );
it( 'Navigate to Login page', async function () {
loginPage = new LoginPage( page );
await loginPage.visit( {
path: SecretsManager.secrets.wooLoginPath,
} );
// Wait 30s to avoid OTP code reuse error.
await page.waitForTimeout( 30000 );
} );
it( 'Enter username', async function () {
loginPage = new LoginPage( page );
await loginPage.fillUsername( credentials.username );
await loginPage.clickSubmit();
} );
it( 'Enter password', async function () {
await loginPage.fillPassword( credentials.password );
} );
it( 'Submit form', async function () {
await Promise.all( [ page.waitForURL( /log-in\/authenticator/ ), loginPage.clickSubmit() ] );
} );
it( 'Enter 2FA code', async function () {
const totpClient = new TOTPClient( credentials.totpKey as string );
const code = totpClient.getToken();
await loginPage.submitVerificationCode( code );
} );
it( 'Redirected to woo.com upon successful login', async function () {
await page.waitForURL( /.*woocommerce\.com*/ );
} );
} );
} );
|