From ff2a3c7026db008426d71dc7ea786a1dc3bffe50 Mon Sep 17 00:00:00 2001 From: mildred Date: Wed, 6 Mar 2024 20:57:38 +0100 Subject: [PATCH] add ci workflow --- README.md | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 02ee93c..7ac60c1 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ To clone the repository and install the project dependencies, follow these steps To run the tests, navigate to the project directory in your terminal and execute the following command: ```bash -npm test +npx playwright test ``` This command runs the test suite using Playwright, executing all tests defined in the project. @@ -129,6 +129,76 @@ The tests directory is where all test files are stored. These test files contai describe +## GitHub Actions Workflow Configuration for Running Playwright Tests + +Following we outline the configuration of a GitHub Actions workflow designed to running tests on GitHub using GitHub actions It breaks down the key components of the workflow to ensure clarity and understanding. +```yaml +name: Playwright Tests +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] +jobs: + test: + timeout-minutes: 60 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Install dependencies + run: npm ci + - name: Install Playwright Browsers + run: npx playwright install --with-deps + - name: Run Playwright tests + run: npx playwright test + - uses: actions/upload-artifact@v3 + if: always() + with: + name: playwright-report + path: playwright-report/ + retention-days: 30 + +``` +### Workflow Name + +- **Workflow Name**: The name of this workflow is "Playwright Tests". This identifier is used within GitHub Actions to reference this workflow. + +### Trigger Events + +- **Push to Main or Master Branches**: The workflow is triggered on any push event to the `main` or `master` branches. +- **Pull Requests to Main or Master Branches**: Similarly, the workflow is also triggered upon any pull request that targets the `main` or `master` branches. + +### Jobs + +- **Jobs**: The workflow defines a job named `test`. This job is executed when the workflow is triggered. + +### Job Configuration + +- **Timeout**: A timeout of 60 minutes is set for this job. If the job exceeds this time, it will be automatically canceled. +- **Environment**: The job is configured to run on the latest version of Ubuntu provided by GitHub Actions. + +### Steps + +1. **Checkout Repository**: The first step checks out the repository, allowing the workflow to access it. + - `uses: actions/checkout@v3` +2. **Setup Node.js Environment**: Sets up a Node.js environment using the specified version (Node.js 18). + - `uses: actions/setup-node@v3` with `node-version: 18` +3. **Install Dependencies**: Installs the project dependencies using `npm ci`, leveraging the `package-lock.json` for precise dependency versions. + - `run: npm ci` +4. **Install Playwright Browsers**: Installs the necessary Playwright browsers along with all necessary system dependencies using `npx playwright install --with-deps`. + - `run: npx playwright install --with-deps` +5. **Run Playwright Tests**: Executes the Playwright tests using `npx playwright test`. + - `run: npx playwright test` +6. **Upload Artifact**: Uploads the `playwright-report/` directory as an artifact named `playwright-report`. This step always runs, even if previous steps fail, and the artifact is retained for 30 days before automatic deletion. + - `uses: actions/upload-artifact@v3` with `if: always()`, `name: playwright-report`, `path: playwright-report/`, and `retention-days: 30` + +### Summary + +This workflow automates the process of running Playwright tests on pushes and pull requests to the `main` and `master` branches, ensuring that code changes do not break existing functionality. It includes steps for setting up the environment, installing dependencies, installing necessary browsers for Playwright, running the tests, and uploading test reports as artifacts for review. + ## License [Include information about the project's license.]