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

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

Open
Mai-Saad opened this issue Nov 25, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Mai-Saad
Copy link
Contributor

Mai-Saad commented Nov 25, 2024

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

public wpAdminLogin = async (): Promise<void> => {
, 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');
}

@Mai-Saad Mai-Saad added the bug Something isn't working label Nov 25, 2024
@jeawhanlee
Copy link
Contributor

LGTM

@jeawhanlee jeawhanlee assigned jeawhanlee and unassigned jeawhanlee Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants