woocommerce/plugins/woocommerce-admin/tests/e2e/pages/WcHomescreen.ts

57 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { getElementByText, waitForElementByText } from '../utils/actions';
import { BasePage } from './BasePage';
export class WcHomescreen extends BasePage {
url = 'wp-admin/admin.php?page=wc-admin';
async isDisplayed() {
// Wait for Benefits section to appear
await waitForElementByText( 'h1', 'Home' );
}
async possiblyDismissWelcomeModal() {
// Wait for Benefits section to appear
const modal = await getElementByText(
'h2',
'Welcome to your WooCommerce stores online HQ!'
);
if ( modal ) {
await this.clickButtonWithText( 'Next' );
await this.clickButtonWithText( 'Next' );
await this.click( '.components-guide__finish-button' );
}
}
async getTaskList() {
await page.waitForSelector(
'.woocommerce-task-card .woocommerce-list__item-title'
);
await waitForElementByText( 'p', 'Get ready to start selling' );
const list = await this.page.$$eval(
'.woocommerce-task-card .woocommerce-list__item-title',
( items ) => items.map( ( item ) => item.textContent )
);
return list.map( ( item: string | null ) => {
const match = item?.match( /(.+)[0-9] minute/ );
if ( match && match.length > 1 ) {
return match[ 1 ];
}
return item;
} );
}
async clickOnTaskList( taskTitle: string ) {
const item = await waitForElementByText( 'div', taskTitle );
if ( ! item ) {
throw new Error(
`Could not find task list item with title: ${ taskTitle }`
);
} else {
await item.click();
await waitForElementByText( 'h1', taskTitle );
}
}
}