-
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
Migrate the Shopper Renew Subscription E2E test to Playwright #10144
Changes from all commits
a3ec316
9437c51
46f6fcc
defe4bd
b164e97
93aa149
9bfe188
9554e25
8e911d3
5f6e0fe
fba0e5d
f8685fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: dev | ||
|
||
Migrate the Shopper Renew Subscription spec to Playwright and remove the corresponding Puppeteer test. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,25 +76,25 @@ export const config = { | |
}, | ||
'subscriptions-customer': { | ||
billing: { | ||
first_name: 'I am', | ||
last_name: 'Subscriptions Customer', | ||
firstname: 'I am', | ||
lastname: 'Subscriptions Customer', | ||
company: 'Automattic', | ||
country: 'United States (US)', | ||
address_1: '60 29th Street #343', | ||
address_2: 'billing', | ||
addressfirstline: '60 29th Street #343', | ||
addresssecondline: 'billing', | ||
city: 'San Francisco', | ||
state: 'CA', | ||
postcode: '94110', | ||
phone: '123456789', | ||
email: '[email protected]', | ||
}, | ||
shipping: { | ||
first_name: 'I am', | ||
last_name: 'Subscriptions Recipient', | ||
firstname: 'I am', | ||
lastname: 'Subscriptions Recipient', | ||
company: 'Automattic', | ||
country: 'United States (US)', | ||
address_1: '60 29th Street #343', | ||
address_2: 'shipping', | ||
addressfirstline: '60 29th Street #343', | ||
addresssecondline: 'shipping', | ||
city: 'San Francisco', | ||
state: 'CA', | ||
postcode: '94110', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { test, expect, Page } from '@playwright/test'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { config } from '../../config/default'; | ||
import { describeif, getAnonymousShopper } from '../../utils/helpers'; | ||
import * as shopper from '../../utils/shopper'; | ||
import * as navigation from '../../utils/shopper-navigation'; | ||
import { products, shouldRunSubscriptionsTests } from '../../utils/constants'; | ||
import RestAPI from '../../utils/rest-api'; | ||
|
||
describeif( shouldRunSubscriptionsTests )( | ||
'Subscriptions > Renew a subscription in my account', | ||
() => { | ||
const customerBillingConfig = | ||
config.addresses[ 'subscriptions-customer' ].billing; | ||
|
||
let subscriptionId: string; | ||
let page: Page; | ||
|
||
test.beforeAll( async ( { browser }, { project } ) => { | ||
const restApi = new RestAPI( project.use.baseURL ); | ||
await restApi.deleteCustomerByEmailAddress( | ||
customerBillingConfig.email | ||
); | ||
|
||
const { shopperPage } = await getAnonymousShopper( browser ); | ||
page = shopperPage; | ||
} ); | ||
|
||
test( 'should be able to purchase a subscription', async () => { | ||
await shopper.addCartProduct( | ||
page, | ||
products.SUBSCRIPTION_SIGNUP_FEE | ||
); | ||
await shopper.setupCheckout( page, customerBillingConfig ); | ||
await shopper.fillCardDetails( page, config.cards.basic ); | ||
await shopper.placeOrder( page ); | ||
await expect( | ||
page.getByRole( 'heading', { name: 'Order received' } ) | ||
).toBeVisible(); | ||
|
||
subscriptionId = await page | ||
.getByLabel( 'View subscription number' ) | ||
.innerText(); | ||
} ); | ||
|
||
test( 'should be able to renew a subscription in my account', async () => { | ||
await navigation.goToSubscriptions( page ); | ||
|
||
if ( ! subscriptionId ) { | ||
throw new Error( 'Subscription ID is not set' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added this |
||
} | ||
|
||
const numericSubscriptionId = subscriptionId.substring( 1 ); | ||
|
||
await page | ||
.getByLabel( | ||
`View subscription number ${ numericSubscriptionId }` | ||
) | ||
.click(); | ||
|
||
await page.getByText( 'Renew now' ).click(); | ||
await page | ||
.getByText( 'Complete checkout to renew now.' ) | ||
.isVisible(); | ||
await shopper.focusPlaceOrderButton( page ); | ||
await shopper.placeOrder( page ); | ||
await expect( | ||
page.getByRole( 'heading', { name: 'Order received' } ) | ||
).toBeVisible(); | ||
} ); | ||
} | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const shouldRunSubscriptionsTests = | ||
process.env.SKIP_WC_SUBSCRIPTIONS_TESTS !== '1'; | ||
|
||
export const products = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unsure about the names of those constants. I wanted to use |
||
SUBSCRIPTION_SIGNUP_FEE: 70, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { HTTPClientFactory } from '@woocommerce/api'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { config } from '../config/default'; | ||
|
||
const userEndpoint = '/wp/v2/users'; | ||
|
||
class RestAPI { | ||
private baseUrl: string; | ||
|
||
constructor( baseUrl: string ) { | ||
if ( ! baseUrl ) { | ||
throw new Error( 'Base URL is required.' ); | ||
} | ||
this.baseUrl = baseUrl; | ||
} | ||
|
||
private getAdminClient() { | ||
return HTTPClientFactory.build( this.baseUrl ) | ||
.withBasicAuth( | ||
config.users.admin.username, | ||
config.users.admin.password | ||
) | ||
.create(); | ||
} | ||
|
||
/** | ||
* Deletes a customer account by their email address if the user exists. | ||
* | ||
* Copied from https://github.com/woocommerce/woocommerce/blob/trunk/packages/js/e2e-utils/src/flows/with-rest-api.js#L374 | ||
* | ||
* @param {string} emailAddress Customer user account email address. | ||
* @return {Promise<void>} | ||
*/ | ||
async deleteCustomerByEmailAddress( | ||
emailAddress: string | ||
): Promise< void > { | ||
const client = this.getAdminClient(); | ||
|
||
const query = { | ||
search: emailAddress, | ||
context: 'edit', | ||
}; | ||
const customers = await client.get( userEndpoint, query ); | ||
|
||
if ( customers.data && customers.data.length ) { | ||
for ( let c = 0; c < customers.data.length; c++ ) { | ||
const deleteUser = { | ||
id: customers.data[ c ].id, | ||
force: true, | ||
reassign: 1, | ||
}; | ||
|
||
await client.delete( | ||
`${ userEndpoint }/${ deleteUser.id }`, | ||
deleteUser | ||
); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default RestAPI; |
This file was deleted.
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're using
project.use.baseURL
to get the same base URL Playwright is using while running the tests.