Skip to content

fix(tooling): add-playwright-tests#420

Merged
Shreyas281299 merged 32 commits into
webex:ccwidgetsfrom
Shreyas281299:playwright
May 26, 2025
Merged

fix(tooling): add-playwright-tests#420
Shreyas281299 merged 32 commits into
webex:ccwidgetsfrom
Shreyas281299:playwright

Conversation

@Shreyas281299

@Shreyas281299 Shreyas281299 commented Mar 24, 2025

Copy link
Copy Markdown
Contributor

COMPLETES # https://jira-eng-sjc12.cisco.com/jira/browse/CAI-6397

This pull request addresses

  • Adds playwright testing in widgets
  • Adds playwright testing in our pull_request github actions
  • Adds test for station login (login, mulitlogin, relogin)

by making the following changes

  • We can run the command yarn run test:e2e to start the playwright tests in widgets
  • In our pipelines, we can add run_e2e label to run the e2e tests for a PR
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Tooling change
  • Internal code refactor

The following scenarios were tested

Screenshot 2025-05-20 at 1 53 48 PM

Passing: https://github.com/Shreyas281299/widgets/actions/runs/15132156111
Screenshot 2025-05-20 at 1 53 54 PM

The GAI Coding Policy And Copyright Annotation Best Practices

  • GAI was not used (or, no additional notation is required)
  • Code was generated entirely by GAI
  • GAI was used to create a draft that was subsequently customized or modified
  • Coder created a draft manually that was non-substantively modified by GAI (e.g., refactoring was performed by GAI on manually written code)
  • Tool used for AI assistance (GitHub Copilot / Other - specify)
    • Github Copilot
    • Other - Please Specify
  • This PR is related to
    • Feature
    • Defect fix
    • Tech Debt
    • Automation

Checklist before merging

  • I have not skipped any automated checks
  • All existing and new tests passed
  • I have updated the testing document

@coderabbitai

coderabbitai Bot commented Mar 24, 2025

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

The changes introduce Playwright-based end-to-end testing to the project. A new Playwright configuration file and test suite are added, along with related dependencies and scripts in package.json. The GitHub Actions workflow is updated to include a new job for running Playwright tests, which executes only when the run_e2e label is present on a pull request. Test artifacts are ignored in .gitignore, and data-testid attributes are added to key React components to facilitate test automation. Minor adjustments are made to ESLint and Jest configurations, and a new development dependency for Node.js types is included.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@aws-amplify-us-east-2

Copy link
Copy Markdown

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-420.d1b38q61t1z947.amplifyapp.com

@Shreyas281299 Shreyas281299 force-pushed the playwright branch 2 times, most recently from 93be8ae to 9610a5d Compare April 29, 2025 10:28
Comment thread playwright.config.ts Outdated
@Shreyas281299 Shreyas281299 added the validated Indicates that the PR is ready for actions label May 20, 2025

@mkesavan13 mkesavan13 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good mostly. Just a few things

Comment thread .github/workflows/pull-request.yml Outdated
Comment thread .github/workflows/pull-request.yml Outdated
Comment thread .github/workflows/pull-request.yml
@bhabalan

Copy link
Copy Markdown
Contributor

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented May 22, 2025

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@Shreyas281299

Copy link
Copy Markdown
Contributor Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented May 22, 2025

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (3)
.github/workflows/pull-request.yml (3)

175-175: Consider reducing the timeout value.

Isn't 60 minutes a lot to timeout? Consider keeping it to 15 or 20 minutes instead to detect and fail stuck tests more quickly.


208-211: Verify if ACCESS_TOKEN is still required.

With OAuth setup, is this ACCESS_TOKEN still needed? Also, this approach requires setting up the access token secret in the parent repo and keeping it updated regularly.


216-223: Clarify where artifacts are uploaded.

Where do these artifacts get uploaded? Consider adding a comment to document the destination and retention policy of these test artifacts.

🧹 Nitpick comments (5)
packages/contact-center/cc-components/src/components/UserState/user-state.tsx (2)

