diff --git a/plugins/woocommerce/changelog/e2e-fix-waiting-response-can-create-a-variation-option-and-publish-the-product b/plugins/woocommerce/changelog/e2e-fix-waiting-response-can-create-a-variation-option-and-publish-the-product new file mode 100644 index 00000000000..4f73f5cc6c2 --- /dev/null +++ b/plugins/woocommerce/changelog/e2e-fix-waiting-response-can-create-a-variation-option-and-publish-the-product @@ -0,0 +1,4 @@ +Significance: patch +Type: dev + + diff --git a/plugins/woocommerce/tests/e2e-pw/tests/merchant/products/block-editor/create-variable-product-block-editor.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/merchant/products/block-editor/create-variable-product-block-editor.spec.js index 1c1ff9c0459..081227712b8 100644 --- a/plugins/woocommerce/tests/e2e-pw/tests/merchant/products/block-editor/create-variable-product-block-editor.spec.js +++ b/plugins/woocommerce/tests/e2e-pw/tests/merchant/products/block-editor/create-variable-product-block-editor.spec.js @@ -147,10 +147,25 @@ test.describe( 'Variations tab', { tag: '@gutenberg' }, () => { ); for ( const term of sizeAttribute.terms ) { + const apiResponsePromise = page.waitForResponse( + ( response ) => { + const urlToMatch = `/wp-json/wc/v3/products/attributes/${ newAttrData.id }/terms?name=${ term.name }&slug=${ term.slug }`; + + return ( + response + .url() + .includes( encodeURI( urlToMatch ) ) && + response.status() === 201 + ); + } + ); + // Fill the input field with the option await FormTokenFieldInputLocator.fill( term.name ); await FormTokenFieldInputLocator.press( 'Enter' ); + await apiResponsePromise; + /* * Check the new option is added to the list, * by checking the last aria-hidden @@ -163,21 +178,6 @@ test.describe( 'Variations tab', { tag: '@gutenberg' }, () => { await expect( newAriaHiddenTokenLocator ).toHaveText( term.name ); - - /* - * Wait for the async POST request - * that creates the new attribute term to finish. - */ - await page.waitForResponse( ( response ) => { - const urlToMatch = `/wp-json/wc/v3/products/attributes/${ newAttrData.id }/terms?name=${ term.name }&slug=${ term.slug }&_locale=user`; - - return ( - response - .url() - .includes( encodeURI( urlToMatch ) ) && - response.status() === 201 - ); - } ); } await page