wp-media / wp-rocket-e2e

Playwright E2E testing repo
GNU General Public License v3.0
0 stars 0 forks source link

CPCSS notice has scenario that won't work correctly now due to the login structure #177

Open Mai-Saad opened 5 days ago

Mai-Saad commented 5 days ago

Scenario:

  Scenario: Shouldnot display the CPCSS banner to admin 2 if it was dismissed by admin 1
    Given I have an unexpired account
    And turn on 'CPCSS'
    Then I must see the banner 'We highly recommend the updated Remove Unused CSS for a better CSS optimization. Load CSS Asynchronously is always available as a back-up.'
    When click on 'Turn on Remove Unused CSS'
    Then I must see the banner 'The Remove Unused CSS service is processing your pages'
    When I connect as 'admin2'
    And I go '/wp-admin/options-general.php?page=wprocket#file_optimization'
    Then I must not see the banner 'We highly recommend the updated Remove Unused CSS for a better CSS optimization. Load CSS Asynchronously is always available as a back-up.'

Currently, at connect as admin2 , we are using the default credentials in config file

Suggested solution 1- In config file we define admin2 username and password 2- In https://github.com/wp-media/wp-rocket-e2e/blob/develop/utils/page-utils.ts#L336 we rewrite the function to accept user as argument and still can take nothing , for example

    /**
 * Performs Wordpress login action.
 *
 * @param user - Optional username for login. If not provided, a default user will be used.
 * @return  {Promise<void>}
 */
public auth = async (user: string | null = null): Promise<void> => {
    if (!this.page.url().includes('wp-login.php')) {
        await this.visitPage('wp-admin');
    }

    if (!await this.page.locator('#user_login').isVisible()) {
        return;
    }

    // Check if the user argument is provided, and login accordingly
    if (user !== null) {
        await this.wpAdminLogin(user);  // Assuming wpAdminLogin can accept a user argument
    } else {
        // If no user is provided, log in as a default user
        await this.wpAdminLogin();  // Default login (possibly using a predefined admin)
    }
}

3- In https://github.com/wp-media/wp-rocket-e2e/blob/e43c0ea4fab6c17ef930ba8f7f46f5ddf94a1078/utils/page-utils.ts#L78, we modify the function to take user i/p then we use from config either default user or user 2 as per passed argument for example:

    /**
 * Performs a Login action on WordPress.
 *
 * @param user - Optional user object or username. If not provided, default credentials are used.
 * @return {Promise<void>}
 */
    public wpAdminLogin = async (user: string | null = null): Promise<void> => {
        var username, password;
        if (user === "admin2"){
            username = WP_USERNAME2;
            password = WP_PASSWORD2;
            }
        else{
            username= WP_USERNAME;
            password= WP_PASSWORD;
        }
    // Fill username & password.
    await this.page.click('#user_login');
    await this.page.fill('#user_login', username);
    await this.page.click('#user_pass');
    await this.page.fill('#user_pass', password);

    // Click login.
    await this.page.click('#wp-submit');
}
jeawhanlee commented 4 days ago

LGTM