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

[Automation] WPUF-lite: e2e testing for Login, Setup, PostForms and RegistrationForms #1365

Open
wants to merge 118 commits into
base: develop
Choose a base branch
from

Conversation

Rat01047
Copy link

@Rat01047 Rat01047 commented Jul 6, 2023

Description:
This Automation Test suite covers basic test scenarios for Login, Setup, PostForms and RegistrationForms-with-shortcode

Test Suite:

Login authentication along with plugin status and also completes WPUF Setup process.
PostForms with addition of all fields and their validation
RegistrationForms creation with shortcode & frontend submission check

Summary by CodeRabbit

  • New Features

    • Introduced a comprehensive suite of end-to-end tests for various functionalities, including post forms, registration forms, and subscription management.
    • Added a GitHub Actions workflow for automating Playwright end-to-end tests.
    • Implemented new classes and methods for managing user sessions, logins, and form interactions.
  • Documentation

    • Added detailed README documentation for setting up and running automated tests using Playwright.
  • Bug Fixes

    • Ensured improvements in the execution of automated tests to enhance reliability and consistency.
  • Chores

    • Created and updated configuration files to streamline the test environment setup and management.

@Rat01047 Rat01047 added the needs: dev review This PR needs review by a developer label Jul 13, 2023
Copy link

coderabbitai bot commented Aug 8, 2024

Walkthrough

This update introduces a comprehensive set of end-to-end tests for a WordPress application using Playwright. Key enhancements include automated testing for login, post forms, registration forms, and subscription functionalities, streamlining the testing process. New configuration files and utility scripts support improved management of test data and environment setup, ensuring that the application remains functional and reliable after changes.

Changes

Files Summary
.github/workflows/playwright.yml New GitHub Actions workflow for running Playwright tests on specific branches and pull requests.
package.json, tests/e2e/package.json Added @types/node to devDependencies for type definitions and created a new package.json for end-to-end tests.
state.json New file to manage state information related to cookies and origins.
tests/e2e/.env-example New template for environment variables needed for testing setup.
tests/e2e/.gitignore New .gitignore file to exclude common artifacts and sensitive information.
tests/e2e/.wp-env.json Configuration for WordPress environment including PHP version and debugging options.
tests/e2e/README.md Documentation for setting up E2E tests using Playwright for the WPUF plugin.
tests/e2e/pages/*.ts (multiple files) New classes introduced for managing interactions with UI components for login, forms, and subscriptions.
tests/e2e/tests/*.spec.ts (multiple files) Comprehensive test suites for different functionalities including login, registration, post forms, and subscriptions.
tests/e2e/utils/testData.ts New file defining structured mock data for testing various entities and interactions.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant System
    participant Database

    User->>System: Starts E2E tests
    System->>Database: Initialize state
    System->>User: Begin login test
    User->>System: Submit login credentials
    System->>Database: Validate credentials
    Database-->>System: Return success/failure
    System-->>User: Display dashboard or error
    User->>System: Conduct post forms tests
    System->>Database: Create and validate forms
    Database-->>System: Return form status
    System->>User: Show form results
    User->>System: Finish tests
    System-->>User: Test summary report
Loading

🐰 Hopping through code, oh what a delight,
New tests added, everything feels right!
From login to posts, all neat and tidy,
Our WordPress checks are now super speedy.
With data and workflows, we’re ready to play,
Hooray for testing, hip-hip-hooray! 🥕✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 45

Outside diff range, codebase verification and nitpick comments (37)
tests/e2e/tests/resetWordpressSite.spec.ts (3)

8-8: Consider renaming the function for clarity.

The function name resetWordpressSite might be misleading as it does not directly reset the site but rather contains tests related to resetting. Consider renaming it to something like testResetWordpressSite for clarity.


11-11: Add a meaningful description to the test suite.

The test suite description 'TEST :-->' is not informative. Consider providing a more descriptive name that reflects the purpose of the tests, such as 'Reset Local WordPress Site Tests'.

- test.describe('TEST :-->', () => {
+ test.describe('Reset Local WordPress Site Tests', () => {

13-13: Ensure test names are descriptive.

The test name '0000:[Reset Local Site] Resetting Local Site' could be simplified and made more descriptive. Consider using a name like 'should reset the local WordPress site successfully'.

- test('0000:[Reset Local Site] Resetting Local Site', async ({ page }) => {
+ test('should reset the local WordPress site successfully', async ({ page }) => {
tests/e2e/pages/basicLogout.ts (1)

23-23: Use a logging library instead of console.log.

Consider using a logging library for better control over log levels and outputs, especially in a testing environment.

tests/e2e/pages/base.ts (1)

5-5: Consider renaming the class for clarity.

The class name base is too generic. Consider renaming it to something more descriptive, like BasePage, to better reflect its purpose.

- export class base {
+ export class BasePage {
tests/e2e/pages/subscriptionFrontEnd (1)

44-44: Reminder: Rework this page.

The TODO comment indicates that the entire page needs reworking. Ensure that the necessary updates are made to align with the current requirements.

tests/e2e/README.md (3)

9-9: Verify link fragments.

Ensure that the link fragments [Install Node.js](#install-node.js) and [How to run tests](#how-to-run-tests) are valid and correctly formatted.

Also applies to: 16-16

Tools
Markdownlint

9-9: null
Link fragments should be valid

(MD051, link-fragments)


40-40: Specify language for code blocks.

Add a language identifier to the fenced code blocks for better syntax highlighting and readability.

- ```
+ ```bash

Also applies to: 46-46

Tools
Markdownlint

40-40: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


40-40: Expected: indented; Actual: fenced
Code block style

(MD046, code-block-style)


54-54: Remove trailing punctuation in headings.

The heading "## Initial Setup:" should not have a trailing colon.

- ## Initial Setup:
+ ## Initial Setup
Tools
Markdownlint

54-54: Punctuation: ':'
Trailing punctuation in heading

(MD026, no-trailing-punctuation)

tests/e2e/tests/registrationFormsTestsLite.spec.ts (1)

18-28: Enhance documentation with consistent formatting.

The comments provide a good overview of the test scenarios. Consider using a consistent format for test scenario descriptions to improve readability and maintainability.

tests/e2e/tests/subscription.spec.ts (2)

14-27: Enhance documentation with consistent formatting.

The comments provide a good overview of the test scenarios. Consider using a consistent format for test scenario descriptions to improve readability and maintainability.


46-47: Initialize subscriptionPackName with meaningful value.

The subscriptionPackName is initialized as an empty string. Consider initializing it with a meaningful default value or directly using it after assignment.

.github/workflows/playwright.yml (2)

23-26: Remove or justify commented-out code.

The checkout step contains commented-out code. Ensure that it is necessary or remove it for clarity.


79-90: Clarify or remove "Remove Later" notes.

The workflow contains notes indicating certain steps should be removed later. Ensure that these steps are necessary or remove them for clarity.

tests/e2e/tests/loginAndSetupTests.spec.ts (2)

1-8: Consider removing unused imports.

The fs module is imported but only used once. Consider removing the import if it's not necessary elsewhere.


38-41: Improve test description clarity.

The test description could be more concise. Consider removing redundant phrases like "Here, Admin is" to improve readability.

- test('001:[Login] Here, Admin is logging into Admin-Dashboard', async ({ page }) => {
+ test('001:[Login] Admin logs into Admin-Dashboard', async ({ page }) => {
tests/e2e/pages/postFormsFrontend.ts (1)

36-66: Improve method documentation and error handling.

Consider adding comments to explain the purpose of each step in createPostFormFrontend. Additionally, implement error handling to manage potential failures during form submission.

tests/e2e/playwright.config.ts (1)

8-8: Consider enabling dotenv configuration.

The dotenv configuration is commented out. If environment variables are needed, ensure this line is enabled, or remove it if unnecessary.

tests/e2e/utils/testData.ts (5)

1-13: Enhance documentation and type safety.

Consider adding comments to explain the purpose of each data set and use TypeScript interfaces for better type safety.

// Example of adding comments and using interfaces
interface UrlConfig {
    baseUrl: string;
}

// Main Site URL configuration
let Urls: UrlConfig = {
    baseUrl: process.env.QA_BASE_URL ? process.env.QA_BASE_URL : 'http://localhost:8889',
};

20-42: Enhance documentation and type safety.

Consider adding comments to explain the purpose of each user credential and use TypeScript interfaces for better type safety.

// Example of adding comments and using interfaces
interface UserCredentials {
    adminUsername: string;
    adminPassword: string;
    userName: string;
    userEmail: string;
    userFirstName: string;
    userLastName: string;
    userPassword: string;
}

// Admin and new user credentials
let Users: UserCredentials = {
    adminUsername: process.env.QA_ADMIN_USERNAME ? process.env.QA_ADMIN_USERNAME : 'admin',
    adminPassword: process.env.QA_ADMIN_PASSWORD ? process.env.QA_ADMIN_PASSWORD : 'password',
    // New User Credentials...
};

49-71: Enhance documentation and type safety.

Consider adding comments to explain the purpose of each post form field and use TypeScript interfaces for better type safety.

// Example of adding comments and using interfaces
interface PostFormConfig {
    pfPostName1: string;
    pfPostName2: string;
    pfPostName3: string;
    pfPostName4: string;
    pfTitle: string;
    pfPostDescription: string;
    pfExcerpt: string;
    pfTags: string;
}

// Post form configuration
let PostForm: PostFormConfig = {
    pfPostName1: faker.lorem.sentence(2),
    // Other fields...
};

78-105: Enhance documentation and type safety.

Consider adding comments to explain the purpose of each registration form field and use TypeScript interfaces for better type safety.

// Example of adding comments and using interfaces
interface RegistrationFormConfig {
    rfPostName1: string;
    rfPostName2: string;
    rfPostName3: string;
    rfPostName4: string;
    rfFirstName: string;
    rfLastName: string;
    rfUsername: string;
    rfEmail: string;
    rfPassword: string;
}

// Registration form configuration
let RegistrationForm: RegistrationFormConfig = {
    rfPostName1: faker.lorem.sentence(2),
    // Other fields...
};

112-132: Enhance documentation and type safety.

Consider adding comments to explain the purpose of each subscription pack field and use TypeScript interfaces for better type safety.

// Example of adding comments and using interfaces
interface SubscriptionPackConfig {
    subscriptionPackName: string;
    subscriptionPackDescription: string;
    SubscriptionPackPrice: string;
    SubscriptionPackExpiration: number;
    subscriptionFeaturedCount: number;
}

// Subscription pack configuration
let SubscriptionPack: SubscriptionPackConfig = {
    subscriptionPackName: faker.commerce.productName(),
    // Other fields...
};
tests/e2e/utils/testData-old.ts (3)

1-2: Use ES6 import syntax consistently.

Consider using ES6 import syntax for dotenv to maintain consistency with the rest of the imports.

- require('dotenv').config();
+ import dotenv from 'dotenv';
+ dotenv.config();

45-52: Ensure consistent naming conventions.

The property SubscriptionPackPrice uses PascalCase, while others use camelCase. Consider using camelCase for consistency.

- SubscriptionPackPrice: string;
+ subscriptionPackPrice: string;

128-169: Avoid hardcoding default values.

Consider using environment variables or configuration files to manage default values like URLs and credentials for better flexibility and security.

tests/e2e/pages/registrationForms.ts (1)

24-44: Improve readability and error handling.

Consider using more descriptive variable names and adding error handling to improve the robustness of the test. For example, handle cases where the page might not load correctly or elements might not be found.

- const validateWPUFProActivate = await this.page.isVisible(selectors.registrationForms.navigatePage_RF.checkAddButton_RF);
+ const isProFeatureButtonVisible = await this.page.isVisible(selectors.registrationForms.navigatePage_RF.checkAddButton_RF);

if (!isProFeatureButtonVisible) {
    try {
        const proFeaturesText = await this.page.innerText(selectors.registrationForms.validateRegistrationFormsProFeatureLite.checkProFeaturesText);
        await expect(proFeaturesText).toContain("Unlock PRO Features");

        const upgradeToProOption = await this.page.locator(selectors.registrationForms.validateRegistrationFormsProFeatureLite.checkUpgradeToProOption);
        expect(upgradeToProOption).toBeTruthy();
    } catch (error) {
        console.error("Error validating Pro features:", error);
    }
}
tests/e2e/tests/postFormsTests.spec.ts (1)

34-54: Implement a beforeAll setup for login.

The TODO comment suggests creating a beforeAll setup for login to avoid repetitive login steps in each test. This will improve test efficiency and readability.

// Consider adding a beforeAll hook for login
test.beforeAll(async ({ page }) => {
    const BasicLogin = new basicLoginPage(page);
    await BasicLogin.basicLoginAndPluginVisit(Users.adminUsername, Users.adminPassword);
});
tests/e2e/pages/settingsSetup.ts (6)

48-56: Add logging for plugin activation status.

Consider adding logging to confirm the activation status of the plugin, which can be helpful for debugging.

console.log("Checking WPUF-Lite plugin status...");
await this.activateWPUFLite();
console.log("WPUF-Lite plugin status check complete.");

60-68: Add logging for plugin activation status.

Consider adding logging to confirm the activation status of the Pro plugin, which can be helpful for debugging.

console.log("Checking WPUF-Pro plugin status...");
await this.activateWPUFPro();
console.log("WPUF-Pro plugin status check complete.");

79-95: Add descriptive logging.

Consider adding descriptive logging to provide more context about the actions being performed and their outcomes.

console.log("Navigating to WPUF plugin page...");
await this.page.goto(Urls.baseUrl + '/wp-admin/', { waitUntil: 'networkidle' });
console.log("Checking for Post Form menu option...");
if (availableText) {
    console.log("Post Form menu option is available.");
    const checkText = await this.page.innerText(selectors.settingsSetup.pluginVisit.wpufPostFormCheckAddButton);
    await expect(checkText).toContain("Add Form");
}

99-126: Enhance logging for activation steps.

Consider enhancing logging to track each step of the plugin activation process for better traceability.

console.log("Navigating to plugins page for WPUF-Lite activation...");
await this.page.goto(pluginsPage, { waitUntil: 'networkidle' });
console.log("Checking activation status...");
if (activateWPUFLite) {
    console.log("Activating WPUF-Lite plugin...");
    await this.page.click(selectors.settingsSetup.pluginStatusCheck.clickWPUFPluginLite);
    await this.page.reload();
    await this.page.goBack();
    await this.page.goto(Urls.baseUrl + '/wp-admin/');
    await this.page.isVisible(selectors.login.basicNavigation.clickWPUFSidebar);
    await this.page.click(selectors.login.basicNavigation.clickWPUFSidebar);
    console.log("WPUF-Lite plugin activated.");
} else {
    console.log("WPUF-Lite plugin is already activated.");
}

129-151: Enhance logging for activation steps.

Consider enhancing logging to track each step of the Pro plugin activation process for better traceability.

console.log("Navigating to plugins page for WPUF-Pro activation...");
await this.page.goto(pluginsPage, { waitUntil: 'networkidle' });
console.log("Checking activation status...");
if (activateWPUFPro) {
    console.log("Activating WPUF-Pro plugin...");
    await this.page.click(selectors.settingsSetup.pluginStatusCheck.clickWPUFPluginPro);
    await this.page.isVisible(selectors.login.basicNavigation.clickWPUFSidebar);
    await this.page.click(selectors.login.basicNavigation.clickWPUFSidebar);
    console.log("WPUF-Pro plugin activated.");
} else {
    console.log("WPUF-Pro plugin is already activated.");
}

163-188: Add logging to confirm actions.

Consider adding logging to confirm each action taken in the method, which can help with debugging and traceability.

console.log("Navigating to WPUF post form page...");
await this.page.goto(wpufpostformpage, { waitUntil: 'networkidle' });
console.log("Changing settings to default login page...");
await this.page.click(selectors.settingsSetup.wpufSettingsPage.settingsTab);
await this.page.reload();
expect(await this.page.isVisible(selectors.settingsSetup.wpufSettingsPage.settingsTabProfile1)).toBeTruthy();
console.log("Login/Registration tab is visible.");
await this.page.waitForSelector(selectors.settingsSetup.wpufSettingsPage.settingsTabProfile2);
await this.page.click(selectors.settingsSetup.wpufSettingsPage.settingsTabProfile2);
console.log("Setting login page to default...");
await this.page.selectOption(selectors.settingsSetup.wpufSettingsPage.settingsTabProfileLoginPage, { label: '— Select —' });
await this.page.click(selectors.settingsSetup.wpufSettingsPage.settingsTabProfileSave);
console.log("Login page settings updated.");
tests/e2e/pages/selectors.ts (3)

9-30: Remove commented-out code for clarity.

The commented-out line for clickWPUFSidebar should be removed if it is no longer needed to improve code readability.

// Remove this line if not needed
// clickWPUFSidebar: '//div[text()="User Frontend"]/.',

59-116: Address or track TODO comments.

There are TODO comments in this section. Ensure these are addressed or tracked in an issue tracker.

// TODO: Ensure all TODO comments are addressed or tracked

213-278: Address or track TODO comments.

There are TODO comments in this section. Ensure these are addressed or tracked in an issue tracker.

// TODO: Ensure all TODO comments are addressed or tracked
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 09d0b00 and 1cd1439.

Files ignored due to path filters (3)
  • package-lock.json is excluded by !**/package-lock.json
  • tests/e2e/package-lock.json is excluded by !**/package-lock.json
  • tests/e2e/uploadeditems/sample_image.jpeg is excluded by !**/*.jpeg
Files selected for processing (30)
  • .github/workflows/playwright.yml (1 hunks)
  • package.json (1 hunks)
  • state.json (1 hunks)
  • tests/e2e/.env-example (1 hunks)
  • tests/e2e/.gitignore (1 hunks)
  • tests/e2e/.wp-env.json (1 hunks)
  • tests/e2e/README.md (1 hunks)
  • tests/e2e/package.json (1 hunks)
  • tests/e2e/pages/base.ts (1 hunks)
  • tests/e2e/pages/basicLogin.ts (1 hunks)
  • tests/e2e/pages/basicLogout.ts (1 hunks)
  • tests/e2e/pages/fieldOptionsCommon.ts (1 hunks)
  • tests/e2e/pages/postForms.ts (1 hunks)
  • tests/e2e/pages/postFormsFrontend.ts (1 hunks)
  • tests/e2e/pages/registrationForms.ts (1 hunks)
  • tests/e2e/pages/registrationFormsFrontEnd.ts (1 hunks)
  • tests/e2e/pages/selectors.ts (1 hunks)
  • tests/e2e/pages/settingsSetup.ts (1 hunks)
  • tests/e2e/pages/subscription.ts (1 hunks)
  • tests/e2e/pages/subscriptionFrontEnd (1 hunks)
  • tests/e2e/playwright.config.ts (1 hunks)
  • tests/e2e/state.json (1 hunks)
  • tests/e2e/tests/e2eMain.spec.ts (1 hunks)
  • tests/e2e/tests/loginAndSetupTests.spec.ts (1 hunks)
  • tests/e2e/tests/postFormsTests.spec.ts (1 hunks)
  • tests/e2e/tests/registrationFormsTestsLite.spec.ts (1 hunks)
  • tests/e2e/tests/resetWordpressSite.spec.ts (1 hunks)
  • tests/e2e/tests/subscription.spec.ts (1 hunks)
  • tests/e2e/utils/testData-old.ts (1 hunks)
  • tests/e2e/utils/testData.ts (1 hunks)
Files skipped from review due to trivial changes (7)
  • package.json
  • state.json
  • tests/e2e/.env-example
  • tests/e2e/.gitignore
  • tests/e2e/.wp-env.json
  • tests/e2e/package.json
  • tests/e2e/state.json
Additional context used
Markdownlint
tests/e2e/README.md

54-54: Punctuation: ':'
Trailing punctuation in heading

(MD026, no-trailing-punctuation)


40-40: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


46-46: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


40-40: Expected: indented; Actual: fenced
Code block style

(MD046, code-block-style)


46-46: Expected: indented; Actual: fenced
Code block style

(MD046, code-block-style)


9-9: null
Link fragments should be valid

(MD051, link-fragments)


16-16: null
Link fragments should be valid

(MD051, link-fragments)

Biome
tests/e2e/pages/subscription.ts

[error] 13-15: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

Additional comments not posted (20)
tests/e2e/tests/registrationFormsTestsLite.spec.ts (4)

31-38: LGTM!

The test for checking the registration forms' pro feature page is well-implemented.


55-62: Verify the purpose of writing to state.json.

The test writes an empty state.json file. Ensure that this step is necessary and correctly implemented.


65-74: Verify the purpose of writing to state.json.

The test writes an empty state.json file. Ensure that this step is necessary and correctly implemented.


41-52: Verify the purpose of writing to state.json.

The test writes an empty state.json file. Ensure that this step is necessary and correctly implemented.

tests/e2e/tests/subscription.spec.ts (3)

28-36: LGTM!

The test for creating a subscription plan is well-implemented and logs the created subscription pack name.


48-56: LGTM!

The test for creating a subscription plan is well-implemented and logs the created subscription pack name.


58-63: LGTM!

The test for updating a subscription plan for featured posts is well-implemented.

.github/workflows/playwright.yml (7)

18-21: LGTM!

The PHP setup step is correctly implemented for version 7.3.


28-30: LGTM!

The Node.js setup step is correctly implemented for version 14.x.


34-38: LGTM!

The Composer install and build step for WPUF-lite is correctly implemented.


40-44: LGTM!

The npm install and build step for WPUF-lite is correctly implemented.


47-50: LGTM!

The step for installing dependencies for the e2e tests is correctly implemented.


52-55: LGTM!

The step for installing Playwright browsers is correctly implemented.


58-115: LGTM!

The steps for setting up WordPress, running Playwright tests, publishing test reports, and archiving artifacts are correctly implemented.

tests/e2e/tests/loginAndSetupTests.spec.ts (1)

16-16: Ensure function is invoked.

The loginAndSetupTests function is defined but not invoked. Ensure that this is intended, or consider invoking it to execute the tests.

tests/e2e/pages/postFormsFrontend.ts (1)

14-16: Clarify data usage for post creation.

The postExcerpt and postTags are being set using RegistrationForm data. Ensure this is intentional, as it might lead to confusion if the data sources are not aligned with their intended use.

tests/e2e/playwright.config.ts (2)

29-29: Review retry settings for CI.

The retry setting is set to 0 for CI. Consider whether retries are necessary to account for potential flakiness in tests.


72-72: Ensure storage state file is managed properly.

The storageState is set to state.json. Ensure this file is correctly managed and cleaned up as needed to prevent stale state issues.

tests/e2e/pages/selectors.ts (2)

491-633: LGTM!

The registrationForms section is well-structured and complete.


645-651: LGTM!

The resetWordpreseSite section is straightforward and complete.

//Logout
await BasicLogout.logOut();

fs.writeFile('state.json', '{"cookies":[],"origins": []}', function () { });
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid hardcoding file paths.

The file path in fs.writeFile is hardcoded. Consider using a configuration or environment variable to specify paths, improving flexibility and maintainability.

Comment on lines +68 to +119
//Function
const generateFakerData = () => {
//Post Form Titles
const pfPostName1: string = faker.lorem.sentence(2);
const pfPostName2: string = faker.lorem.sentence(2);
const pfPostName3: string = faker.lorem.sentence(2);
const pfPostName4: string = faker.lorem.sentence(2);
//Post Form Data
const pfTitle: string = faker.lorem.words(2);
const pfPostDescription: string = faker.lorem.sentence(4);
const pfExcerpt: string = faker.lorem.word(3);
const pfTags: string = faker.lorem.word();

//-----------------------------------------------------------------//
//Registration Form Titles
const rfPostName1: string = faker.lorem.sentence(2);
const rfPostName2: string = faker.lorem.sentence(2);
const rfPostName3: string = faker.lorem.sentence(2);
const rfPostName4: string = faker.lorem.sentence(2);
//Registration Form Data
//Generate random user details
const rfFirstName: string = faker.name.firstName();
const rfLastName: string = faker.name.lastName();
const rfUsername: string = faker.internet.userName(rfFirstName, rfLastName);
const rfEmail: string = faker.internet.email(rfFirstName, rfLastName);
const rfPassword: string = faker.internet.password();

return {
//Post Form Titles
pfPostName1,
pfPostName2,
pfPostName3,
pfPostName4,
//Post Form Data
pfTitle,
pfPostDescription,
pfExcerpt,
pfTags,

//Reg Form Titles
rfPostName1,
rfPostName2,
rfPostName3,
rfPostName4,
//Registration Form Data
rfFirstName,
rfLastName,
rfUsername,
rfEmail,
rfPassword,
};
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider parameterizing faker data generation.

The generateFakerData function could be parameterized to allow more flexible data generation, which could be useful for testing different scenarios.

const generateFakerData = (numWords: number = 2, numSentences: number = 2) => {
    const pfPostName1: string = faker.lorem.sentence(numSentences);
    // ... other faker data generation
};

Comment on lines +15 to +17
async buy_SubscriptionPack_Basic() {

}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement the subscription methods.

The methods buy_SubscriptionPack_Basic, buy_SubscriptionPack_PostPageRestriction, and createMultipleposts are placeholders without any implementation. Consider adding the necessary logic to fulfill their intended functionalities.

Would you like assistance in drafting the implementation for these methods or opening a GitHub issue to track this task?

Also applies to: 21-23, 40-42

import postFormsTests from './postFormsTests.spec';
import registrationFormsTestsLite from './registrationFormsTestsLite.spec';
import subscriptionsTests from './subscription.spec';
import * as fs from "fs"; //Clear Cookie
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using Playwright's context management for cookie handling.

Using fs.writeFile to clear cookies is unconventional. Playwright provides context management capabilities that can handle cookies more effectively. Consider using browserContext.clearCookies() instead.

- fs.writeFile('state.json', '{"cookies":[],"origins": []}', function () { });
+ await context.clearCookies();

Also applies to: 15-15, 29-29, 34-34, 39-39

//Second tab
await this.page.isVisible('//a[@href="#wpuf-post-restriction"]');
//Third tab
await this.page.isVisible('//a[@href="#taxonomy-restriction""]');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix syntax error in selector.

There is an extra double quote in the selector string.

- await this.page.isVisible('//a[@href="#taxonomy-restriction""]');
+ await this.page.isVisible('//a[@href="#taxonomy-restriction"]');
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
await this.page.isVisible('//a[@href="#taxonomy-restriction""]');
await this.page.isVisible('//a[@href="#taxonomy-restriction"]');

Comment on lines +161 to +178
test('0016:[Post-Forms-FE] Here, Admin is creating a Preset Post Form - with Guest Enabled', async ({ page }) => {
const PostForms = new postForms(page);
const FieldOptionsCommon = new fieldOptionsCommon(page);

//For Front-End
//Create Post Form
const postFormPresetFrontendTitle = 'FE PostForm';
//Post Preset Form
await PostForms.createPresetPostFormWithGuestEnabled(postFormPresetFrontendTitle);
//Validate
await FieldOptionsCommon.validatePostFields_PF();
await FieldOptionsCommon.validateTaxonomiesPreset_PF();

//Save
await FieldOptionsCommon.saveForm_Common(postFormPresetFrontendTitle);
//Validate
await FieldOptionsCommon.validatePostFormCreated(postFormPresetFrontendTitle);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reuse shared setup and validation logic.

This test can be improved by reusing shared setup and validation logic to reduce redundancy.

// Example of reusing shared logic
await setupPostForm(page, postFormPresetFrontendTitle);
await validatePostForm(page, postFormPresetFrontendTitle);

Committable suggestion was skipped due to low confidence.

Comment on lines +57 to +73
test('0011:[Post-Forms] Admin is creating Blank Form with > Taxonomies', async ({ page }) => {
const PostForms = new postForms(page);
const FieldOptionsCommon = new fieldOptionsCommon(page);

//Post Blank Form
await PostForms.createBlankFormPostForm(PostForm.pfPostName2);
//PostFields
await FieldOptionsCommon.addPostFields_PF();
//Taxonomies + Validate
await FieldOptionsCommon.addTaxonomies_PF();
await FieldOptionsCommon.validateTaxonomies_PF();

//Save
await FieldOptionsCommon.saveForm_Common(PostForm.pfPostName2);
//Validate
await FieldOptionsCommon.validatePostFormCreated(PostForm.pfPostName2);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reuse common setup steps.

Consider reusing common setup steps across tests to reduce redundancy and improve maintainability. Extracting shared logic into helper functions or using beforeEach can help.

// Example of reusing setup steps
test.beforeEach(async ({ page }) => {
    const PostForms = new postForms(page);
    const FieldOptionsCommon = new fieldOptionsCommon(page);
    await PostForms.createBlankFormPostForm(PostForm.pfPostName);
    await FieldOptionsCommon.addPostFields_PF();
});

Committable suggestion was skipped due to low confidence.

Comment on lines +96 to +114
test('0013:[Post-Forms] Here, Admin is creating Blank Form with > Others', async ({ page }) => {
const PostForms = new postForms(page);
const FieldOptionsCommon = new fieldOptionsCommon(page);


//Post Blank Form
await PostForms.createBlankFormPostForm(PostForm.pfPostName4);
//PostFields
await FieldOptionsCommon.addPostFields_PF();
//Others + Validate
await FieldOptionsCommon.addOthers_Common();
await FieldOptionsCommon.validateOthers_Common();
await FieldOptionsCommon.setMultiStepSettings_Common();

//Save
await FieldOptionsCommon.saveForm_Common(PostForm.pfPostName4);
//Validate
await FieldOptionsCommon.validatePostFormCreated(PostForm.pfPostName4);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement shared setup and teardown logic.

Consider implementing shared setup and teardown logic to improve test maintainability and reduce redundancy.

// Example of shared setup and teardown
test.beforeEach(async ({ page }) => {
    await setupPostForm(page, PostForm.pfPostName);
});

test.afterEach(async ({ page }) => {
    // Optional: Add teardown logic if needed
});

Committable suggestion was skipped due to low confidence.

Comment on lines +289 to +322
async createNewUserAdmin(userName, email, firstName, lastName, password) {
const pluginsPage = Urls.baseUrl + '/wp-admin/';
await Promise.all([
this.page.goto(pluginsPage, { waitUntil: 'networkidle' }),
]);

//Go to Admin-Users
await this.page.click(selectors.settingsSetup.createNewUser.clickUserMenuAdmin);
//Add New User
await this.page.click(selectors.settingsSetup.createNewUser.clickAddNewUserAdmin);
await this.page.reload();
await this.page.waitForLoadState('domcontentloaded');

//New User creation flow
//Enter Username
await this.page.fill(selectors.settingsSetup.createNewUser.newUserName, userName);
//Enter Email
await this.page.fill(selectors.settingsSetup.createNewUser.newUserEmail, email);
//Enter First Name
await this.page.fill(selectors.settingsSetup.createNewUser.newUserFirstName, firstName);
//Enter Last Name
await this.page.fill(selectors.settingsSetup.createNewUser.newUserLastName, lastName);
//Enter Password
await this.page.fill(selectors.settingsSetup.createNewUser.newUserPassword, password);
//Allow weak Password
await this.page.check(selectors.settingsSetup.createNewUser.newUserWeakPasswordAllow);
//Select Role
await this.page.waitForLoadState('domcontentloaded');
await expect(await this.page.isVisible(selectors.settingsSetup.createNewUser.newUserSelectRole)).toBeTruthy();
await this.page.selectOption(selectors.settingsSetup.createNewUser.newUserSelectRole, { label: 'Subscriber' });

//Create User
await this.page.click(selectors.settingsSetup.createNewUser.newUserSubmit);
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add logging and error handling for user creation.

Consider adding logging to confirm each action taken during user creation and error handling for form submissions to improve reliability.

console.log("Navigating to admin users page...");
await this.page.goto(pluginsPage, { waitUntil: 'networkidle' });
console.log("Adding a new user...");
await this.page.click(selectors.settingsSetup.createNewUser.clickUserMenuAdmin);
await this.page.click(selectors.settingsSetup.createNewUser.clickAddNewUserAdmin);
await this.page.reload();
await this.page.waitForLoadState('domcontentloaded');

try {
    console.log("Filling out new user form...");
    await this.page.fill(selectors.settingsSetup.createNewUser.newUserName, userName);
    await this.page.fill(selectors.settingsSetup.createNewUser.newUserEmail, email);
    await this.page.fill(selectors.settingsSetup.createNewUser.newUserFirstName, firstName);
    await this.page.fill(selectors.settingsSetup.createNewUser.newUserLastName, lastName);
    await this.page.fill(selectors.settingsSetup.createNewUser.newUserPassword, password);
    await this.page.check(selectors.settingsSetup.createNewUser.newUserWeakPasswordAllow);
    await this.page.selectOption(selectors.settingsSetup.createNewUser.newUserSelectRole, { label: 'Subscriber' });
    await this.page.click(selectors.settingsSetup.createNewUser.newUserSubmit);
    console.log("New user created successfully.");
} catch (error) {
    console.error("Error during new user creation:", error);
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async createNewUserAdmin(userName, email, firstName, lastName, password) {
const pluginsPage = Urls.baseUrl + '/wp-admin/';
await Promise.all([
this.page.goto(pluginsPage, { waitUntil: 'networkidle' }),
]);
//Go to Admin-Users
await this.page.click(selectors.settingsSetup.createNewUser.clickUserMenuAdmin);
//Add New User
await this.page.click(selectors.settingsSetup.createNewUser.clickAddNewUserAdmin);
await this.page.reload();
await this.page.waitForLoadState('domcontentloaded');
//New User creation flow
//Enter Username
await this.page.fill(selectors.settingsSetup.createNewUser.newUserName, userName);
//Enter Email
await this.page.fill(selectors.settingsSetup.createNewUser.newUserEmail, email);
//Enter First Name
await this.page.fill(selectors.settingsSetup.createNewUser.newUserFirstName, firstName);
//Enter Last Name
await this.page.fill(selectors.settingsSetup.createNewUser.newUserLastName, lastName);
//Enter Password
await this.page.fill(selectors.settingsSetup.createNewUser.newUserPassword, password);
//Allow weak Password
await this.page.check(selectors.settingsSetup.createNewUser.newUserWeakPasswordAllow);
//Select Role
await this.page.waitForLoadState('domcontentloaded');
await expect(await this.page.isVisible(selectors.settingsSetup.createNewUser.newUserSelectRole)).toBeTruthy();
await this.page.selectOption(selectors.settingsSetup.createNewUser.newUserSelectRole, { label: 'Subscriber' });
//Create User
await this.page.click(selectors.settingsSetup.createNewUser.newUserSubmit);
};
async createNewUserAdmin(userName, email, firstName, lastName, password) {
const pluginsPage = Urls.baseUrl + '/wp-admin/';
console.log("Navigating to admin users page...");
await Promise.all([
this.page.goto(pluginsPage, { waitUntil: 'networkidle' }),
]);
//Go to Admin-Users
console.log("Adding a new user...");
await this.page.click(selectors.settingsSetup.createNewUser.clickUserMenuAdmin);
await this.page.click(selectors.settingsSetup.createNewUser.clickAddNewUserAdmin);
await this.page.reload();
await this.page.waitForLoadState('domcontentloaded');
try {
//New User creation flow
console.log("Filling out new user form...");
//Enter Username
await this.page.fill(selectors.settingsSetup.createNewUser.newUserName, userName);
//Enter Email
await this.page.fill(selectors.settingsSetup.createNewUser.newUserEmail, email);
//Enter First Name
await this.page.fill(selectors.settingsSetup.createNewUser.newUserFirstName, firstName);
//Enter Last Name
await this.page.fill(selectors.settingsSetup.createNewUser.newUserLastName, lastName);
//Enter Password
await this.page.fill(selectors.settingsSetup.createNewUser.newUserPassword, password);
//Allow weak Password
await this.page.check(selectors.settingsSetup.createNewUser.newUserWeakPasswordAllow);
//Select Role
await this.page.selectOption(selectors.settingsSetup.createNewUser.newUserSelectRole, { label: 'Subscriber' });
//Create User
await this.page.click(selectors.settingsSetup.createNewUser.newUserSubmit);
console.log("New user created successfully.");
} catch (error) {
console.error("Error during new user creation:", error);
}
};

Comment on lines +22 to +37
async wpufSetup() {
//WPUF Setup
const wpufSetupPage = Urls.baseUrl + '/wp-admin/index.php?page=wpuf-setup';
await Promise.all([
this.page.goto(wpufSetupPage, { waitUntil: 'networkidle' }),
]);

const wpufSetup = await this.page.isVisible(selectors.settingsSetup.wpufSetup.validateWPUFSetupPage);
if (wpufSetup == true) {
//await this.page.click(SelectorsPage.settingsSetup.clickWPUFSetupSkip);
await this.page.click(selectors.settingsSetup.wpufSetup.clickWPUFSetupLetsGo);
await this.page.click(selectors.settingsSetup.wpufSetup.clickWPUFSetupContinue);
await this.page.click(selectors.settingsSetup.wpufSetup.clickWPUFSetupEnd);
}

};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error handling and logging.

Consider adding error handling and logging for each setup step to improve debugging and reliability.

try {
    const wpufSetup = await this.page.isVisible(selectors.settingsSetup.wpufSetup.validateWPUFSetupPage);
    if (wpufSetup) {
        await this.page.click(selectors.settingsSetup.wpufSetup.clickWPUFSetupLetsGo);
        await this.page.click(selectors.settingsSetup.wpufSetup.clickWPUFSetupContinue);
        await this.page.click(selectors.settingsSetup.wpufSetup.clickWPUFSetupEnd);
    }
} catch (error) {
    console.error("Error during WPUF setup:", error);
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async wpufSetup() {
//WPUF Setup
const wpufSetupPage = Urls.baseUrl + '/wp-admin/index.php?page=wpuf-setup';
await Promise.all([
this.page.goto(wpufSetupPage, { waitUntil: 'networkidle' }),
]);
const wpufSetup = await this.page.isVisible(selectors.settingsSetup.wpufSetup.validateWPUFSetupPage);
if (wpufSetup == true) {
//await this.page.click(SelectorsPage.settingsSetup.clickWPUFSetupSkip);
await this.page.click(selectors.settingsSetup.wpufSetup.clickWPUFSetupLetsGo);
await this.page.click(selectors.settingsSetup.wpufSetup.clickWPUFSetupContinue);
await this.page.click(selectors.settingsSetup.wpufSetup.clickWPUFSetupEnd);
}
};
async wpufSetup() {
//WPUF Setup
const wpufSetupPage = Urls.baseUrl + '/wp-admin/index.php?page=wpuf-setup';
await Promise.all([
this.page.goto(wpufSetupPage, { waitUntil: 'networkidle' }),
]);
try {
const wpufSetup = await this.page.isVisible(selectors.settingsSetup.wpufSetup.validateWPUFSetupPage);
if (wpufSetup) {
await this.page.click(selectors.settingsSetup.wpufSetup.clickWPUFSetupLetsGo);
await this.page.click(selectors.settingsSetup.wpufSetup.clickWPUFSetupContinue);
await this.page.click(selectors.settingsSetup.wpufSetup.clickWPUFSetupEnd);
}
} catch (error) {
console.error("Error during WPUF setup:", error);
}
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: dev review This PR needs review by a developer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants