Skip to content

Add E2E tests for Enhanced Conversions data collection during WPForms submissions#13162

Open
JakePT wants to merge 5 commits into
developfrom
enhancement/12013-wpforms-ecee-e2e-tests
Open

Add E2E tests for Enhanced Conversions data collection during WPForms submissions#13162
JakePT wants to merge 5 commits into
developfrom
enhancement/12013-wpforms-ecee-e2e-tests

Conversation

@JakePT

@JakePT JakePT commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Summary

Addresses issue:

Relevant technical choices

  • The IB calls for installing WPForms Lite for the test, but that appears to have already been done.
  • The IB called for using wp ability run to create forms but the oldest version of WPForms Lite that supports this command does not support WordPress 5.2 so I registered a custom CLI command in tests/playwright/docker/wordpress/plugins/enhanced-conversions.php and called that to do it with PHP.
  • The IB called for using helpers to activate conversion tracking slated for Add E2E tests for Enhanced Conversions data collection during WooCommerce purchases #12012 but in light of this comment I opted to use a call to the existing REST endpoint for this setting, but added a filter to the test plugin that allowed the request to be made unauthenticated.

I started with the implement-issue skill with Codex and gpt-5.6-sol and it went pretty well. It caught the issue with the ability command in the IB but it needed a fair amount of handholding to implement a different approach. Because the original IB had the form creation in the CLI it tried to do a different approach entirely within the CLI and needed to be guided towards a cleaner solution. The other results still needed a lot of work but that was not really anything to do with the skill, and more with how the model implemented the IB.

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 7.4.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

Do not alter or remove anything below. The following sections will be managed by moderators only.

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.
  • Ensure there are no unexpected significant changes to file sizes.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown

🤖 This comment is automatically updated by CI workflows. Each section is managed independently.

🎭 Playwright reports for bc00f45:

Comment thread tests/playwright/bin/generate-backup-sql.sh

@eugene-manuilov eugene-manuilov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @JakePT. This is a good start. Left a number of comments for you. Please, take a look.

env:
# Update this date suffix (YYYYMMDD) whenever the bundled plugins in the playwright-wp Dockerfile change.
PLAYWRIGHT_WP_DATE_SUFFIX: '20260715'
PLAYWRIGHT_WP_DATE_SUFFIX: '20260722'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to change the image version if the Dockerfile hasn't been changed. Since the wpforms plugin has already been added to the image, no changes to the Dockerfile are needed. So, please revert the tag changes in this PR.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test.describe.configure( { mode: 'serial' } );

test.beforeEach( async ( { wp } ) => {
await wp.activatePlugin( 'wpforms-lite/wpforms.php' );

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be done using withPlugins.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eugene-manuilov It looks like withPlugins only works with plugins in google-site-kit-test-plugins/. I see a few options:

  • Update withPlugins to fall back to plugins outside that directory.
  • Split withPlugins into withPlugins and withTestPlugins for plugins in google-site-kit-test-plugins/.
  • Stick with wp.activatePlugin.

What do you think?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update withPlugins to fall back to plugins outside that directory.

Yes, let's update withPlugins to allow other plugins to be enabled as well. Perhaps we can consider plugins with / as 3rd plugins and not prepend google-site-kit-test-plugins/?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eugene-manuilov I've updated withPlugins to not prepend the test plugins directory if the plugin file name includes a /.

'WPForms Enhanced Conversions',
{ annotation: [ plugins, anonymousUser ] },
() => {
test.describe.configure( { mode: 'serial' } );

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests must run in parallel.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eugene-manuilov I've removed this setting.

Comment on lines +119 to +132
async verifyEmailFormEvent(): Promise< void > {
await this.fillAndSubmit( [ SAMPLE_FORM_DATA.email ] );

const payload = await waitForGTagEvent( this.page, 'submit_lead_form' );

expect( payload ).toMatchObject( {
event_source: 'site-kit',
googlesitekit_event_provider: 'wpforms',
user_data: {
email: SAMPLE_FORM_DATA.email.normalizedValue,
},
} );
expect( payload.googlesitekit_form_id ).toMatch( /^\d+$/ );
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These verify* methods should be actual Playwright tests. Please, move them into the spec file.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eugene-manuilov My thinking here was to make potential future specs for other form plugins as minimal as possible by making these shared methods available, and this is the same pattern used by email-reporting-page.ts and pdf-generation-page.ts, which also have verify* methods that call expect() in the page object. What do you think?

* @param eventName The gtag event name.
* @return The event payload, or null when the event has not fired.
*/
export function getGTagEvent(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getGTagEvent and waitForGTagEvent functions should be part of the FormsPage page object class.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +24 to +39
add_filter(
'rest_endpoints',
function ( $endpoints ) {
$route = '/' . Google\Site_Kit\Core\REST_API\REST_Routes::REST_ROOT . '/core/site/data/conversion-tracking';

foreach ( array_keys( $endpoints[ $route ] ) as $key ) {
if ( 'namespace' === $key ) {
continue;
}

$endpoints[ $route ][ $key ]['permission_callback'] = '__return_true';
}

return $endpoints;
}
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... I can't say I like this. Instead of changing our REST route permissions, we should use a different approach to send information from tests to e2e plugins. For example, we can do it similarly to how we send other dynamic information. This will require you to set a special cookie for tests that need enhanced conversion enabled, and then use a filter hook to override the setting if the cookie is set in the request. See how we do it to set user or module information.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eugene-manuilov I've changed the approach to add a withConversionTracking annotation that sets a cookie that an MU plugin uses to filter the setting value, following the pattern used by other annotations like withFeatureFlags.

Comment on lines +146 to +148
if ( defined( 'WP_CLI' ) && WP_CLI ) {
WP_CLI::add_command( 'site-kit-e2e create-wpforms-fixtures', 'google_site_kit_e2e_create_wpforms_fixtures' );
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's probably move this code that generates test forms and pages to a new file wpforms.php in the tests/playwright/bin folder and then execute it using the wp eval-file command? Something like this:

cat wpforms.php | wp eval-file -

In this case, this code will be close to the script that actually generates data and won't mess with the plugin we use for testing.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eugene-manuilov I've moved this code to tests/playwright/bin/create-wpforms-fixtures.php, which is run during backup with wp eval-file.

@JakePT

JakePT commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator Author

@eugene-manuilov I've addressed all of your feedback except for this one where I've left a comment. Playwright / WordPress 5.2.21 is failing but I'll probably need your help understanding what's going on there. It looks like WPForms isn't active so maybe something is wrong with how I've used withPlugins?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants