-
Notifications
You must be signed in to change notification settings - Fork 72
Migrate shopper free trial subscription purchase to Playwright #10159
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
Merged
tpaksu
merged 7 commits into
develop
from
dev/10086-playwright-migration-shopper-subscriptions-purchase-free-trial
Jan 23, 2025
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
985a251
Migrate shopper free trial subscription purchase to Playwright
tpaksu e7bf581
Merge branch 'develop' into dev/10086-playwright-migration-shopper-su…
tpaksu a64d53f
Remove duplicates
tpaksu 6e78873
Merge branch 'develop' into dev/10086-playwright-migration-shopper-su…
tpaksu 81034ef
Merge branch 'develop' into dev/10086-playwright-migration-shopper-su…
tpaksu 3496fdc
Simplify test by removing customer deletion and class locators
tpaksu c6ac2c6
Merge branch 'develop' into dev/10086-playwright-migration-shopper-su…
tpaksu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
changelog/dev-10086-playwright-migration-shopper-subscriptions-purchase-free-trial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: dev | ||
|
||
Migrate shopper subscription free-trial purchase E2E test to Playwright |
171 changes: 171 additions & 0 deletions
171
tests/e2e-pw/specs/shopper/shopper-subscriptions-purchase-free-trial.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import test, { expect } from '@playwright/test'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { shouldRunSubscriptionsTests } from '../../utils/constants'; | ||
import { describeif, getMerchant, getShopper } from '../../utils/helpers'; | ||
import RestAPI from '../../utils/rest-api'; | ||
import { config } from '../../config/default'; | ||
import { | ||
confirmCardAuthentication, | ||
emptyCart, | ||
fillCardDetails, | ||
setupCheckout, | ||
} from '../../utils/shopper'; | ||
import { | ||
goToCart, | ||
goToProductPageBySlug, | ||
} from '../../utils/shopper-navigation'; | ||
import { goToOrder, goToSubscriptions } from '../../utils/merchant-navigation'; | ||
|
||
const nowLocal = new Date(); | ||
const nowUTC = new Date( | ||
nowLocal.getUTCFullYear(), | ||
nowLocal.getUTCMonth(), | ||
nowLocal.getUTCDate() | ||
); | ||
const formatter = new Intl.DateTimeFormat( 'en-US', { | ||
dateStyle: 'long', | ||
} ); | ||
const renewalDate = nowUTC.setDate( nowUTC.getDate() + 14 ); | ||
const renewalDateFormatted = formatter.format( renewalDate ); | ||
const productName = 'Subscription free trial product'; | ||
const productSlug = 'subscription-free-trial-product'; | ||
const customerBilling = config.addresses.customer.billing; | ||
const customerBillingConfig = | ||
config.addresses[ 'subscriptions-customer' ].billing; | ||
let orderId, subscriptionId; | ||
|
||
const testSelectors = { | ||
productSubscriptionDetails: '.summary span.subscription-details', | ||
cartSubscriptionDetails: '.product-price span.subscription-details', | ||
cartSubscriptionFirstPaymentDate: '.first-payment-date', | ||
cartOrderTotal: 'tr.order-total:not(.recurring-total) td', | ||
checkoutSubscriptionDetails: 'span.subscription-details', | ||
checkoutSubscriptionFirstPaymentDate: '.first-payment-date', | ||
checkoutPlaceOrderButton: '#place_order', | ||
checkoutOrderId: '.woocommerce-order-overview__order.order > strong', | ||
checkoutSubscriptionId: 'td.subscription-id > a', | ||
wcOrderPaymentId: '.woocommerce-order-data__meta', | ||
subscriptionStatus: '.subscription-status', | ||
subscriptionProductName: '.order-item', | ||
subscriptionRecurringTotal: '.recurring_total', | ||
subscriptionTrialEnd: 'time.trial_end_date', | ||
}; | ||
|
||
describeif( shouldRunSubscriptionsTests )( | ||
'Shopper: Subscriptions - Purchase Free Trial', | ||
() => { | ||
test.beforeAll( async ( {}, { project } ) => { | ||
const restApi = new RestAPI( project.use.baseURL ); | ||
await restApi.deleteCustomerByEmailAddress( | ||
customerBillingConfig.email | ||
); | ||
} ); | ||
|
||
test( 'Merchant should be able to purchase a free trial', async ( { | ||
browser, | ||
} ) => { | ||
const { shopperPage } = await getShopper( browser ); | ||
tpaksu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Just to be sure, empty the cart | ||
await emptyCart( shopperPage ); | ||
|
||
// Open the subscription product, and verify that the | ||
// 14-day free trial is shown in the product description | ||
await goToProductPageBySlug( shopperPage, productSlug ); | ||
await expect( | ||
shopperPage.locator( testSelectors.productSubscriptionDetails ) | ||
).toHaveText( /\s*\/ month with a 14-day free trial\s*/ ); | ||
|
||
// Add it to the cart and verify that the cart page shows the free trial details | ||
await shopperPage.locator( '.single_add_to_cart_button' ).click(); | ||
await goToCart( shopperPage ); | ||
await expect( | ||
shopperPage.locator( testSelectors.cartSubscriptionDetails ) | ||
).toHaveText( /\s*\/ month with a 14-day free trial\s*/ ); | ||
|
||
// Also verify that the first renewal is 14 days from now | ||
await expect( | ||
shopperPage.locator( | ||
testSelectors.cartSubscriptionFirstPaymentDate | ||
) | ||
).toHaveText( `First renewal: ${ renewalDateFormatted }` ); | ||
|
||
// Verify that the order total is $0.00 | ||
await expect( | ||
shopperPage.locator( testSelectors.cartOrderTotal ) | ||
).toHaveText( `$0.00` ); | ||
|
||
// Proceed to the checkout page and verify that the 14-day free trial is shown in the product line item, | ||
// and that the first renewal date is 14 days from now. | ||
await setupCheckout( shopperPage, customerBilling ); | ||
await expect( | ||
shopperPage.locator( testSelectors.checkoutSubscriptionDetails ) | ||
).toHaveText( '/ month with a 14-day free trial' ); | ||
await expect( | ||
shopperPage.locator( | ||
testSelectors.cartSubscriptionFirstPaymentDate | ||
) | ||
).toHaveText( `First renewal: ${ renewalDateFormatted }` ); | ||
|
||
// Pay using a 3DS card | ||
const card = config.cards[ '3dsOTP' ]; | ||
await fillCardDetails( shopperPage, card ); | ||
await shopperPage.click( testSelectors.checkoutPlaceOrderButton ); | ||
await shopperPage.frames()[ 0 ].waitForLoadState( 'load' ); | ||
await confirmCardAuthentication( shopperPage, true ); | ||
await shopperPage.waitForLoadState( 'networkidle' ); | ||
await expect( | ||
shopperPage.getByRole( 'heading', { | ||
name: 'Order received', | ||
} ) | ||
).toBeVisible(); | ||
|
||
// Get the order ID so we can open it in the merchant view | ||
const orderIdField = await shopperPage.$( | ||
testSelectors.checkoutOrderId | ||
); | ||
orderId = await orderIdField.evaluate( ( el ) => el.textContent ); | ||
const subscriptionIdField = await shopperPage.$( | ||
testSelectors.checkoutSubscriptionId | ||
); | ||
subscriptionId = await subscriptionIdField.evaluate( ( el ) => | ||
el.textContent.trim().replace( '#', '' ) | ||
); | ||
} ); | ||
|
||
test( 'Merchant should be able to create an order with "Setup Intent"', async ( { | ||
browser, | ||
} ) => { | ||
const { merchantPage } = await getMerchant( browser ); | ||
await goToOrder( merchantPage, orderId ); | ||
await expect( | ||
merchantPage.locator( testSelectors.wcOrderPaymentId ) | ||
).toHaveText( /\(seti_.*\)/ ); | ||
|
||
await goToSubscriptions( merchantPage ); | ||
const subscriptionRow = await merchantPage.locator( | ||
tpaksu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'#order-' + subscriptionId | ||
); | ||
await expect( | ||
subscriptionRow.locator( testSelectors.subscriptionStatus ) | ||
).toHaveText( 'Active' ); | ||
await expect( | ||
subscriptionRow.locator( testSelectors.subscriptionProductName ) | ||
).toHaveText( productName ); | ||
await expect( | ||
subscriptionRow.locator( | ||
testSelectors.subscriptionRecurringTotal | ||
) | ||
).toHaveText( /\$9\.99/ ); | ||
await expect( | ||
subscriptionRow.locator( testSelectors.subscriptionTrialEnd ) | ||
).toHaveText( renewalDateFormatted ); | ||
} ); | ||
} | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 0 additions & 172 deletions
172
tests/e2e/specs/subscriptions/shopper/shopper-subscriptions-purchase-free-trial.spec.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.