| | import assert from 'assert'; |
| | import { Page } from 'playwright'; |
| | import { getCalypsoURL } from '../../data-helper'; |
| |
|
| | const selectors = { |
| | |
| | modalButtonWithText: ( text: string ) => `.dialog__action-buttons button:has-text("${ text }")`, |
| |
|
| | listTitle: ( section: string ) => `.plugins-results-header__title:text("${ section }")`, |
| | listSubtitle: ( section: string ) => `.plugins-results-header__subtitle:text("${ section }")`, |
| | headerTitle: ( section: string ) => `.plugins-results-header__title:text("${ section }")`, |
| | pluginTitle: ( plugin: string ) => `.plugins-browser-item__title:text("${ plugin }")`, |
| | pluginTitleOnSection: ( section: string, plugin: string ) => |
| | `.plugins-browser-list:has(.plugins-results-header__title:text("${ section }")) :text-is("${ plugin }")`, |
| | sectionTitles: '.plugins-results-header__title', |
| | browseAllFree: 'a[href^="/plugins/browse/popular"]', |
| | browseAllPaid: 'a[href^="/plugins/browse/paid"]', |
| | browseFirstCategory: 'button:has-text("Search Engine Optimization")', |
| | breadcrumb: ( section: string ) => `.navigation-header__main a:text("${ section }") `, |
| | pricingToggle: ':text("Monthly Price"), :text("Annual Price")', |
| | monthlyPricingSelect: 'a[data-bold-text^="Monthly price"]', |
| | annualPricingSelect: 'a[data-bold-text^="Annual price"]', |
| | monthlyPricing: '.plugins-browser-item__period:text("monthly")', |
| | annualPricing: '.plugins-browser-item__period:text("per year")', |
| |
|
| | |
| | searchInput: '.components-search-control .components-input-control__input', |
| | searchResult: ( text: string ) => `.plugins-browser-item__title:text("${ text }")`, |
| | |
| | searchResultTitle: ( text: string ) => `:text('plugins for "${ text }"')`, |
| |
|
| | |
| | installButton: '.plugin-details-cta__install-button', |
| | deactivateButton: 'button:text("Deactivate")', |
| | activateButton: 'button:text("Activate")', |
| | openRemoveMenuButton: '.plugin-details-cta__manage-plugin-menu button[title="Toggle menu"]', |
| | removeButton: '.popover__menu button:has-text("Remove")', |
| |
|
| | |
| | selectedCategory: ( categoryTitle: string ) => `.categories__header:text("${ categoryTitle }")`, |
| |
|
| | |
| | pluginDetailsHeaderTitle: ( section: string ) => |
| | `.plugin-details-header__name:text("${ section }")`, |
| | planUpgradeRequiredIcon: 'span.plugin-details-cta__upgrade-required-icon', |
| |
|
| | |
| | installedPluginCard: '.thank-you__step', |
| | installedfooterCards: '.thank-you__footer', |
| | manageInstalledPluginButton: 'a:has-text("Manage plugin")', |
| | }; |
| |
|
| | |
| | |
| | |
| | export class PluginsPage { |
| | private page: Page; |
| |
|
| | static paidSection = 'Must-have premium plugins'; |
| | static featuredSection = 'Our developers’ favorites'; |
| | static freeSection = 'Popular Plugins'; |
| |
|
| | |
| | |
| | |
| | constructor( page: Page ) { |
| | this.page = page; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | async visit( site = '' ): Promise< void > { |
| | await Promise.all( [ |
| | this.page.waitForResponse( /\/sites\/\d+\/plugins/, { timeout: 20 * 1000 } ), |
| | |
| | |
| | this.page.goto( getCalypsoURL( `plugins/${ site }` ), { timeout: 20 * 1000 } ), |
| | ] ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | async visitPage( page: string, site = '' ): Promise< void > { |
| | await this.page.goto( getCalypsoURL( `plugins/${ page }/${ site }` ) ); |
| | } |
| |
|
| | |
| | |
| | |
| | async validateHasSection( section: string ): Promise< void > { |
| | await this.page.waitForSelector( selectors.listTitle( section ) ); |
| | } |
| |
|
| | |
| | |
| | |
| | async validateHasSubtitle( section: string ): Promise< void > { |
| | await this.page.waitForSelector( selectors.listSubtitle( section ) ); |
| | } |
| |
|
| | |
| | |
| | |
| | async validateSelectedCategory( categoryTitle: string ): Promise< void > { |
| | await this.page.waitForSelector( selectors.selectedCategory( categoryTitle ) ); |
| | } |
| |
|
| | |
| | |
| | |
| | async validateHasHeaderTitle( section: string ): Promise< void > { |
| | await this.page.waitForSelector( selectors.headerTitle( section ) ); |
| | } |
| |
|
| | |
| | |
| | |
| | async validatePluginDetailsHasHeaderTitle( section: string ): Promise< void > { |
| | await this.page.waitForSelector( selectors.pluginDetailsHeaderTitle( section ) ); |
| | } |
| |
|
| | |
| | |
| | |
| | async validateNotHasSection( section: string ): Promise< void > { |
| | await this.page.waitForSelector( selectors.sectionTitles ); |
| | const titles = this.page.locator( selectors.sectionTitles ); |
| | const count = await titles.count(); |
| | assert.notEqual( count, 0 ); |
| | for ( let i = 0; i < count; i++ ) { |
| | const title = await titles.nth( i ).innerText(); |
| | assert.notEqual( title, section ); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | async validateHasPluginOnSection( section: string, plugin: string ): Promise< void > { |
| | await this.page.waitForSelector( selectors.pluginTitleOnSection( section, plugin ) ); |
| | } |
| |
|
| | |
| | |
| | |
| | async validateHasPluginInCategory( section: string, plugin: string ): Promise< void > { |
| | await this.page.waitForSelector( selectors.headerTitle( section ) ); |
| | await this.page.waitForSelector( selectors.pluginTitle( plugin ) ); |
| | } |
| |
|
| | |
| | |
| | |
| | async clickBrowseAllFreePlugins(): Promise< void > { |
| | await this.page.click( selectors.browseAllFree ); |
| | } |
| |
|
| | |
| | |
| | |
| | async clickBrowseAllPaidPlugins(): Promise< void > { |
| | await this.page.click( selectors.browseAllPaid ); |
| | } |
| |
|
| | |
| | |
| | |
| | async validateCategoryButton( category: string, isDesktop: boolean ): Promise< void > { |
| | let categoryLocator; |
| | if ( isDesktop ) { |
| | categoryLocator = this.page.getByRole( 'radio', { name: category } ); |
| | } else { |
| | await this.page.getByRole( 'button', { name: 'More', exact: true } ).click(); |
| | categoryLocator = this.page.getByRole( 'menuitem', { name: category } ); |
| | } |
| | await categoryLocator.click(); |
| | await this.page.waitForSelector( selectors.headerTitle( category ) ); |
| | } |
| |
|
| | |
| | |
| | |
| | async clickBackBreadcrumb(): Promise< void > { |
| | await this.page.click( selectors.breadcrumb( 'Back' ) ); |
| | } |
| |
|
| | |
| | |
| | |
| | async clickPluginsBreadcrumb(): Promise< void > { |
| | await this.page.click( selectors.breadcrumb( 'Plugins' ) ); |
| | } |
| |
|
| | |
| | |
| | |
| | async clickSearchResultsBreadcrumb(): Promise< void > { |
| | await this.page.click( selectors.breadcrumb( 'Search Results' ) ); |
| | } |
| |
|
| | |
| | |
| | |
| | async selectMonthlyPricing(): Promise< void > { |
| | await this.page.click( selectors.pricingToggle ); |
| | await this.page.click( selectors.monthlyPricingSelect ); |
| | } |
| |
|
| | |
| | |
| | |
| | async selectAnnualPricing(): Promise< void > { |
| | await this.page.click( selectors.pricingToggle ); |
| | await this.page.click( selectors.annualPricingSelect ); |
| | } |
| |
|
| | |
| | |
| | |
| | async validateIsMonthlyPricing(): Promise< void > { |
| | await this.page.waitForSelector( selectors.monthlyPricing ); |
| | } |
| |
|
| | |
| | |
| | |
| | async validateIsAnnualPricing(): Promise< void > { |
| | await this.page.waitForSelector( selectors.annualPricing ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async search( query: string ): Promise< void > { |
| | await this.page.fill( selectors.searchInput, query ); |
| | await this.page.press( selectors.searchInput, 'Enter' ); |
| | await this.page.waitForSelector( selectors.searchResultTitle( query ) ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async clickSearchResult( name: string ): Promise< void > { |
| | await this.page.click( selectors.searchResult( name ) ); |
| | } |
| |
|
| | |
| | |
| | |
| | async validateExpectedSearchResultFound( expectedResult: string ): Promise< void > { |
| | await this.page.waitForSelector( selectors.searchResult( expectedResult ) ); |
| | } |
| |
|
| | |
| |
|
| | |
| | |
| | |
| | async clickDeactivatePlugin(): Promise< void > { |
| | await this.page.getByRole( 'button', { name: 'Deactivate', exact: true } ).click(); |
| | await this.page.getByRole( 'button', { name: 'Activate', exact: true } ).waitFor(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | async clickInstallPlugin(): Promise< void > { |
| | const button = await this.page.locator( selectors.installButton ); |
| |
|
| | const text = await button.innerText(); |
| | if ( /^(Purchase|Upgrade) and activate$/.test( text ) ) { |
| | await Promise.all( [ this.page.waitForResponse( /eligibility/ ), button.click() ] ); |
| | |
| | |
| | await this.page.getByRole( 'button', { name: 'Upgrade and activate plugin' } ).click(); |
| | } else { |
| | await Promise.all( [ this.page.waitForResponse( /.*install\?.*/ ), button.click() ] ); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | async clickRemovePlugin(): Promise< void > { |
| | const openRemoveMenuButtonLocator = this.page.locator( selectors.openRemoveMenuButton ); |
| | await openRemoveMenuButtonLocator.click(); |
| |
|
| | const removeButtonLocator = this.page.locator( selectors.removeButton ); |
| | await removeButtonLocator.click(); |
| | const confirmDialogButton = this.page.locator( selectors.modalButtonWithText( 'Remove' ) ); |
| | await Promise.all( [ |
| | this.page.waitForResponse( /.*delete\?.*/ ), |
| | confirmDialogButton.click(), |
| | ] ); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | async validateConfirmationPagePostInstall( expectedPluginName?: string ): Promise< void > { |
| | await this.page |
| | .getByRole( 'heading', { name: "Congrats on your site's new superpowers!" } ) |
| | .click(); |
| |
|
| | |
| | await this.page.locator( selectors.installedPluginCard ).getByText( 'expire' ).waitFor(); |
| |
|
| | |
| | await this.page.locator( selectors.installedfooterCards ).getByText( 'Keep growing' ).waitFor(); |
| | await this.page.locator( selectors.installedfooterCards ).getByText( 'Learn More' ).waitFor(); |
| |
|
| | |
| | if ( expectedPluginName ) { |
| | await this.page |
| | .locator( selectors.installedPluginCard ) |
| | .getByText( expectedPluginName ) |
| | .waitFor(); |
| | } |
| | } |
| |
|
| | |
| | |
| | |
| | async clickManageInstalledPluginButton(): Promise< void > { |
| | await this.page.locator( selectors.manageInstalledPluginButton ).click(); |
| | } |
| |
|
| | |
| | |
| | |
| | async clickCategory( name: string ): Promise< void > { |
| | await this.page.getByRole( 'radio', { name } ).click(); |
| | } |
| |
|
| | |
| | |
| | |
| | async openCategoriesDropdown(): Promise< void > { |
| | await this.page.getByRole( 'button', { name: 'More', exact: true } ).click(); |
| | } |
| |
|
| | |
| | |
| | |
| | async clickDropdownCategory( name: string ): Promise< void > { |
| | await this.openCategoriesDropdown(); |
| | await this.page.getByRole( 'menuitem', { name } ).click(); |
| | } |
| | } |
| |
|