108-112: Refactor dynamic data-testid on item container
Embedding dynamic classes inside data-testid can break selector stability. Consider using a static data-testid="item-container" and assert highlight state via its className.

- data-testid={`item-container ${shouldHighlight ? `selected ${getIconStyle(item).class}` : ''}`}
+ data-testid="item-container"

108-108: Use immutable identifiers for list items
data-testid={state-item-${item.name}} may include spaces or casing changes. Using item.id or a slugified version ensures consistent selectors.

- data-testid={`state-item-${item.name}`}
+ data-testid={`state-item-${item.id}`}
.github/workflows/pull-request.yml (1)

182-185: Update checkout action version.

The version of actions/checkout@v3 is outdated. Consider updating to the latest version.

- uses: actions/checkout@v3
+ uses: actions/checkout@v4
🧰 Tools
🪛 actionlint (1.7.7)

182-182: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

playwright/login-user-state.spec.ts (2)

11-145: Consider refactoring repeated code patterns.

There's significant code duplication across the test cases, particularly for:

  1. Checking and filling the ACCESS_TOKEN
  2. Handling login/logout button state verification
  3. Navigation to the application URL

Consider extracting these common patterns into helper functions or using test fixtures to improve maintainability.


12-12: Use baseURL from configuration instead of hardcoded URLs.

You've defined baseURL: 'http://localhost:3000' in the Playwright config, but you're using hardcoded URLs in the tests. Use relative paths with the configured baseURL:

- await page.goto('http://localhost:3000/');
+ await page.goto('/');

Also applies to: 56-57, 105-105

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f67f9c and 9c09e1d.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (9)
  • .github/workflows/pull-request.yml (2 hunks)
  • .gitignore (1 hunks)
  • package.json (2 hunks)
  • packages/contact-center/cc-components/src/components/StationLogin/station-login.tsx (5 hunks)
  • packages/contact-center/cc-components/src/components/UserState/user-state.tsx (4 hunks)
  • packages/contact-center/station-login/eslint.config.mjs (1 hunks)
  • packages/contact-center/station-login/package.json (2 hunks)
  • playwright.config.ts (1 hunks)
  • playwright/login-user-state.spec.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/contact-center/cc-components/src/components/StationLogin/station-login.tsx (1)
Learnt from: Kesari3008
PR: webex/widgets#239
File: packages/contact-center/station-login/tests/station-login/station-login.presentational.tsx:0-0
Timestamp: 2024-11-19T13:44:14.152Z
Learning: The file `packages/contact-center/station-login/tests/station-login/station-login.presentational.tsx` is going to change completely, so writing tests for these changes are being ignored.
🧬 Code Graph Analysis (1)
packages/contact-center/cc-components/src/components/UserState/user-state.tsx (1)
packages/contact-center/cc-components/src/utils/index.ts (1)
  • formatTime (4-17)
🪛 actionlint (1.7.7)
.github/workflows/pull-request.yml

182-182: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🔇 Additional comments (18)
packages/contact-center/station-login/eslint.config.mjs (1)

10-12: ESLint config reformat — looks good
The multi-line ignores block improves readability without altering behavior.

.gitignore (1)

50-54: Ignore Playwright test artifacts
Adding **/test-results/ and **/playwright-report ensures Playwright output isn’t committed. The existing test_results/ rule remains for any legacy artifacts with underscores.

packages/contact-center/cc-components/src/components/UserState/user-state.tsx (4)

86-99: Add stable test IDs to container & select
The new data-testid attributes on the root <div> and <SelectNext> enable reliable element targeting in Playwright.


117-119: Approve icon & text test IDs
Static data-testid on the <Icon> and <Text> elements provides clear hooks for verifying both visuals and labels.


131-132: Approve elapsed-time test ID
The <span> for elapsed times now has a stable data-testid="elapsed-time", facilitating accurate timing assertions.


137-137: Approve arrow-icon test ID
Adding data-testid="select-arrow-icon" on the dropdown indicator supports end-to-end assertions on dropdown state.

package.json (1)

15-15: Introduce Playwright and e2e script
Adding @playwright/test@^1.51.1 and a test:e2e script integrates E2E testing into local workflows.

Also applies to: 50-50

packages/contact-center/station-login/package.json (1)

37-37: Add Node types & narrow Jest patterns
Including @types/node and refining jest.testMatch to tests/station-login/*.ts(x) scopes unit tests appropriately.

Also applies to: 69-70

packages/contact-center/cc-components/src/components/StationLogin/station-login.tsx (1)

128-128: Well-implemented test identifiers for Playwright E2E testing.

You've added appropriate data-testid attributes to key interactive elements in the StationLogin component. These identifiers are well-named and align with the selectors used in the Playwright tests, enabling robust UI testing.

Also applies to: 169-169, 175-180, 212-212, 226-226, 245-245, 249-249

.github/workflows/pull-request.yml (2)

144-144: Good implementation of conditional E2E test execution.

Adding a condition to run E2E tests only when the PR has the run_e2e label is a good practice. This prevents unnecessary test runs and saves CI resources.


213-215: Good implementation of the Playwright test execution.

The step to run Playwright tests is correctly set up using the new test:e2e script defined in package.json.

playwright.config.ts (3)

1-21: Well-configured Playwright setup with web server integration.

The configuration properly loads environment variables and sets up a local development server for testing. The reuse of existing servers in local development is a good optimization.


22-37: Good testing configuration for stability.

Running tests non-parallel with a single worker is appropriate for ensuring stability during initial implementation of Playwright tests. The trace retention policy is well configured to capture failures without excessive storage use.


39-57: Appropriate browser selection strategy.

Starting with just Chromium and commenting out additional browsers until stability is achieved is a sensible approach. The dependencies array ensures browsers will run in sequence when enabled.

playwright/login-user-state.spec.ts (4)

3-10: Good test setup with environment validation.

The beforeAll hook correctly validates that the required ACCESS_TOKEN environment variable is present before running tests.


11-48: Well-implemented extension login test flow.

The test thoroughly verifies the login flow with the Extension option, including state changes and logout functionality.


50-98: Comprehensive multi-login test across browser tabs.

This test effectively validates that login state synchronizes across multiple tabs, which is a critical feature for multi-device usage scenarios.


100-145: Thorough relogin test after page refresh.

The test correctly verifies that login state and preferences persist after a page refresh, which is important for maintaining user session integrity.

@@ -0,0 +1,35 @@
import {test as setup} from '@playwright/test';

@Shreyas281299 Shreyas281299 May 23, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is global.setup.ts, we are running this through the playwright.config(see project in the config), this will run before running any playwright test, ensuring that before running any test we have an access_token,

We would need to add 2 secrets in our actions
PLAYWRIGHT_USERNAME
PLAYWRIGHT_PASSWORD

We can add more username pass and more oauth process like this to store more access_tokens

const fs = require('fs');
const path = require('path');

setup('OAuth', async ({browser}) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we write a cleanup for this?

<Option key={1} value="token">Access Token</Option>
<Option key={2} value="oauth">Login with Webex</Option>
<Option data-testid='samples:login_option_token' key={1} value="token">Access Token</Option>
<Option data-testid='samples:login_option_oauth' key={2} value="oauth">Login with Webex</Option>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we really complicate this value by having a ":"? Can we just do "_" or "-" every where?

@Shreyas281299 Shreyas281299 merged commit fa52889 into webex:ccwidgets May 26, 2025
7 of 8 checks passed
github-actions Bot pushed a commit that referenced this pull request May 26, 2025
# [1.28.0-ccwidgets.61](v1.28.0-ccwidgets.60...v1.28.0-ccwidgets.61) (2025-05-26)

### Bug Fixes

* **tooling:** add-playwright-tests ([#420](#420)) ([fa52889](fa52889))
@sreenara

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.28.0-ccwidgets.61 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released on @ccwidgets validated Indicates that the PR is ready for actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants