Skip to content

Commit

Permalink
Fixed cpcss admin2 issue :closes: #171
Browse files Browse the repository at this point in the history
  • Loading branch information
Khadreal committed Dec 31, 2024
1 parent 313d044 commit aa0c8c8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/support/steps/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ When('I go {string}', async function (this: ICustomWorld, url: string) {
*/
When('I connect as {string}', async function (this: ICustomWorld, user: string) {
await this.utils.wpAdminLogout();
await this.utils.auth();
await this.utils.auth('admin2');
});

/**
Expand Down
28 changes: 21 additions & 7 deletions utils/page-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {expect} from "@playwright/test";
import { ICustomWorld } from '../src/common/custom-world';
import fs from "fs/promises";

import {WP_BASE_URL, WP_PASSWORD, WP_USERNAME} from '../config/wp.config';
import {WP_BASE_URL, WP_PASSWORD, WP_PASSWORD2, WP_USERNAME, WP_USERNAME2} from '../config/wp.config';
import { uninstallPlugin, updatePermalinkStructure, deactivatePlugin, switchTheme } from "./commands";

/**
Expand Down Expand Up @@ -75,12 +75,21 @@ export class PageUtils {
*
* @return {Promise<void>}
*/
public wpAdminLogin = async (): Promise<void> => {
public wpAdminLogin = async (user: string | null = null): Promise<void> => {

let username= WP_USERNAME;
let password= WP_PASSWORD;

if(user === 'admin2') {
username = WP_USERNAME2
password = WP_PASSWORD2
}

// Fill username & password.
await this.page.click('#user_login');
await this.page.fill('#user_login', WP_USERNAME);
await this.page.fill('#user_login', username);
await this.page.click('#user_pass');
await this.page.fill('#user_pass', WP_PASSWORD);
await this.page.fill('#user_pass', password);

// Click login.
await this.page.click('#wp-submit');
Expand Down Expand Up @@ -331,9 +340,10 @@ export class PageUtils {
/**
* 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 (): Promise<void> => {
public auth = async (user: string| null = null): Promise<void> => {
if(! this.page.url().includes('wp-login.php')) {
await this.visitPage('wp-admin');
}
Expand All @@ -342,8 +352,12 @@ export class PageUtils {
return ;
}

await this.wpAdminLogin();

// Check if user is not null, login with the provider user.
if (user !== null) {
await this.wpAdminLogin(user);
} else {
await this.wpAdminLogin();
}
}

/**
Expand Down

0 comments on commit aa0c8c8

Please sign in to comment.