-
Notifications
You must be signed in to change notification settings - Fork 27.3k
docs: update e2e skill #68936
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
Open
alejandrocuba
wants to merge
2
commits into
angular:main
Choose a base branch
from
alejandrocuba:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+47
−54
Open
docs: update e2e skill #68936
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 46 additions & 53 deletions
99
skills/dev-skills/angular-developer/references/e2e-testing.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,66 +1,59 @@ | ||
| # End-to-End (E2E) Testing | ||
|
|
||
| This project uses [Cypress](https://www.cypress.io/) for end-to-end (E2E) testing, which simulates real user interactions in a browser. The E2E tests are located primarily within the `devtools/` package. | ||
| > [!IMPORTANT] | ||
| > Only use the setup guidelines in this file if there is no existing E2E testing framework configured in the workspace, or if the user has explicitly requested to change or set up E2E testing. | ||
|
|
||
| ## Running E2E Tests | ||
| ## Setting Up and Running E2E Tests | ||
|
|
||
| The primary way to run E2E tests is through the `pnpm` script defined in the root `package.json`. | ||
|
|
||
| 1. **Build DevTools:** The E2E tests run against a built version of the devtools extension. You must build it first: | ||
| Add supported E2E frameworks to the project using `ng add`: | ||
|
|
||
| * **Cypress:** | ||
| ```shell | ||
| pnpm -F ng-devtools-mcp build:dev | ||
| ng add @cypress/schematic | ||
| ``` | ||
| * **Playwright:** | ||
| ```shell | ||
| ng add playwright-ng-schematics | ||
| ``` | ||
| * **Nightwatch:** | ||
| ```shell | ||
| ng add @nightwatch/schematics | ||
| ``` | ||
| * **WebdriverIO:** | ||
| ```shell | ||
| ng add @wdio/schematics | ||
| ``` | ||
| * **Puppeteer:** | ||
| ```shell | ||
| ng add @puppeteer/ng-schematics | ||
| ``` | ||
|
|
||
| 2. **Run Cypress:** Use the `cy:open` or `cy:run` script: | ||
| - To open the interactive Cypress Test Runner: | ||
| ```shell | ||
| pnpm -F ng-devtools-mcp cy:open | ||
| ``` | ||
| - To run the tests headlessly in the terminal (ideal for CI): | ||
| ```shell | ||
| pnpm -F ng-devtools-mcp cy:run | ||
| ``` | ||
|
|
||
| ## Test Structure | ||
|
|
||
| - **Configuration:** The main Cypress configuration is located at `devtools/cypress.json`. | ||
| - **Specs:** Test files (specs) are located in `devtools/cypress/integration/`. | ||
| - **Custom Commands:** Reusable custom commands and actions are defined in `devtools/cypress/support/`. | ||
|
|
||
| ### Example E2E Test Snippet | ||
|
|
||
| A typical test might look like this: | ||
|
|
||
| ```typescript | ||
| // in devtools/cypress/integration/profiler.spec.ts | ||
|
|
||
| describe('Profiler', () => { | ||
| beforeEach(() => { | ||
| cy.visit('/?e2e-app'); | ||
| cy.wait(1000); | ||
| cy.get('ng-devtools-tabs').find('a').contains('Profiler').click(); | ||
| }); | ||
|
|
||
| it('should record and display profiling data', () => { | ||
| // Find the record button and click it | ||
| cy.get('button[aria-label="start-recording-button"]').click(); | ||
| Run E2E tests: | ||
| ```shell | ||
| ng e2e [project] [options] | ||
| ``` | ||
|
|
||
| // Interact with the test application to generate profiling data | ||
| cy.get('body').find('#cards button').first().click(); | ||
| cy.wait(500); | ||
| ### Builder Configuration | ||
|
|
||
| E2E runners are configured under the `e2e` target of the application in `angular.json`: | ||
| ```json | ||
| "e2e": { | ||
| "builder": "@cypress/schematic:cypress", | ||
| "options": { | ||
| "devServerTarget": "my-app:serve" | ||
| }, | ||
| "configurations": { | ||
| "production": { | ||
| "devServerTarget": "my-app:serve:production" | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| // Stop recording | ||
| cy.get('button[aria-label="stop-recording-button"]').click(); | ||
| ## Creating a Custom E2E Builder | ||
|
|
||
| // Assert that the flame graph is now visible | ||
| cy.get('ng-devtools-recording-timeline').find('canvas').should('be.visible'); | ||
| }); | ||
| }); | ||
| ``` | ||
| For advanced runner integrations (e.g., wrapper execution with custom setup/teardown), implement a custom CLI builder following the [Angular CLI Builder Documentation](https://angular.dev/tools/cli/cli-builder#creating-a-builder). | ||
|
|
||
| ### Best Practices | ||
| ## Custom & Enterprise Testing Tools | ||
|
|
||
| - **Use `data-` attributes:** Whenever possible, use `data-cy` or similar attributes for selecting elements to make tests more resilient to CSS or structural changes. | ||
| - **Custom Commands:** Encapsulate common sequences of actions into custom commands in the `support` directory to keep tests clean and readable. | ||
| - **Wait for Application State:** Use `cy.wait()` for arbitrary waits sparingly. Prefer to wait for specific UI elements to appear or for network requests to complete to avoid flaky tests. | ||
| For custom enterprise runners (e.g., Katalon Studio, TestCafe, Selenium), define execution commands in `package.json` scripts. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.