From 97439e71d403f3712b0c62cc418341b130ef8f5f Mon Sep 17 00:00:00 2001 From: Adrian Moldovan Date: Mon, 26 Feb 2024 11:53:15 +0200 Subject: [PATCH 1/9] Fix locator for command palette --- .../tests/e2e-pw/tests/merchant/command-palette.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/woocommerce/tests/e2e-pw/tests/merchant/command-palette.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/merchant/command-palette.spec.js index 715e4f2a60cb..2cc61abae890 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/merchant/command-palette.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/merchant/command-palette.spec.js @@ -10,7 +10,7 @@ const clickOnCommandPaletteOption = async ( { page, optionName } ) => { // Press `Ctrl` + `K` to open the command palette. await page.keyboard.press( cmdKeyCombo ); - await page.getByLabel( 'Command palette' ).fill( optionName ); + await page.getByPlaceholder( 'Search for commands' ).fill( optionName ); // Click on the relevant option. const option = page.getByRole( 'option', { From ec78cb388ad93f8326666bfe6df5b9254cbe47dc Mon Sep 17 00:00:00 2001 From: Adrian Moldovan Date: Mon, 26 Feb 2024 11:54:16 +0200 Subject: [PATCH 2/9] Add changelog --- .../changelog/e2e-fix-command-pallete-with-gb-tests | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 plugins/woocommerce/changelog/e2e-fix-command-pallete-with-gb-tests diff --git a/plugins/woocommerce/changelog/e2e-fix-command-pallete-with-gb-tests b/plugins/woocommerce/changelog/e2e-fix-command-pallete-with-gb-tests new file mode 100644 index 000000000000..beee8e51a26f --- /dev/null +++ b/plugins/woocommerce/changelog/e2e-fix-command-pallete-with-gb-tests @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +E2E tests: fix command palette test with Gutengerg From 7772bde4331a393b0add440857f6de4d9696b311 Mon Sep 17 00:00:00 2001 From: Adrian Moldovan Date: Mon, 26 Feb 2024 12:02:49 +0200 Subject: [PATCH 3/9] Use fixtures instead of before/after hooks --- .../tests/merchant/command-palette.spec.js | 59 +++++++------------ 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/plugins/woocommerce/tests/e2e-pw/tests/merchant/command-palette.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/merchant/command-palette.spec.js index 2cc61abae890..4611256e9eb5 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/merchant/command-palette.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/merchant/command-palette.spec.js @@ -1,5 +1,4 @@ -const { test, expect } = require( '@playwright/test' ); -const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default; +const { test: baseTest, expect } = require( '../../fixtures' ); const { goToPostEditor } = require( '../../utils/editor' ); // need to figure out whether tests are being run on a mac @@ -21,41 +20,27 @@ const clickOnCommandPaletteOption = async ( { page, optionName } ) => { option.click(); }; -test.describe( 'Use Command Palette commands', () => { - test.use( { storageState: process.env.ADMINSTATE } ); - - let productId; - - test.beforeAll( async ( { baseURL } ) => { - const api = new wcApi( { - url: baseURL, - consumerKey: process.env.CONSUMER_KEY, - consumerSecret: process.env.CONSUMER_SECRET, - version: 'wc/v3', +const test = baseTest.extend( { + storageState: process.env.ADMINSTATE, + product: async ( { api }, use ) => { + let product = { + id: 0, + name: `Product ${ Date.now() }`, + type: 'simple', + }; + + await api.post( 'products', product ).then( ( response ) => { + product = response.data; } ); - await api - .post( 'products', { - name: 'Product to search', - type: 'simple', - regular_price: '12.99', - } ) - .then( ( response ) => { - productId = response.data.id; - } ); - } ); - test.afterAll( async ( { baseURL } ) => { - const api = new wcApi( { - url: baseURL, - consumerKey: process.env.CONSUMER_KEY, - consumerSecret: process.env.CONSUMER_SECRET, - version: 'wc/v3', - } ); - await api.delete( `products/${ productId }`, { - force: true, - } ); - } ); + await use( product ); + // Cleanup + await api.delete( `products/${ product.id }`, { force: true } ); + }, +} ); + +test.describe( 'Use Command Palette commands', () => { test( 'can use the "Add new product" command', async ( { page } ) => { await goToPostEditor( { page } ); @@ -112,17 +97,17 @@ test.describe( 'Use Command Palette commands', () => { ).toBeVisible(); } ); - test( 'can use the product search command', async ( { page } ) => { + test( 'can use the product search command', async ( { page, product } ) => { await goToPostEditor( { page } ); await clickOnCommandPaletteOption( { page, - optionName: 'Product to search', + optionName: product.name, } ); // Verify that the page has loaded. await expect( page.getByLabel( 'Product name' ) ).toHaveValue( - 'Product to search' + `${ product.name }` ); } ); From 54c4a08cffc258faafa39d4b4b209a6e574ad103 Mon Sep 17 00:00:00 2001 From: Adrian Moldovan Date: Mon, 26 Feb 2024 13:01:03 +0200 Subject: [PATCH 4/9] Disable welcome modal --- .../tests/merchant/command-palette.spec.js | 21 ++++++------------- .../woocommerce/tests/e2e-pw/utils/editor.js | 13 ++++++++++++ 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/plugins/woocommerce/tests/e2e-pw/tests/merchant/command-palette.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/merchant/command-palette.spec.js index 4611256e9eb5..d5a0345cb4f7 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/merchant/command-palette.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/merchant/command-palette.spec.js @@ -1,5 +1,5 @@ const { test: baseTest, expect } = require( '../../fixtures' ); -const { goToPostEditor } = require( '../../utils/editor' ); +const { disableWelcomeModal } = require( '../../utils/editor' ); // need to figure out whether tests are being run on a mac const macOS = process.platform === 'darwin'; @@ -38,12 +38,15 @@ const test = baseTest.extend( { // Cleanup await api.delete( `products/${ product.id }`, { force: true } ); }, + page: async ( { page }, use ) => { + await page.goto( 'wp-admin/post-new.php' ); + await disableWelcomeModal( { page } ); + await use( page ); + }, } ); test.describe( 'Use Command Palette commands', () => { test( 'can use the "Add new product" command', async ( { page } ) => { - await goToPostEditor( { page } ); - await clickOnCommandPaletteOption( { page, optionName: 'Add new product', @@ -56,8 +59,6 @@ test.describe( 'Use Command Palette commands', () => { } ); test( 'can use the "Add new order" command', async ( { page } ) => { - await goToPostEditor( { page } ); - await clickOnCommandPaletteOption( { page, optionName: 'Add new order', @@ -70,8 +71,6 @@ test.describe( 'Use Command Palette commands', () => { } ); test( 'can use the "Products" command', async ( { page } ) => { - await goToPostEditor( { page } ); - await clickOnCommandPaletteOption( { page, optionName: 'Products', @@ -84,8 +83,6 @@ test.describe( 'Use Command Palette commands', () => { } ); test( 'can use the "Orders" command', async ( { page } ) => { - await goToPostEditor( { page } ); - await clickOnCommandPaletteOption( { page, optionName: 'Orders', @@ -98,8 +95,6 @@ test.describe( 'Use Command Palette commands', () => { } ); test( 'can use the product search command', async ( { page, product } ) => { - await goToPostEditor( { page } ); - await clickOnCommandPaletteOption( { page, optionName: product.name, @@ -112,8 +107,6 @@ test.describe( 'Use Command Palette commands', () => { } ); test( 'can use a settings command', async ( { page } ) => { - await goToPostEditor( { page } ); - await clickOnCommandPaletteOption( { page, optionName: 'WooCommerce Settings: Products', @@ -124,8 +117,6 @@ test.describe( 'Use Command Palette commands', () => { } ); test( 'can use an analytics command', async ( { page } ) => { - await goToPostEditor( { page } ); - await clickOnCommandPaletteOption( { page, optionName: 'WooCommerce Analytics: Products', diff --git a/plugins/woocommerce/tests/e2e-pw/utils/editor.js b/plugins/woocommerce/tests/e2e-pw/utils/editor.js index 6c23d095cf88..3dac3602979d 100644 --- a/plugins/woocommerce/tests/e2e-pw/utils/editor.js +++ b/plugins/woocommerce/tests/e2e-pw/utils/editor.js @@ -21,8 +21,21 @@ const goToPostEditor = async ( { page } ) => { await closeWelcomeModal( { page } ); }; +const disableWelcomeModal = async ( { page } ) => { + const isWelcomeGuideActive = await page.evaluate( () => + wp.data.select( 'core/edit-post' ).isFeatureActive( 'welcomeGuide' ) + ); + + if ( isWelcomeGuideActive ) { + await page.evaluate( () => + wp.data.dispatch( 'core/edit-post' ).toggleFeature( 'welcomeGuide' ) + ); + } +}; + module.exports = { closeWelcomeModal, goToPageEditor, goToPostEditor, + disableWelcomeModal, }; From 5b92efd91592e6b23d25c858f351f36e16bb232a Mon Sep 17 00:00:00 2001 From: Adrian Moldovan Date: Mon, 26 Feb 2024 13:01:44 +0200 Subject: [PATCH 5/9] Remove describe block --- .../tests/merchant/command-palette.spec.js | 128 +++++++++--------- 1 file changed, 63 insertions(+), 65 deletions(-) diff --git a/plugins/woocommerce/tests/e2e-pw/tests/merchant/command-palette.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/merchant/command-palette.spec.js index d5a0345cb4f7..3b390927269f 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/merchant/command-palette.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/merchant/command-palette.spec.js @@ -45,88 +45,86 @@ const test = baseTest.extend( { }, } ); -test.describe( 'Use Command Palette commands', () => { - test( 'can use the "Add new product" command', async ( { page } ) => { - await clickOnCommandPaletteOption( { - page, - optionName: 'Add new product', - } ); - - // Verify that the page has loaded. - await expect( - page.getByRole( 'heading', { name: 'Add new product' } ) - ).toBeVisible(); +test( 'can use the "Add new product" command', async ( { page } ) => { + await clickOnCommandPaletteOption( { + page, + optionName: 'Add new product', } ); - test( 'can use the "Add new order" command', async ( { page } ) => { - await clickOnCommandPaletteOption( { - page, - optionName: 'Add new order', - } ); + // Verify that the page has loaded. + await expect( + page.getByRole( 'heading', { name: 'Add new product' } ) + ).toBeVisible(); +} ); - // Verify that the page has loaded. - await expect( - page.getByRole( 'heading', { name: 'Add new order' } ) - ).toBeVisible(); +test( 'can use the "Add new order" command', async ( { page } ) => { + await clickOnCommandPaletteOption( { + page, + optionName: 'Add new order', } ); - test( 'can use the "Products" command', async ( { page } ) => { - await clickOnCommandPaletteOption( { - page, - optionName: 'Products', - } ); + // Verify that the page has loaded. + await expect( + page.getByRole( 'heading', { name: 'Add new order' } ) + ).toBeVisible(); +} ); - // Verify that the page has loaded. - await expect( - page.locator( 'h1' ).filter( { hasText: 'Products' } ).first() - ).toBeVisible(); +test( 'can use the "Products" command', async ( { page } ) => { + await clickOnCommandPaletteOption( { + page, + optionName: 'Products', } ); - test( 'can use the "Orders" command', async ( { page } ) => { - await clickOnCommandPaletteOption( { - page, - optionName: 'Orders', - } ); + // Verify that the page has loaded. + await expect( + page.locator( 'h1' ).filter( { hasText: 'Products' } ).first() + ).toBeVisible(); +} ); - // Verify that the page has loaded. - await expect( - page.locator( 'h1' ).filter( { hasText: 'Orders' } ).first() - ).toBeVisible(); +test( 'can use the "Orders" command', async ( { page } ) => { + await clickOnCommandPaletteOption( { + page, + optionName: 'Orders', } ); - test( 'can use the product search command', async ( { page, product } ) => { - await clickOnCommandPaletteOption( { - page, - optionName: product.name, - } ); + // Verify that the page has loaded. + await expect( + page.locator( 'h1' ).filter( { hasText: 'Orders' } ).first() + ).toBeVisible(); +} ); - // Verify that the page has loaded. - await expect( page.getByLabel( 'Product name' ) ).toHaveValue( - `${ product.name }` - ); +test( 'can use the product search command', async ( { page, product } ) => { + await clickOnCommandPaletteOption( { + page, + optionName: product.name, } ); - test( 'can use a settings command', async ( { page } ) => { - await clickOnCommandPaletteOption( { - page, - optionName: 'WooCommerce Settings: Products', - } ); + // Verify that the page has loaded. + await expect( page.getByLabel( 'Product name' ) ).toHaveValue( + `${ product.name }` + ); +} ); - // Verify that the page has loaded. - await expect( page.getByText( 'Shop pages' ) ).toBeVisible(); +test( 'can use a settings command', async ( { page } ) => { + await clickOnCommandPaletteOption( { + page, + optionName: 'WooCommerce Settings: Products', } ); - test( 'can use an analytics command', async ( { page } ) => { - await clickOnCommandPaletteOption( { - page, - optionName: 'WooCommerce Analytics: Products', - } ); + // Verify that the page has loaded. + await expect( page.getByText( 'Shop pages' ) ).toBeVisible(); +} ); - // Verify that the page has loaded. - await expect( - page.locator( 'h1' ).filter( { hasText: 'Products' } ) - ).toBeVisible(); - const pageTitle = await page.title(); - expect( pageTitle.includes( 'Products ‹ Analytics' ) ).toBeTruthy(); +test( 'can use an analytics command', async ( { page } ) => { + await clickOnCommandPaletteOption( { + page, + optionName: 'WooCommerce Analytics: Products', } ); + + // Verify that the page has loaded. + await expect( + page.locator( 'h1' ).filter( { hasText: 'Products' } ) + ).toBeVisible(); + const pageTitle = await page.title(); + expect( pageTitle.includes( 'Products ‹ Analytics' ) ).toBeTruthy(); } ); From 6cc21887b5890f4255688a69a786f45161334944 Mon Sep 17 00:00:00 2001 From: Adrian Moldovan Date: Mon, 26 Feb 2024 16:03:29 +0200 Subject: [PATCH 6/9] Replace closeWelcomeModal with disableWelcomeModal --- .../tests/merchant/create-cart-block.spec.js | 4 ++-- .../cart-block-calculate-shipping.spec.js | 5 ++-- .../tests/shopper/cart-block-coupons.spec.js | 5 ++-- .../e2e-pw/tests/shopper/cart-block.spec.js | 4 ++-- .../cart-checkout-block-calculate-tax.spec.js | 5 ++-- .../e2e-pw/tests/shopper/mini-cart.spec.js | 4 ++-- .../shop-products-filter-by-price.spec.js | 4 ++-- .../woocommerce/tests/e2e-pw/utils/editor.js | 24 +++++++++---------- 8 files changed, 26 insertions(+), 29 deletions(-) diff --git a/plugins/woocommerce/tests/e2e-pw/tests/merchant/create-cart-block.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/merchant/create-cart-block.spec.js index 22dea643514e..f479d98123ef 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/merchant/create-cart-block.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/merchant/create-cart-block.spec.js @@ -1,5 +1,5 @@ const { test, expect } = require( '@playwright/test' ); -const { closeWelcomeModal } = require( '../../utils/editor' ); +const { disableWelcomeModal } = require( '../../utils/editor' ); const transformedCartBlockTitle = `Transformed Cart ${ Date.now() }`; const transformedCartBlockSlug = transformedCartBlockTitle @@ -13,7 +13,7 @@ test.describe( 'Transform Classic Cart To Cart Block', () => { // go to create a new page await page.goto( 'wp-admin/post-new.php?post_type=page' ); - await closeWelcomeModal( { page } ); + await disableWelcomeModal( { page } ); // fill page title await page diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-block-calculate-shipping.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-block-calculate-shipping.spec.js index 4b508a23990f..2a54d04eb23a 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-block-calculate-shipping.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-block-calculate-shipping.spec.js @@ -1,6 +1,6 @@ const { test, expect } = require( '@playwright/test' ); const { admin } = require( '../../test-data/data' ); -const { closeWelcomeModal } = require( '../../utils/editor' ); +const { disableWelcomeModal } = require( '../../utils/editor' ); const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default; const firstProductName = 'First Product'; @@ -142,12 +142,11 @@ test.describe( 'Cart Block Calculate Shipping', () => { test( 'create Cart Block page', async ( { page } ) => { // create a new page with cart block await page.goto( 'wp-admin/post-new.php?post_type=page' ); - await page.waitForLoadState( 'networkidle' ); await page.locator( 'input[name="log"]' ).fill( admin.username ); await page.locator( 'input[name="pwd"]' ).fill( admin.password ); await page.locator( 'text=Log In' ).click(); - await closeWelcomeModal( { page } ); + await disableWelcomeModal( { page } ); await page .getByRole( 'textbox', { name: 'Add title' } ) diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-block-coupons.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-block-coupons.spec.js index 3ace4e875aaa..c64a0ba79e2a 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-block-coupons.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-block-coupons.spec.js @@ -1,6 +1,6 @@ const { test, expect } = require( '@playwright/test' ); const { admin } = require( '../../test-data/data' ); -const { closeWelcomeModal } = require( '../../utils/editor' ); +const { disableWelcomeModal } = require( '../../utils/editor' ); const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default; const simpleProductName = 'Cart Coupons Product'; @@ -124,12 +124,11 @@ test.describe( 'Cart Block Applying Coupons', () => { test( 'can create Cart Block page', async ( { page } ) => { // create a new page with cart block await page.goto( 'wp-admin/post-new.php?post_type=page' ); - await page.waitForLoadState( 'networkidle' ); await page.locator( 'input[name="log"]' ).fill( admin.username ); await page.locator( 'input[name="pwd"]' ).fill( admin.password ); await page.locator( 'text=Log In' ).click(); - await closeWelcomeModal( { page } ); + await disableWelcomeModal( { page } ); await page .getByRole( 'textbox', { name: 'Add title' } ) diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-block.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-block.spec.js index c50d4a55731d..2df1b59f1e23 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-block.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-block.spec.js @@ -1,5 +1,5 @@ const { test, expect } = require( '@playwright/test' ); -const { closeWelcomeModal } = require( '../../utils/editor' ); +const { disableWelcomeModal } = require( '../../utils/editor' ); const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default; const simpleProductName = 'Single Simple Product'; @@ -88,7 +88,7 @@ test.describe( 'Cart Block page', () => { // create a new page with cart block await page.goto( 'wp-admin/post-new.php?post_type=page' ); - await closeWelcomeModal( { page } ); + await disableWelcomeModal( { page } ); await page .getByRole( 'textbox', { name: 'Add title' } ) diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-block-calculate-tax.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-block-calculate-tax.spec.js index 0a883252a2ee..456f3357061f 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-block-calculate-tax.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-block-calculate-tax.spec.js @@ -1,7 +1,7 @@ const { test, expect } = require( '@playwright/test' ); const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default; const { admin } = require( '../../test-data/data' ); -const { closeWelcomeModal } = require( '../../utils/editor' ); +const { disableWelcomeModal } = require( '../../utils/editor' ); const productName = 'First Product Cart Block Taxing'; const productPrice = '100.00'; @@ -108,12 +108,11 @@ test.describe( 'Shopper Cart & Checkout Block Tax Display', () => { test( 'can create Cart Block page', async ( { page } ) => { // create a new page with cart block await page.goto( 'wp-admin/post-new.php?post_type=page' ); - await page.waitForLoadState( 'networkidle' ); await page.locator( 'input[name="log"]' ).fill( admin.username ); await page.locator( 'input[name="pwd"]' ).fill( admin.password ); await page.locator( 'text=Log In' ).click(); - await closeWelcomeModal( { page } ); + await disableWelcomeModal( { page } ); await page .getByRole( 'textbox', { name: 'Add title' } ) diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/mini-cart.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/mini-cart.spec.js index 367abac41545..068b1be6a301 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/shopper/mini-cart.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/shopper/mini-cart.spec.js @@ -1,5 +1,5 @@ const { test, expect } = require( '@playwright/test' ); -const { closeWelcomeModal } = require( '../../utils/editor' ); +const { disableWelcomeModal } = require( '../../utils/editor' ); const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default; const miniCartPageTitle = `Mini Cart ${ Date.now() }`; @@ -121,7 +121,7 @@ test.describe( 'Mini Cart block page', () => { // create a new page with mini cart block await page.goto( 'wp-admin/post-new.php?post_type=page' ); - await closeWelcomeModal( { page } ); + await disableWelcomeModal( { page } ); await page .getByRole( 'textbox', { name: 'Add title' } ) diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/shop-products-filter-by-price.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/shop-products-filter-by-price.spec.js index e3906dd657a4..dceb19c20cc9 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/shopper/shop-products-filter-by-price.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/shopper/shop-products-filter-by-price.spec.js @@ -1,5 +1,5 @@ const { test, expect } = require( '@playwright/test' ); -const { closeWelcomeModal } = require( '../../utils/editor' ); +const { disableWelcomeModal } = require( '../../utils/editor' ); const wcApi = require( '@woocommerce/woocommerce-rest-api' ).default; const singleProductPrice1 = '10'; @@ -75,7 +75,7 @@ test.describe( 'Filter items in the shop by product price', () => { // go to create a new page with filtering products by price await page.goto( 'wp-admin/post-new.php?post_type=page' ); - await closeWelcomeModal( { page } ); + await disableWelcomeModal( { page } ); await page .getByRole( 'textbox', { name: 'Add title' } ) diff --git a/plugins/woocommerce/tests/e2e-pw/utils/editor.js b/plugins/woocommerce/tests/e2e-pw/utils/editor.js index 3dac3602979d..88c675adb541 100644 --- a/plugins/woocommerce/tests/e2e-pw/utils/editor.js +++ b/plugins/woocommerce/tests/e2e-pw/utils/editor.js @@ -9,18 +9,6 @@ const closeWelcomeModal = async ( { page } ) => { } }; -const goToPageEditor = async ( { page } ) => { - await page.goto( 'wp-admin/post-new.php?post_type=page' ); - - await closeWelcomeModal( { page } ); -}; - -const goToPostEditor = async ( { page } ) => { - await page.goto( 'wp-admin/post-new.php' ); - - await closeWelcomeModal( { page } ); -}; - const disableWelcomeModal = async ( { page } ) => { const isWelcomeGuideActive = await page.evaluate( () => wp.data.select( 'core/edit-post' ).isFeatureActive( 'welcomeGuide' ) @@ -33,6 +21,18 @@ const disableWelcomeModal = async ( { page } ) => { } }; +const goToPageEditor = async ( { page } ) => { + await page.goto( 'wp-admin/post-new.php?post_type=page' ); + + await disableWelcomeModal( { page } ); +}; + +const goToPostEditor = async ( { page } ) => { + await page.goto( 'wp-admin/post-new.php' ); + + await disableWelcomeModal( { page } ); +}; + module.exports = { closeWelcomeModal, goToPageEditor, From d770dd364e9eaeb89349ef81982b03f5073bcced Mon Sep 17 00:00:00 2001 From: Adrian Moldovan Date: Mon, 26 Feb 2024 16:06:14 +0200 Subject: [PATCH 7/9] Remove wait for networkidle --- .../tests/shopper/cart-checkout-block-calculate-tax.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-block-calculate-tax.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-block-calculate-tax.spec.js index 456f3357061f..05243fb87741 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-block-calculate-tax.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-block-calculate-tax.spec.js @@ -139,7 +139,6 @@ test.describe( 'Shopper Cart & Checkout Block Tax Display', () => { test( 'can create Checkout Block page', async ( { page } ) => { // create a new page with checkout block await page.goto( 'wp-admin/post-new.php?post_type=page' ); - await page.waitForLoadState( 'networkidle' ); await page.locator( 'input[name="log"]' ).fill( admin.username ); await page.locator( 'input[name="pwd"]' ).fill( admin.password ); await page.locator( 'text=Log In' ).click(); From 8e36f9caa9f14506d38b70707524b90b96b3d6c1 Mon Sep 17 00:00:00 2001 From: Adrian Moldovan Date: Mon, 26 Feb 2024 16:38:55 +0200 Subject: [PATCH 8/9] Wait for page load --- .../shopper/cart-checkout-block-calculate-tax.spec.js | 9 +-------- plugins/woocommerce/tests/e2e-pw/utils/editor.js | 3 +++ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-block-calculate-tax.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-block-calculate-tax.spec.js index 05243fb87741..f7547799e35c 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-block-calculate-tax.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/shopper/cart-checkout-block-calculate-tax.spec.js @@ -143,14 +143,7 @@ test.describe( 'Shopper Cart & Checkout Block Tax Display', () => { await page.locator( 'input[name="pwd"]' ).fill( admin.password ); await page.locator( 'text=Log In' ).click(); - // Close welcome popup if prompted - try { - await page - .getByLabel( 'Close', { exact: true } ) - .click( { timeout: 5000 } ); - } catch ( error ) { - console.log( "Welcome modal wasn't present, skipping action." ); - } + await disableWelcomeModal( { page } ); await page .getByRole( 'textbox', { name: 'Add title' } ) diff --git a/plugins/woocommerce/tests/e2e-pw/utils/editor.js b/plugins/woocommerce/tests/e2e-pw/utils/editor.js index 88c675adb541..201be714e449 100644 --- a/plugins/woocommerce/tests/e2e-pw/utils/editor.js +++ b/plugins/woocommerce/tests/e2e-pw/utils/editor.js @@ -10,6 +10,9 @@ const closeWelcomeModal = async ( { page } ) => { }; const disableWelcomeModal = async ( { page } ) => { + await page.waitForLoadState(); + await page.waitForFunction( () => window?.wp?.data ); + const isWelcomeGuideActive = await page.evaluate( () => wp.data.select( 'core/edit-post' ).isFeatureActive( 'welcomeGuide' ) ); From 98e10cbbd4e60c8068560c3f8fb42229292a4ccf Mon Sep 17 00:00:00 2001 From: Adrian Moldovan Date: Mon, 26 Feb 2024 17:31:22 +0200 Subject: [PATCH 9/9] Add changelog --- .../woocommerce/changelog/e2e-disable-editor-welcome-guide | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 plugins/woocommerce/changelog/e2e-disable-editor-welcome-guide diff --git a/plugins/woocommerce/changelog/e2e-disable-editor-welcome-guide b/plugins/woocommerce/changelog/e2e-disable-editor-welcome-guide new file mode 100644 index 000000000000..f9c04ce0808e --- /dev/null +++ b/plugins/woocommerce/changelog/e2e-disable-editor-welcome-guide @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + +E2E tests: improve execution time by disabling the welcomeGuide feature instead of waiting for the modal