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

Enhancement/refactor smoke test #142

Merged
merged 18 commits into from
Sep 19, 2024
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
7 changes: 3 additions & 4 deletions src/features/delete-plugin.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@smoke @local @setup
@smoke @local @setup
Feature: C4466 - Should successfully delete the plugin

Background:
Expand All @@ -13,9 +13,8 @@ Feature: C4466 - Should successfully delete the plugin
Scenario: WP Rocket is installed and activated
Given plugin is installed 'new_release'
And plugin is activated
When I go to 'wp-admin/options-general.php?page=wprocket#dashboard'
And I enable all settings
And I delete plugin
When I delete plugin
Then plugin should delete successfully
Then I must not see any error in debug.log
And I must not see any error in debug.log

6 changes: 2 additions & 4 deletions src/features/settings-export-import.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@smoke @local @export @setup
@smoke @local @export @setup
Feature: C2148 - Should not change the content of existing fields

Background:
Expand All @@ -8,7 +8,6 @@ Feature: C2148 - Should not change the content of existing fields
Given plugin is installed 'previous_stable'
And plugin is activated
And I disabled all settings
And I save settings 'cache' 'cacheLoggedUser'
And I export data '1'
And I enable all settings
When I import data
Expand All @@ -18,15 +17,14 @@ Feature: C2148 - Should not change the content of existing fields
Given plugin is installed 'previous_stable'
And plugin is activated
Given I disabled all settings
And I save settings 'media' 'lazyload'
When I export data '2'
Then data '2' is exported correctly

Scenario: Data exported correctly on latest version
Given plugin is installed 'previous_stable'
And plugin is activated
And I updated plugin to 'new_release'
And I disabled all settings
And I updated plugin to 'new_release'
And I save settings 'media' 'lazyload'
When I export data '3'
Then data '3' is exported correctly
Expand Down
13 changes: 6 additions & 7 deletions src/support/steps/delete-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,21 @@ When('I delete plugin', async function (this: ICustomWorld) {
await this.page.locator('text=Confirm').click();
}

await this.page.waitForLoadState('load', { timeout: 30000 });

// Delete WPR.
await this.page.locator( '#delete-wp-rocket' ).click();

if (await this.page.getByRole('button', { name: 'Yes, delete these files and data' }).isVisible()) {
await this.page.getByRole('button', { name: 'Yes, delete these files and data' }).click();
await expect(this.page.locator('#activate-wp-rocket')).toBeHidden();
return;
}
});

