Commit 61bbf121b3a for woocommerce
commit 61bbf121b3acbd840991abe911974bef3931dacc
Author: Wesley Rosa <wesleyjrosa@gmail.com>
Date: Thu Mar 5 10:48:46 2026 -0300
PayPal Standard e2e tests 2 - Jetpack onboarding (#62982)
* Revert "Revert "PayPal Standard e2e tests 1 - enablement" (#62977)"
This reverts commit 3e596189f19d41b946d27df7fb69b2d93af8f071.
* PayPal Standard e2e tests 2 - Jetpack onboarding
* Adding filters to mock Jetpack data
* Cleaning up
* Add changefile(s) from automation for the following project(s): woocommerce
* Simplifying logic
* Removing duplicate changelog entry
* Add changefile(s) from automation for the following project(s): woocommerce
* Simplifying logic
* Fix merge + adding JSDOc
* Removing duplicate file
* Revert unnecessary change
* Applying AI suggestion
* Applying AI suggestion
* Fix playwright config
* Fix playwright config
* Updating test definition in package JSON
* Revert unnecessary change
* Attempt to remove the save button fix
* Adding issue related to save button not getting enabled
* Update plugins/woocommerce/tests/e2e-pw/tests/paypal/paypal.spec.ts
Co-authored-by: daledupreez <dale@automattic.com>
---------
Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
Co-authored-by: daledupreez <dale@automattic.com>
diff --git a/plugins/woocommerce/changelog/62982-add-paypal-standard-e2e-tests-onboarding b/plugins/woocommerce/changelog/62982-add-paypal-standard-e2e-tests-onboarding
new file mode 100644
index 00000000000..f276b34b057
--- /dev/null
+++ b/plugins/woocommerce/changelog/62982-add-paypal-standard-e2e-tests-onboarding
@@ -0,0 +1,4 @@
+Significance: minor
+Type: dev
+
+Introduce end-to-end tests for PayPal Standard (Jetpack onboarding flow).
\ No newline at end of file
diff --git a/plugins/woocommerce/package.json b/plugins/woocommerce/package.json
index b85e5aa014a..55e9c5f333c 100644
--- a/plugins/woocommerce/package.json
+++ b/plugins/woocommerce/package.json
@@ -880,7 +880,11 @@
"testType": "e2e",
"command": "test:e2e:paypal-standard",
"shardingArguments": [],
- "changes": [],
+ "changes": [
+ "includes/gateways/paypal/**/*.php",
+ "src/Gateways/PayPal/**/*.php",
+ "tests/e2e-pw/tests/paypal/**"
+ ],
"events": [
"pull_request",
"push",
diff --git a/plugins/woocommerce/tests/e2e-pw/tests/paypal/paypal-enablement.spec.js b/plugins/woocommerce/tests/e2e-pw/tests/paypal/paypal-enablement.spec.js
deleted file mode 100644
index 14e7e12b97a..00000000000
--- a/plugins/woocommerce/tests/e2e-pw/tests/paypal/paypal-enablement.spec.js
+++ /dev/null
@@ -1,102 +0,0 @@
-/**
- * Internal dependencies
- */
-import { expect, tags } from '../../fixtures/fixtures';
-import { test } from '../../fixtures/paypal-fixtures';
-import { ADMIN_STATE_PATH } from '../../playwright.config';
-
-test.describe(
- 'PayPal Standard Enablement',
- { tag: [ tags.PAYMENTS, tags.PAYPAL ] },
- () => {
- test.use( { storageState: ADMIN_STATE_PATH } );
-
- const visibilityOptions = { timeout: 30000 };
-
- async function openWCSettings( page ) {
- await page.goto( '/wp-admin/index.php', {
- // networkidle is needed to ensure all JS files are loaded and avoid race conditions
- // eslint-disable-next-line playwright/no-networkidle
- waitUntil: 'networkidle',
- } );
-
- await page
- .locator( '#adminmenu' )
- .getByRole( 'link', { name: 'WooCommerce', exact: true } )
- .click();
-
- const wcMenu = page.locator(
- '#toplevel_page_woocommerce .wp-submenu'
- );
- await expect( wcMenu ).toBeVisible();
-
- await wcMenu
- .getByRole( 'link', { name: 'Settings', exact: true } )
- .click();
- }
-
- async function openPayments( page ) {
- await openWCSettings( page );
-
- await page
- .locator( '.woo-nav-tab-wrapper' )
- .getByRole( 'link', {
- name: 'Payments',
- exact: true,
- } )
- .click();
-
- await expect(
- page.locator( '.settings-payment-gateways__header-title' )
- ).toBeVisible( visibilityOptions );
- }
-
- async function waitForPayPalToLoad( page ) {
- const paypalDiv = page.locator( '#paypal' );
- await expect( paypalDiv ).toBeVisible( visibilityOptions );
-
- return paypalDiv;
- }
-
- test( 'PayPal Standard can be enabled', async ( { page } ) => {
- await openPayments( page );
-
- const paypalDiv = await waitForPayPalToLoad( page );
-
- await test.step( 'Enable PayPal Standard', async () => {
- const enableLink = paypalDiv.getByRole( 'link', {
- name: 'Enable',
- } );
- await expect( enableLink ).toBeVisible( visibilityOptions );
- await enableLink.click();
- } );
-
- const labelActive = paypalDiv.getByText( 'Active' );
- const labelTestAccount = paypalDiv.getByText( 'Test account' );
-
- await expect( labelActive.or( labelTestAccount ) ).toBeVisible(
- visibilityOptions
- );
-
- // Clean up by disabling PayPal again.
- await test.step( 'Disable PayPal Standard', async () => {
- await paypalDiv
- .getByRole( 'button', {
- name: 'Payment provider options',
- } )
- .click();
-
- await page
- .getByRole( 'button', {
- name: 'Disable',
- } )
- .click();
-
- // Confirm the Enable button is present again.
- await expect(
- paypalDiv.getByRole( 'link', { name: 'Enable' } )
- ).toBeVisible( visibilityOptions );
- } );
- } );
- }
-);
diff --git a/plugins/woocommerce/tests/e2e-pw/tests/paypal/paypal.spec.ts b/plugins/woocommerce/tests/e2e-pw/tests/paypal/paypal.spec.ts
new file mode 100644
index 00000000000..a83c6f68a87
--- /dev/null
+++ b/plugins/woocommerce/tests/e2e-pw/tests/paypal/paypal.spec.ts
@@ -0,0 +1,231 @@
+/**
+ * External dependencies
+ */
+import { Page } from '@playwright/test';
+
+/**
+ * Internal dependencies
+ */
+import { expect, tags } from '../../fixtures/fixtures';
+import { test } from '../../fixtures/paypal-fixtures';
+import { ADMIN_STATE_PATH } from '../../playwright.config';
+import { setFilterValue } from '../../utils/filters';
+
+test.describe(
+ 'PayPal Standard enablement and Jetpack onboarding',
+ { tag: [ tags.PAYMENTS, tags.PAYPAL ] },
+ () => {
+ test.use( { storageState: ADMIN_STATE_PATH } );
+
+ const visibilityOptions = { timeout: 30000 };
+
+ /**
+ * Navigates to the WooCommerce settings page by clicking on the WooCommerce link in the WordPress admin menu.
+ *
+ * @param {Page} page The Playwright Page object representing the browser page to interact with.
+ */
+ async function openWCSettings( page: Page ) {
+ await page.goto( '/wp-admin/index.php', {
+ // networkidle is needed to ensure all JS files are loaded and avoid race conditions
+ // eslint-disable-next-line playwright/no-networkidle
+ waitUntil: 'networkidle',
+ } );
+
+ await page
+ .locator( '#adminmenu' )
+ .getByRole( 'link', { name: 'WooCommerce', exact: true } )
+ .click();
+
+ const wcMenu = page.locator(
+ '#toplevel_page_woocommerce .wp-submenu'
+ );
+ await expect( wcMenu ).toBeVisible();
+
+ await wcMenu
+ .getByRole( 'link', { name: 'Settings', exact: true } )
+ .click();
+ }
+
+ /**
+ * Navigates to the Payments settings page by first opening the WooCommerce settings and then clicking on the Payments tab.
+ *
+ * @param {Page} page The Playwright Page object representing the browser page to interact with.
+ */
+ async function openPayments( page: Page ) {
+ await openWCSettings( page );
+
+ await page
+ .locator( '.woo-nav-tab-wrapper' )
+ .getByRole( 'link', {
+ name: 'Payments',
+ exact: true,
+ } )
+ .click();
+
+ await expect(
+ page.locator( '.settings-payment-gateways__header-title' )
+ ).toBeVisible( visibilityOptions );
+ }
+
+ /**
+ * Waits for the PayPal Standard section to load on the Payments settings page by checking for the visibility of the PayPal div.
+ *
+ * @param {Page} page The Playwright Page object representing the browser page to interact with.
+ */
+ async function waitForPayPalToLoad( page: Page ) {
+ const paypalDiv = page.locator( '#paypal' );
+ await expect( paypalDiv ).toBeVisible( visibilityOptions );
+
+ return paypalDiv;
+ }
+
+ /**
+ * Temporary function to remove the disabled attribute from the Save changes button, as it is currently disabled by default and prevents saving changes in tests.
+ * This should be removed once the underlying issue is resolved and the Save changes button can be enabled as expected.
+ * See: https://github.com/woocommerce/woocommerce/issues/63498
+ *
+ * @param {Page} page The Playwright Page object representing the browser page to interact with.
+ */
+ async function enableSaveButton( page: Page ) {
+ await page.evaluate( () => {
+ const saveButton = document.querySelector(
+ 'button[name="save"]'
+ );
+ if ( saveButton ) {
+ saveButton.removeAttribute( 'disabled' );
+ }
+ } );
+ }
+
+ test( 'PayPal Standard can be enabled', async ( { page } ) => {
+ await openPayments( page );
+
+ const paypalDiv = await waitForPayPalToLoad( page );
+
+ await test.step( 'Enable PayPal Standard', async () => {
+ const enableLink = paypalDiv.getByRole( 'link', {
+ name: 'Enable',
+ } );
+ await expect( enableLink ).toBeVisible( visibilityOptions );
+ await enableLink.click();
+ } );
+
+ const labelActive = paypalDiv.getByText( 'Active' );
+ const labelTestAccount = paypalDiv.getByText( 'Test account' );
+
+ await expect( labelActive.or( labelTestAccount ) ).toBeVisible(
+ visibilityOptions
+ );
+ } );
+
+ test( 'PayPal Standard onboards to Jetpack upon changing any setting', async ( {
+ page,
+ } ) => {
+ await openPayments( page );
+
+ const paypalDiv = await waitForPayPalToLoad( page );
+
+ // Ensure PayPal Standard is enabled before trying to open the Manage dialog.
+ const enableLink = paypalDiv.getByRole( 'link', {
+ name: 'Enable',
+ } );
+
+ // eslint-disable-next-line playwright/no-conditional-in-test
+ if ( await enableLink.isVisible() ) {
+ await enableLink.click();
+ await expect(
+ paypalDiv
+ .getByText( 'Active' )
+ .or( paypalDiv.getByText( 'Test account' ) )
+ ).toBeVisible( visibilityOptions );
+ }
+
+ await paypalDiv
+ .getByRole( 'button', {
+ name: 'Manage',
+ } )
+ .click();
+
+ // Set up filters to simulate a completed Jetpack onboarding.
+ await setFilterValue( page, 'pre_option_jetpack_options', {
+ id: 12345,
+ } );
+
+ // Simulate a connected Jetpack site with a blog token.
+ await setFilterValue( page, 'pre_option_jetpack_private_options', {
+ blog_token: 'IAM.AJETPACKBLOGTOKEN',
+ } );
+
+ // Mock the response for the PayPal onboarding API request (merchant account data).
+ await setFilterValue( page, 'pre_http_request', {
+ response: {
+ code: 200,
+ message: 'OK',
+ },
+ body: JSON.stringify( {
+ public_id: 'test_public_id',
+ } ),
+ } );
+
+ // Ensure that the filters above are 100% in place by reloading the page.
+ await page.reload();
+
+ const originalPayPalTitle = await page
+ .locator( '#woocommerce_paypal_title' )
+ .inputValue();
+
+ await test.step( 'Update the title field', async () => {
+ await page
+ .locator( '#woocommerce_paypal_title' )
+ .fill( 'PayPal Custom Title ' + Date.now() );
+
+ // TODO: Temporarily removing the disabled attribute from the Save changes button.
+ await enableSaveButton( page );
+
+ await page
+ .getByRole( 'button', {
+ name: 'Save changes',
+ } )
+ .click();
+
+ await expect(
+ page.locator( 'div.updated.inline' )
+ ).toContainText( 'Your settings have been saved.' );
+ } );
+
+ await test.step( 'Check the setting present only when Jetpack onboarding is complete', async () => {
+ const paypalButtonsSetting = page.getByText(
+ 'Enable PayPal Buttons',
+ { exact: true }
+ );
+ await expect( paypalButtonsSetting ).toBeVisible();
+ } );
+
+ // Clean up by reverting the title change and disabling PayPal Standard.
+ await test.step( 'Revert title change and disable PayPal Standard', async () => {
+ await page
+ .locator( '#woocommerce_paypal_title' )
+ .fill( originalPayPalTitle );
+
+ await page
+ .getByRole( 'checkbox', {
+ name: 'Enable PayPal Standard',
+ } )
+ .uncheck();
+
+ // TODO: Temporarily removing the disabled attribute from the Save changes button.
+ await enableSaveButton( page );
+
+ await page
+ .getByRole( 'button', {
+ name: 'Save changes',
+ } )
+ .click();
+
+ await expect(
+ page.locator( 'div.updated.inline' )
+ ).toContainText( 'Your settings have been saved.' );
+ } );
+ } );
+ }
+);