-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
E2E Playwright Migration: convert Order Manual Capture spec #10180
base: develop
Are you sure you want to change the base?
Conversation
Test the buildOption 1. Jetpack Beta
Option 2. Jurassic Ninja - available for logged-in A12s🚀 Launch a JN site with this branch 🚀 ℹ️ Install this Tampermonkey script to get more options. Build info:
Note: the build is updated when a new commit is pushed to this PR. |
Size Change: 0 B Total Size: 1.36 MB ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for handling it, the conversion looks good at works as intended in most cases. I left a few suggestions 🙂
|
||
test.afterEach( async ( { browser } ) => { | ||
// Merchant go to settings, disable capture later, and then save. | ||
const { merchantPage } = await getMerchant( browser ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every time we call getMerchant
a new browser window is created, to avoid that, we can reuse the same page, doing something like:
test.describe( '...' , () => {
let merchantPage;
test.beforeAll( async ( { browser } => {
merchantPage = ( await getMerchant( browser ) ).merchantPage;
});
Also notice that we could use beforeAll
instead of beforeEach
to call the setup part only once.
// Merchant go to settings, enable capture later, and then save. | ||
const { merchantPage } = await getMerchant( browser ); | ||
await goToWooPaymentsSettings( merchantPage ); | ||
await merchantPage.getByTestId( 'capture-later-checkbox' ).click(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can lead to flaky tests because it just clicks the checkbox instead of unchecking it, which does the opposite of what we intend if it's already checked.
We are already following a good pattern to do it properly in the merchant utils.
await emptyCart( shopperPage ); | ||
await goToShop( shopperPage, 1 ); | ||
await setupProductCheckout( shopperPage ); | ||
await fillCardDetails( shopperPage ); | ||
await focusPlaceOrderButton( shopperPage ); | ||
await placeOrder( shopperPage ); | ||
|
||
// Confirm that the order was placed and get the order number. | ||
await shopperPage.waitForURL( /\/order-received\//, { | ||
waitUntil: 'load', | ||
} ); | ||
await expect( | ||
shopperPage.getByRole( 'heading', { name: 'Order received' } ) | ||
).toBeVisible(); | ||
const orderIdField = shopperPage.locator( | ||
'.woocommerce-order-overview__order.order > strong' | ||
); | ||
orderId = await orderIdField.innerText(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be greatly simplified by using the placeOrderWithOptions
helper 🙂
orderId = await placeOrderWithOptions( shopperPage );
await expect( merchantPage.getByTitle( 'On hold' ) ).toHaveText( | ||
'On hold' | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of checking for the text twice, we can use toBeVisble
or toBeAttached
, being the former more commonly used.
); | ||
await expect( | ||
merchantPage.getByText( | ||
/A payment of \$\d+\.\d{2}.* was authorized using WooPayments/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good way to handle unknown prices, although as we're under a controlled environment, it's okay just to use plain text and test for $18.00
, you'll notice that almost every test does that.
merchantPage | ||
.locator( '#woocommerce-order-actions select' ) | ||
.selectOption( 'capture_charge' ); | ||
// Using locator due to there are several buttons "named" Update. | ||
merchantPage | ||
.locator( '#woocommerce-order-actions li#actions button' ) | ||
.click(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to be very careful, it's easy to forget about adding await
to every Playwright action and quite frustrating when you can't find why the test is failing 😅
Fixes #9962
Changes proposed in this Pull Request
saveWooPaymentsSettings
function, it looked for any snackbar on the page, not just the success one.Testing instructions
npm run changelog
to add a changelog file, choosepatch
to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.