diff --git a/tests/e2e/specs/smoke-tests/update-woocommerce.js b/tests/e2e/specs/smoke-tests/update-woocommerce.js index a6c2794b884..1aef2383a4e 100644 --- a/tests/e2e/specs/smoke-tests/update-woocommerce.js +++ b/tests/e2e/specs/smoke-tests/update-woocommerce.js @@ -41,4 +41,9 @@ utils.describeIf( UPDATE_WC )( 'WooCommerce plugin can be uploaded and activated await merchant.uploadAndActivatePlugin( pluginPath, pluginName ); }); + it( 'can run the database update', async () => { + // Check for, and run, the database upgrade if needed + await merchant.runDatabaseUpdate(); + }); + }); diff --git a/tests/e2e/utils/CHANGELOG.md b/tests/e2e/utils/CHANGELOG.md index 05cb246aa6b..17a2b5d2d83 100644 --- a/tests/e2e/utils/CHANGELOG.md +++ b/tests/e2e/utils/CHANGELOG.md @@ -12,6 +12,7 @@ - Added `describeIf()` to conditionally run a test suite - Added `itIf()` to conditionally run a test case. - Added merchant workflows around plugins: `uploadAndActivatePlugin()`, `activatePlugin()`, `deactivatePlugin()`, `deletePlugin()` +- Added merchant workflows checking for a database update and performing the update if needed: `runDatabaseUpdate()` - Added `deleteAllOrders()` that goes through and deletes all orders - Added `deleteAllShippingClasses()` which permanently deletes all shipping classes using the API - Added `statuses` optional parameter to `deleteAllRepositoryObjects()` to delete on specific statuses diff --git a/tests/e2e/utils/README.md b/tests/e2e/utils/README.md index 4bc56544746..5d1cc3831d7 100644 --- a/tests/e2e/utils/README.md +++ b/tests/e2e/utils/README.md @@ -109,6 +109,7 @@ This package provides support for enabling retries in tests: | `updateWordPress` | | Install pending WordPress updates on Dashboard -> Updates| | `updatePlugins` | | Install all pending plugin updates on Dashboard -> Updates| | `updateThemes` | | Install all pending theme updates on Dashboard -> Updates| +| `runDatabaseUpdate` || Runs the database update if needed | ### Shopper `shopper` @@ -133,7 +134,7 @@ This package provides support for enabling retries in tests: | `removeFromCart` | `productTitle` | Remove a product from the cart on the cart page | | `setCartQuantity` | `productTitle, quantityValue` | Change the quantity of a product on the cart page | | `searchForProduct` | | Searching for a product name and landing on its detail page | -| `emptyCart` | | Removes any products and coupons that are in the cart | +| `emptyCart` | | Removes any products and coupons that are in the cart | ### REST API `withRestApi` diff --git a/tests/e2e/utils/package.json b/tests/e2e/utils/package.json index 89994c56a72..ab2a83dfb8a 100644 --- a/tests/e2e/utils/package.json +++ b/tests/e2e/utils/package.json @@ -2,7 +2,7 @@ "name": "@woocommerce/e2e-utils", "version": "0.1.5", "description": "End-To-End (E2E) test utils for WooCommerce", - "homepage": "https://github.com/woocommerce/woocommerce/tree/trunk/tests/e2e-utils/README.md", + "homepage": "https://github.com/woocommerce/woocommerce/tree/trunk/tests/utils/README.md", "repository": { "type": "git", "url": "https://github.com/woocommerce/woocommerce.git" diff --git a/tests/e2e/utils/src/flows/merchant.js b/tests/e2e/utils/src/flows/merchant.js index 2708d8b30f4..d86acff8522 100644 --- a/tests/e2e/utils/src/flows/merchant.js +++ b/tests/e2e/utils/src/flows/merchant.js @@ -380,6 +380,34 @@ const merchant = { // Wait for Ajax calls to finish await page.waitForResponse( response => response.status() === 200 ); + }, + + /** + * Runs the database update if needed. For example, after uploading the WooCommerce plugin or updating WooCommerce. + */ + runDatabaseUpdate: async () => { + if ( await page.$( '.updated.woocommerce-message.wc-connect' ) !== null ) { + await expect( page ).toMatchElement( 'a.wc-update-now', { text: 'Update WooCommerce Database' } ); + await expect( page ).toClick( 'a.wc-update-now' ); + await page.waitForNavigation( { waitUntil: 'networkidle0' } ); + await merchant.checkDatabaseUpdateComplete(); + } + }, + + /** + * Checks if the database update is complete, if not, refresh the page until it is. + */ + checkDatabaseUpdateComplete: async () => { + await page.reload( { waitUntil: [ 'networkidle0', 'domcontentloaded'] } ); + + const thanksButtonSelector = 'a.components-button.is-primary'; + + if ( await page.$( thanksButtonSelector ) !== null ) { + await expect( page ).toMatchElement( thanksButtonSelector, { text: 'Thanks!' } ); + await expect( page ).toClick( thanksButtonSelector ); + } else { + await merchant.checkDatabaseUpdateComplete(); + } }, };