Skip to content
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

Update permalink structure using Playwright global setup #35282

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/add-setup-permalinks
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Uses the globa-setup.js to setup permalinks structure
37 changes: 37 additions & 0 deletions plugins/woocommerce/tests/e2e-pw/global-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ const adminPassword = ADMIN_PASSWORD ?? 'password';
const customerUsername = CUSTOMER_USER ?? 'customer';
const customerPassword = CUSTOMER_PASSWORD ?? 'password';

const setupPermalinks = async ( adminPage, baseURL ) => {
console.log( 'Trying to setup permalinks!' );
await adminPage.goto( baseURL + '/wp-admin/options-permalink.php' );
await expect( adminPage.locator( 'div.wrap > h1' ) ).toHaveText(
'Permalink Settings'
);
await adminPage.click( '#custom_selection' );
await adminPage.fill( '#permalink_structure', '/%postname%/' );
await adminPage.click( '#submit' );

console.log( 'Permalinks Set!' );
}

module.exports = async ( config ) => {
const { stateDir, baseURL, userAgent } = config.projects[ 0 ].use;

Expand Down Expand Up @@ -129,6 +142,30 @@ module.exports = async ( config ) => {
process.exit( 1 );
}

// Ensure that permalinks are correctly setup since we can't set it up using wp-env when not using the default WP version.
// More info here: https://github.com/WordPress/gutenberg/issues/28201
let permalinkConfigured = false;
const permalinkRetries = 5;
for ( let i = 0; i < permalinkRetries; i++ ) {
try {
await setupPermalinks( adminPage, baseURL );
permalinkConfigured = true;
break;
} catch ( e ) {
console.log(
`Setting permalink failed, Retrying... ${ i }/${ permalinkRetries }`
);
console.log( e );
}
}

if ( ! permalinkConfigured ) {
console.error(
'Cannot proceed e2e test, as we could not setup permalinks. Please check if the test site has been setup correctly.'
);
process.exit( 1 );
}

// Sign in as customer user and save state
const customerRetries = 5;
for ( let i = 0; i < customerRetries; i++ ) {
Expand Down