/**
* Executes the step to assert successful deletion of the WP Rocket plugin.
*/
Then('plugin should delete successfully', async function (this: ICustomWorld) {

if (await this.page.getByRole('button', { name: 'Yes, delete these files and data' }).isVisible()) {
await this.page.getByRole('button', { name: 'Yes, delete these files and data' }).click();
await expect(this.page.locator('#activate-wp-rocket')).toBeHidden();
return;
}
// Assert that WPR is deleted successfully
await this.page.waitForSelector('#wp-rocket-deleted');
await expect(this.page.locator('#wp-rocket-deleted')).toBeVisible();
Expand Down
2 changes: 1 addition & 1 deletion src/support/steps/enable-all-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ Then('page loads successfully', async function (this: ICustomWorld) {
expect(response.status()).not.toEqual(404);
});
await this.page.goto(WP_BASE_URL);
await this.page.waitForLoadState('load', { timeout: 30000 });
//Todo: future enahancement, we can do VR compared to nowprocket but if no CNAME is set or correct CNAME is set
});
16 changes: 8 additions & 8 deletions src/support/steps/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Given('I am logged in', async function (this: ICustomWorld) {
*/
Given('plugin is installed {string}', async function (this: ICustomWorld, pluginVersion: string) {
await this.utils.uploadNewPlugin(`./plugin/${pluginVersion}.zip`);
await this.page.waitForLoadState('load', { timeout: 30000 });
await expect(this.page).toHaveURL(/action=upload-plugin/);
});

Expand Down Expand Up @@ -84,7 +83,6 @@ Given('I save settings {string} {string}', async function (this: ICustomWorld, s
await this.sections.state(true).toggle(element);
await this.utils.saveSettings();

await this.page.waitForLoadState('load', { timeout: 30000 });
});

/**
Expand All @@ -107,7 +105,6 @@ When('I log in', async function (this: ICustomWorld) {
*/
When('I go to {string}', async function (this: ICustomWorld, page) {
await this.utils.visitPage(page);
await this.page.waitForLoadState('load', { timeout: 100000 });
});

/**
Expand All @@ -132,12 +129,15 @@ When('I click on {string}', async function (this: ICustomWorld, selector) {
await this.page.locator('#tools_tab').click();
await this.page.waitForSelector('#save_last_major_version');
await this.page.locator('#save_last_major_version').click();
await this.page.waitForLoadState('load', { timeout: 30000 });
await this.utils.gotoWpr();
await this.page.locator('#wpr-nav-tools').click();
await this.page.locator(selector).click();
await this.page.waitForLoadState('load', { timeout: 70000 });
}
await this.page.locator(selector).click();
await this.page.waitForLoadState('load', { timeout: 100000 });
else{
await this.page.locator(selector).click();
}

});

/**
Expand Down Expand Up @@ -280,8 +280,8 @@ Then('I should see {string}', async function (this: ICustomWorld, text) {
*/
Then('I must not see any error in debug.log', async function (this: ICustomWorld){
// Goto WP Rocket dashboard
await this.utils.gotoWpr();
await this.page.waitForLoadState('load', { timeout: 30000 });
await this.utils.gotoPlugin();

// Assert that there is no related error in debug.log
await expect(this.page.locator('#wpr_debug_log_notice')).toBeHidden();
});
Expand Down
7 changes: 6 additions & 1 deletion src/support/steps/settings-export-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,19 @@ Given('I updated to latest version', async function (this: ICustomWorld) {
*/
When('I import data', async function (this: ICustomWorld) {
await this.utils.importSettings('./plugin/exported_settings/wp-rocket-settings-test-2023-00-01-64e7ada0d3b70.json');
await this.page.waitForLoadState('load', { timeout: 100000 });
await expect(this.page.getByText('Settings imported and saved.')).toBeVisible();
});

/**
* Executes the step to export data.
*/

When('I export data {string}', async function (this: ICustomWorld, fileNo: string) {
if(! await this.page.url().includes('page=wprocket#tools'))
{
await this.utils.visitPage('wp-admin/options-general.php?page=wprocket#tools');

}
await this.page.locator('#wpr-nav-tools').click();
// Export settings.
const downloadPromise = this.page.waitForEvent('download');
Expand Down
91 changes: 45 additions & 46 deletions utils/page-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,15 @@ export class PageUtils {
* Performs upload new plugin action.
*
* @param file File to be uploaded.
*
* @return {Promise<void>}
*/
public uploadNewPlugin = async (file: string): Promise<void> => {
await this.page.goto(WP_BASE_URL + '/wp-admin/plugin-install.php');
await this.page.waitForSelector('.upload-view-toggle');
await this.page.locator('.upload-view-toggle').click();
await this.page.locator('#pluginzip').setInputFiles(file);
await this.page.waitForSelector('#install-plugin-submit');
await this.page.locator('#install-plugin-submit').click({ timeout: 120000 });
await this.page.locator('#install-plugin-submit').click();
}

/**
Expand Down Expand Up @@ -297,9 +297,9 @@ export class PageUtils {
if(! await this.page.locator('#user_login').isVisible()) {
return ;
}
await this.page.waitForTimeout(200);

await this.wpAdminLogin();
await this.page.waitForLoadState('load', { timeout: 30000 });

}

/**
Expand All @@ -317,53 +317,56 @@ export class PageUtils {
await this.sections.set("cache").visit();
await this.sections.massToggle();
await this.saveSettings();

await this.page.waitForLoadState('load', { timeout: 30000 });
await expect(this.page.getByText('Settings saved.')).toBeVisible();
await this.page.locator('#setting-error-settings_updated > button').click();

}

if(await this.sections.doesSectionExist('fileOptimization')) {
// Disable all settings for file optimization section.
await this.sections.set("fileOptimization").visit();
await this.sections.massToggle();
await this.saveSettings();

await this.page.waitForLoadState('load', { timeout: 30000 });
await expect(this.page.getByText('Settings saved.')).toBeVisible();
await this.page.locator('#setting-error-settings_updated > button').click();

}

if(await this.sections.doesSectionExist('media')) {
// Disable all settings for Media section.
await this.sections.set("media").visit();
await this.sections.massToggle();
await this.saveSettings();

await this.page.waitForLoadState('load', { timeout: 30000 });
await expect(this.page.getByText('Settings saved.')).toBeVisible();
await this.page.locator('#setting-error-settings_updated > button').click();

}

if(await this.sections.doesSectionExist('preload')) {
// Disable all settings for Preload section.
await this.sections.set("preload").visit();
await this.sections.massToggle();
await this.saveSettings();

await this.page.waitForLoadState('load', { timeout: 30000 });
await expect(this.page.getByText('Settings saved.')).toBeVisible();
await this.page.locator('#setting-error-settings_updated > button').click();
}

if(await this.sections.doesSectionExist('advancedRules')) {
// Advanced rules section.
await this.sections.set("advancedRules").visit();
await this.sections.massFill("");
await this.saveSettings();

await this.page.waitForLoadState('load', { timeout: 30000 });
await expect(this.page.getByText('Settings saved.')).toBeVisible();
await this.page.locator('#setting-error-settings_updated > button').click();
}

if(await this.sections.doesSectionExist('database')) {
// Disable all settings for Database.
await this.sections.set("database").visit();
await this.sections.massToggle();
await this.page.getByRole('button', { name: 'Save Changes and Optimize' }).click();

await this.page.waitForLoadState('load', { timeout: 30000 });
await expect(this.page.getByText('Settings saved.')).toBeVisible();
await this.page.locator('#setting-error-settings_updated > button').click();
}

if(await this.sections.doesSectionExist('cdn')) {
Expand All @@ -372,24 +375,27 @@ export class PageUtils {
await this.sections.massToggle();
await this.sections.fill("cnames", "");
await this.saveSettings();
await expect(this.page.getByText('Settings saved.')).toBeVisible();
await this.page.locator('#setting-error-settings_updated > button').click();

}

await this.page.waitForLoadState('load', { timeout: 30000 });
if(await this.sections.doesSectionExist('addons')) {
// Disable all settings for Addons.
await this.sections.set("addons").visit();
await this.sections.massToggle();
}

if(await this.sections.doesSectionExist('heartbeat')) {
// Disable all settings for Heartbeat.
await this.sections.set("heartbeat").visit();
await this.sections.massToggle();
await this.saveSettings();

await this.page.waitForLoadState('load', { timeout: 30000 });
await expect(this.page.getByText('Settings saved.')).toBeVisible();

}

if(await this.sections.doesSectionExist('addons')) {
// Disable all settings for Addons.
await this.sections.set("addons").visit();
await this.sections.massToggle();
}

}

/**
Expand All @@ -415,44 +421,38 @@ export class PageUtils {
public enableAllOptions = async (): Promise<void> => {
await this.gotoWpr();

await this.page.waitForLoadState('load', { timeout: 30000 });

this.sections.optionState = true;

if (await this.sections.doesSectionExist('cache')) {
// Enable all settings for cache section.
await this.sections.set("cache").visit();
await this.sections.massToggle();
await this.saveSettings();

await this.page.waitForLoadState('load', { timeout: 30000 });
await expect(this.page.getByText('Settings saved.')).toBeVisible();
}

if(await this.sections.doesSectionExist('fileOptimization')) {
// Enable all settings for file optimization section.
await this.sections.set("fileOptimization").visit();
await this.sections.massToggle();
await this.saveSettings();

await this.page.waitForLoadState('load', { timeout: 30000 });
await expect(this.page.getByText('Settings saved.')).toBeVisible();
}

if (await this.sections.doesSectionExist('media')) {
// Enable all settings for Media section.
await this.sections.set("media").visit();
await this.sections.massToggle();
await this.saveSettings();

await this.page.waitForLoadState('load', { timeout: 30000 });
await expect(this.page.getByText('Settings saved.')).toBeVisible();
}

if (await this.sections.doesSectionExist('preload')) {
// Enable all settings for Preload section.
await this.sections.set("preload").visit();
await this.sections.massToggle();
await this.saveSettings();

await this.page.waitForLoadState('load', { timeout: 30000 });
await expect(this.page.getByText('Settings saved.')).toBeVisible();
}

if(await this.sections.doesSectionExist('advancedRules')) {
Expand All @@ -461,17 +461,15 @@ export class PageUtils {
const values: Array<string> = ['/test\n/.*\n/test2', 'woocommerce_items_in_cart', 'Mobile(.*)Safari(.*)', '/hello-world/', 'country'];
await this.sections.massFill(values);
await this.saveSettings();

await this.page.waitForLoadState('load', { timeout: 30000 });
await expect(this.page.getByText('Settings saved.')).toBeVisible();
}

if(await this.sections.doesSectionExist('database')) {
// Enable all settings for Database.
await this.sections.set("database").visit();
await this.sections.massToggle();
await this.page.getByRole('button', { name: 'Save Changes and Optimize' }).click();

await this.page.waitForLoadState('load', { timeout: 30000 });
await expect(this.page.getByText('Database optimization process is complete')).toBeVisible();
}

if(await this.sections.doesSectionExist('cdn')) {
Expand All @@ -480,24 +478,25 @@ export class PageUtils {
await this.sections.toggle("cdn");
await this.sections.fill("cnames", "test.example.com");
await this.saveSettings();
await expect(this.page.getByText('Settings saved.')).toBeVisible();
await this.page.locator('#setting-error-settings_updated > button').click();
}

await this.page.waitForLoadState('load', { timeout: 30000 });
if(await this.sections.doesSectionExist('addons')) {
// Enable all settings for Addons.
await this.sections.set("addons").visit();
await this.sections.massToggle();
}

if(await this.sections.doesSectionExist('heartbeat')) {
// Enable all settings for Heartbeat.
await this.sections.set("heartbeat").visit();
await this.sections.toggle("controlHeartbeat");
await this.saveSettings();

await this.page.waitForLoadState('load', { timeout: 30000 });
await expect(this.page.getByText('Settings saved.')).toBeVisible();
}

if(await this.sections.doesSectionExist('addons')) {
// Enable all settings for Addons.
await this.sections.set("addons").visit();
await this.sections.massToggle();
}

}

/**
Expand Down