Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Try to fix E2E tests once and for all #6337

Merged
merged 29 commits into from
May 1, 2022
Merged

Conversation

alexflorisca
Copy link
Member

@alexflorisca alexflorisca commented Apr 27, 2022

After digging a little deeper, there were some actual issues that were making the tests fail, not just flakiness. Saying that, there are still some of those funky looking errors we all love:

Test suite failed to run

Expected an Error, but "" was thrown

From the jest repo, it looks like something outside of the tests is failing. Didn't have time to dig into this one though.

Also note there might be a few irrelevant github workflows changed, only because of updated linting

Fixes #6286

So what went wrong?

Flakey switchUserToAdmin().

The wordpress/e2e-test-utils function switchUserToAdmin() is flakey and seems to fail quite often. Instead we should use merchant.login() which seems a bit more stable. My guess is because of this line. But either way, Gutenberg is migrating to Playwright and those test-utils are not being actively maintained any more so I wouldn't rely on them too much going forward.

Missing woo-test-helper plugin

The woo-test-helper plugin was missing from the E2E tests (with Gutenberg) github action. There are a couple of sneaky lines of code that overrides the plugins entry of the .wp-env.json . If you don't know they exist, it's very easy to miss when adding a new plugin to the wordpress test env.

I created ./bin/wp-env-with-gutenberg.js script to extend the existing .wp-env.json with the Gutenberg plugin. This could be extended in the future with other features if needed (passing command line args, etc), but kept it simple for now. The benefit is you only have to define the wp-env config in one place.

goToCheckout() and goToCart() functions were not waiting for the block to load

AS it says on the tin. We were waiting for the page to load, but not for the blocks to finish loading. This was causing flakiness when sometimes the assertions would run after the block was loaded (and pass) and sometimes before (and would fail)

Placing orders without filling in the checkout

There were a couple of instances where we were calling shopper.block.placeOrder() and the checking for order summary page, without actually filling in the details on the checkout page. This sometimes worked because the tests that run before it may have stored some details in the browser cache, and hence the flakiness. If these tests were to run first, it would almost certainly fail as there would be no details entered.

Calling page.waitForNavigation() and page.click()

The visitBlockPage was calling page.waitForNavigation() after page.click(). With this approach, there are some rare cases where the page can navigate immediately after the click and before the waitForNavigation has had a chance to register its event handlers. The recommended approach from the puppeteer docs is

await Promise.all( [
	page.waitForNavigation( { waitUntil: 'networkidle0' } ),
	page.click( '#search-submit' ),
] );

Use networkidle0 instead of domcontentloaded when navigating

There were a couple of instances that were using page.waitForNavigation( { waitUntil: 'domcontentloaded' } ). This might work for shortcode based pages, but blocks tend to load more resources async after dom content loaded, so we should use { waitUntil: 'networkidle0' } for extra safety to make sure all resources have loaded after a page navigation.

To Test

  1. Tests pass in CI

@rubikuserbot rubikuserbot requested review from a team and nielslange and removed request for a team April 27, 2022 14:25
@alexflorisca alexflorisca changed the title Try to fix E2E tests once and for all WIP: Try to fix E2E tests once and for all Apr 27, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Apr 27, 2022

Size Change: +689 B (0%)

Total Size: 871 kB

Filename Size Change
build/active-filters.js 7.42 kB -1 B (0%)
build/all-products.js 33.4 kB +3 B (0%)
build/all-reviews.js 7.78 kB -1 B (0%)
build/attribute-filter-frontend.js 17.7 kB -7 B (0%)
build/attribute-filter.js 13.7 kB -17 B (0%)
build/cart.js 44.3 kB +11 B (0%)
build/checkout.js 45.6 kB +4 B (0%)
build/featured-category.js 12.5 kB +373 B (+3%)
build/featured-product.js 11 kB +332 B (+3%)
build/handpicked-products.js 7.11 kB +1 B (0%)
build/legacy-template.js 2.18 kB -5 B (0%)
build/mini-cart-contents.js 22.7 kB -7 B (0%)
build/mini-cart.js 6.1 kB +2 B (0%)
build/price-filter.js 8.71 kB -3 B (0%)
build/product-add-to-cart--product-button--product-image--product-title.js 2.65 kB -1 B (0%)
build/product-add-to-cart--product-button.js 565 B +1 B (0%)
build/product-add-to-cart.js 6.64 kB +1 B (0%)
build/product-best-sellers.js 7.39 kB +1 B (0%)
build/product-button.js 1.08 kB +1 B (0%)
build/product-categories.js 2.78 kB -2 B (0%)
build/product-category-list.js 500 B -1 B (0%)
build/product-category.js 8.49 kB +2 B (0%)
build/product-new.js 7.68 kB -1 B (0%)
build/product-on-sale.js 7.99 kB +2 B (0%)
build/product-price.js 1.5 kB -1 B (0%)
build/product-rating.js 736 B +5 B (+1%)
build/product-sale-badge.js 678 B -2 B (0%)
build/product-search.js 2.18 kB +2 B (0%)
build/product-stock-indicator.js 621 B +1 B (0%)
build/product-summary.js 918 B -1 B (0%)
build/product-tag-list.js 495 B -1 B (0%)
build/product-tag.js 7.81 kB +2 B (0%)
build/product-top-rated.js 7.91 kB -1 B (0%)
build/products-by-attribute.js 8.38 kB -1 B (0%)
build/reviews-by-category.js 11.2 kB -1 B (0%)
build/single-product.js 10 kB +2 B (0%)
build/stock-filter.js 6.93 kB -2 B (0%)
build/wc-blocks-vendors.js 71.4 kB -1 B (0%)
ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 6.59 kB
build/all-products-frontend.js 18.1 kB
build/blocks-checkout.js 17.4 kB
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.16 kB
build/cart-blocks/cart-express-payment-frontend.js 5.24 kB
build/cart-blocks/cart-items-frontend.js 299 B
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.27 kB
build/cart-blocks/cart-line-items-frontend.js 433 B
build/cart-blocks/cart-order-summary-frontend.js 1.1 kB
build/cart-blocks/cart-totals-frontend.js 322 B
build/cart-blocks/empty-cart-frontend.js 346 B
build/cart-blocks/filled-cart-frontend.js 783 B
build/cart-blocks/order-summary-coupon-form-frontend.js 2.81 kB
build/cart-blocks/order-summary-discount-frontend.js 2.31 kB
build/cart-blocks/order-summary-fee-frontend.js 273 B
build/cart-blocks/order-summary-heading-frontend.js 454 B
build/cart-blocks/order-summary-shipping--checkout-blocks/order-summary-shipping-frontend.js 6.34 kB
build/cart-blocks/order-summary-shipping-frontend.js 428 B
build/cart-blocks/order-summary-subtotal-frontend.js 273 B
build/cart-blocks/order-summary-taxes-frontend.js 433 B
build/cart-blocks/proceed-to-checkout-frontend.js 1.15 kB
build/cart-frontend.js 45.5 kB
build/checkout-blocks/actions-frontend.js 1.41 kB
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.12 kB
build/checkout-blocks/billing-address-frontend.js 889 B
build/checkout-blocks/contact-information-frontend.js 2.83 kB
build/checkout-blocks/express-payment-frontend.js 5.53 kB
build/checkout-blocks/fields-frontend.js 345 B
build/checkout-blocks/order-note-frontend.js 1.07 kB
build/checkout-blocks/order-summary-cart-items-frontend.js 3.67 kB
build/checkout-blocks/order-summary-coupon-form-frontend.js 2.96 kB
build/checkout-blocks/order-summary-discount-frontend.js 2.43 kB
build/checkout-blocks/order-summary-fee-frontend.js 275 B
build/checkout-blocks/order-summary-frontend.js 1.11 kB
build/checkout-blocks/order-summary-shipping-frontend.js 603 B
build/checkout-blocks/order-summary-subtotal-frontend.js 273 B
build/checkout-blocks/order-summary-taxes-frontend.js 432 B
build/checkout-blocks/payment-frontend.js 7.84 kB
build/checkout-blocks/shipping-address-frontend.js 995 B
build/checkout-blocks/shipping-methods-frontend.js 4.71 kB
build/checkout-blocks/terms-frontend.js 1.22 kB
build/checkout-blocks/totals-frontend.js 326 B
build/checkout-frontend.js 47.7 kB
build/mini-cart-component-frontend.js 16.6 kB
build/mini-cart-contents-block/empty-cart-frontend.js 328 B
build/mini-cart-contents-block/filled-cart-frontend.js 230 B
build/mini-cart-contents-block/footer--mini-cart-contents-block/products-table-frontend.js 4.69 kB
build/mini-cart-contents-block/footer-frontend.js 5.63 kB
build/mini-cart-contents-block/items-frontend.js 225 B
build/mini-cart-contents-block/products-table-frontend.js 289 B
build/mini-cart-contents-block/shopping-button-frontend.js 287 B
build/mini-cart-contents-block/title-frontend.js 366 B
build/mini-cart-frontend.js 1.72 kB
build/price-filter-frontend.js 12.5 kB
build/price-format.js 1.19 kB
build/product-add-to-cart--product-button--product-category-list--product-image--product-price--product-r--a0326d00.js 223 B
build/product-add-to-cart-frontend.js 6.96 kB
build/product-button--product-category-list--product-image--product-price--product-rating--product-sale-b--e17c7c01.js 500 B
build/product-button-frontend.js 1.84 kB
build/product-category-list-frontend.js 924 B
build/product-image-frontend.js 1.84 kB
build/product-image.js 1.07 kB
build/product-price-frontend.js 1.94 kB
build/product-rating-frontend.js 1.15 kB
build/product-sale-badge-frontend.js 1.09 kB
build/product-sku-frontend.js 380 B
build/product-sku.js 382 B
build/product-stock-indicator-frontend.js 1.03 kB
build/product-summary-frontend.js 1.33 kB
build/product-tag-list-frontend.js 918 B
build/product-title-frontend.js 1.3 kB
build/product-title.js 910 B
build/reviews-by-product.js 12.2 kB
build/reviews-frontend.js 7 kB
build/single-product-frontend.js 21.5 kB
build/stock-filter-frontend.js 6.87 kB
build/vendors--cart-blocks/cart-line-items--cart-blocks/cart-order-summary--cart-blocks/order-summary-shi--c02aad66-frontend.js 5.26 kB
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.14 kB
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--5b8feb0b-frontend.js 4.75 kB
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--decc3dc6-frontend.js 20.5 kB
build/vendors--mini-cart-contents-block/footer-frontend.js 6.86 kB
build/vendors--product-add-to-cart-frontend.js 7.53 kB
build/wc-blocks-data.js 9.87 kB
build/wc-blocks-editor-style-rtl.css 4.92 kB
build/wc-blocks-editor-style.css 4.92 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 930 B
build/wc-blocks-registry.js 2.7 kB
build/wc-blocks-shared-context.js 1.52 kB
build/wc-blocks-shared-hocs.js 1.14 kB
build/wc-blocks-style-rtl.css 22 kB
build/wc-blocks-style.css 22 kB
build/wc-blocks-vendors-style-rtl.css 1.28 kB
build/wc-blocks-vendors-style.css 1.28 kB
build/wc-blocks.js 2.63 kB
build/wc-payment-method-bacs.js 816 B
build/wc-payment-method-cheque.js 811 B
build/wc-payment-method-cod.js 909 B
build/wc-payment-method-paypal.js 837 B
build/wc-settings.js 2.61 kB

compressed-size-action

@alexflorisca alexflorisca requested a review from wavvves April 28, 2022 14:10
- name: E2E Tests (WP latest with Gutenberg plugin)
env:
WOOCOMMERCE_BLOCKS_PHASE: 3
GUTENBERG_EDITOR_CONTEXT: 'gutenberg'
run: |
chmod -R 767 ./ #needed for permissions issues
JSON='{"plugins": ["https://downloads.wordpress.org/plugin/woocommerce.latest-stable.zip","https://github.com/WP-API/Basic-Auth/archive/master.zip","https://downloads.wordpress.org/plugin/gutenberg.latest-stable.zip", "."] }'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We longer install Basic-Auth?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line has moved to wp-env-with-gutenberg.js, we still use Basic-Auth I think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@senadir this was overwriting completely the JSON file, and Alex's changes read the JSON and only push the Gutenberg entry on the "plugins" object, so the rest remains unchanged.

@alexflorisca alexflorisca changed the title WIP: Try to fix E2E tests once and for all Try to fix E2E tests once and for all Apr 29, 2022
@@ -111,6 +105,7 @@ jobs:
run: |
npm run wp-env start
npm run wp-env clean all
mkdir -p reports/e2e/screenshots
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work on the CI? I expect this to work locally, but I am not aware if something like this is supported on the CI? Would we have screenshots uploaded when a test fails?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually realised @opr already added screenshots to failing tests 2 months ago, so I'll remove this, thanks for reminding me. And yeah, the mkdir command should work in CI, as we are specifying running it on ubuntu, and mkdir is installed by default. There are safer ways to do it though for sure!

Copy link
Contributor

@ralucaStan ralucaStan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work!

@@ -1,22 +1,22 @@
name: "Close stale issues"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn’t any relevant change in this file for the tests right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope this is just linting corections

},

goToCheckout: async () => {
await shopper.block.goToBlockPage( 'Checkout' );
// Wait for Checkout block to finish loading
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add extra details here and for the previous utils that it is good practice to wait for the block to load, otherwise we will get flaky tests.

shippingName
);

// eslint throws an errors saying this is aoutside
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// eslint throws an errors saying this is aoutside
// eslint throws an errors saying this is outside

await expect( page ).toMatchElement(
'.wc-block-components-totals-shipping .wc-block-formatted-money-amount',
{
text: shippingPrice,
timeout: 5000,
timeout: 30000,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed, I would add a small comment if so

@github-actions github-actions bot added this to the 7.6.0 milestone Apr 29, 2022
@alexflorisca alexflorisca merged commit 96bed2e into trunk May 1, 2022
@alexflorisca alexflorisca deleted the fix/e2e-tests-take-3 branch May 1, 2022 11:33
@opr opr added tools Used for work on build or release tools. skip-changelog PRs that you don't want to appear in the changelog. category: tests labels May 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
skip-changelog PRs that you don't want to appear in the changelog. tools Used for work on build or release tools.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

E2E flaky tests
5 participants