Skip to content

Commit

Permalink
Implement test for check for payment methods in the checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
mescalantea committed Feb 3, 2025
1 parent 6115cc6 commit 6265524
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
31 changes: 24 additions & 7 deletions tests-e2e/fixtures/pages/CheckoutPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ export default class CheckoutPage extends BaseCheckoutPage {
*/
initLocators() {
return {
// ...super.initLocators(),
// messageSuccess: () => this.page.locator('.message-success'),
...super.initLocators(),
loader: () => this.page.locator('.loading-mask', { state: 'visible' }),
email: () => this.page.locator('#customer-email'),
firstName: () => this.page.locator('[name=firstname]'),
lastName: () => this.page.locator('[name=lastname]'),
// locator for selector [name="street[0]"]
address1: () => this.page.locator('[name="street[0]"]'),
country: () => this.page.locator('[name=country_id]'),
state: () => this.page.locator('[name=region_id]'),
Expand Down Expand Up @@ -58,7 +56,7 @@ export default class CheckoutPage extends BaseCheckoutPage {
await this.fillShippingForm(options);
await this.selectShippingMethod(options);
await this.locators.continueButton().click();
// TODO: Implement the form filling
await this.#waitForFinishLoading();
}

/**
Expand All @@ -79,7 +77,6 @@ export default class CheckoutPage extends BaseCheckoutPage {
await this.page.waitForURL(/#shipping/);
await this.#waitForFinishLoading();
const { email, firstName, lastName, address1, country, state, city, postcode, phone } = options;
// TODO: Implement the form filling
await this.locators.email().fill(email);
await this.locators.firstName().fill(firstName);
await this.locators.lastName().fill(lastName);
Expand All @@ -99,8 +96,6 @@ export default class CheckoutPage extends BaseCheckoutPage {
*/
async selectShippingMethod(options) {
await this.page.waitForURL(/#shipping/);
const { shippingMethod } = options;
// TODO: Implement the method selection
await this.#waitForFinishLoading();
this.locators.flatRateShipping().click();
}
Expand All @@ -114,4 +109,26 @@ export default class CheckoutPage extends BaseCheckoutPage {
await this.expect(this.locators.loader().first()).toBeHidden();
} while ((await this.locators.loader()) > 0);
}

/**
* Provide the locator to input the payment method
* @param {Object} options
* @param {string} options.product seQura product (i1, pp3, etc)
* @param {boolean} options.checked Whether the payment method should be checked
* @returns {import("@playwright/test").Locator}
*/
paymentMethodInputLocator(options) {
return this.page.locator(`#sequra_${options.product}${options.checked ? ':checked' : ''}`);
}

/**
* Provide the locator to input the payment method
* @param {Object} options
* @param {string} options.product seQura product (i1, pp3, etc)
* @param {string} options.title Payment method title as it appears in the UI
* @returns {import("@playwright/test").Locator}
*/
paymentMethodTitleLocator(options) {
return this.page.locator(`#sequra_${options.product} + label`).getByText(options.title);
}
}
20 changes: 4 additions & 16 deletions tests-e2e/specs/001-checkout-product.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,16 @@ test.describe('Product checkout', () => {
// Setup
const { dummy_config } = helper.webhooks;
const shopper = dataProvider.shopper();
const paymentMethods = dataProvider.checkoutPaymentMethods();
await helper.executeWebhook({ webhook: dummy_config }); // Setup for physical products.

// Execution
await productPage.addToCart({ slug: 'push-it-messenger-bag', quantity: 1 });
await checkoutPage.goto();
await checkoutPage.fillForm(shopper);
// --

// await productPage.addToCart({ slug: 'sunglasses', quantity: 1 });

// const helper = new SeQuraHelper(request, expect);
// for (const version of ['classic', 'blocks']) {
// await helper.executeWebhook({ webhook: helper.webhooks.CHECKOUT_VERSION, args: [{ name: 'version', value: version }] });
// await checkoutPage.goto();
// if (version === 'blocks') {
// await checkoutPage.expectPaymentMethodsBeingReloaded();
// }
// await checkoutPage.expectI1ToBeVisible();
// await checkoutPage.expectSp1ToBeVisible();
// await checkoutPage.expectPp3ToBeVisible();
// await checkoutPage.expectEducationPopupToWork('100.00');
// }
for (const paymentMethod of paymentMethods) {
await checkoutPage.expectPaymentMethodToBeVisible(paymentMethod);
}
});

// test('Make a successful payment using any shopper name', async ({ productPage, checkoutPage }) => {
Expand Down

0 comments on commit 6265524

Please sign in to comment.