Skip to content

Commit e34661c

Browse files
committed
add blogs on running plywright tests in CI using github actions
Signed-off-by: nabim777 <[email protected]>
1 parent 9dba5c0 commit e34661c

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed
190 KB
Loading
40.6 KB
Loading
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
---
2+
title: Playwright and GitHub Actions - Run tests in CI
3+
authorName: Nabin Ale
4+
authorAvatar : https://avatars.githubusercontent.com/u/61624650?v=4
5+
authorLink: https://github.com/nabim777
6+
createdAt: Apr 8, 2025
7+
tags: continuous integration, continuous delivery, continuous deployment, github actions, ci, cd, playwright
8+
banner: https://blog.jankaritech.com/src/assets/RunPlaywrightOnCI/images/githubaction_with_playwright_banner
9+
---
10+
11+
This is a blog about how to run Playwright UI tests in GitHub Actions. If you are not familiar and new to UI testing using Playwright, then it would be good to check out this blog about [Playwright](https://blog.jankaritech.com/#/blog/E2E%20Testing%20using%20BDD%20with%20Playwright/Behavior%20Driven%20Development%20(BDD)%20using%20Playwright). Similarly, if you are unfamiliar with GitHub Actions, you can check another blog about [Introduction to GitHub Actions](https://blog.jankaritech.com/#/blog/Introduction%20to%20GitHub%20Actions%20-%20CI%20%26%20CD).
12+
13+
## 🤔 Why to run tests on CI?
14+
Tests are run on CI(Continuous Integration) to ensure the code works properly in a clean and an isolated environment every time a change is made. Here are some reasons:
15+
16+
**1. Early bug detection:**
17+
By automatically running tests after every code commit, you can quickly identify issues as they arise, preventing them from accumulating and causing larger problems later on.
18+
19+
**2. Fast feedback loop:**
20+
Developers get immediate notification for failing tests. That way they can fix bugs immediately and iterate quickly.
21+
22+
**3. Consistent testing environment:**
23+
The CI servers run tests in an uniform environment. Therefore, there is no correlation between the developer configurations.
24+
25+
**4. Improved code quality:**
26+
Regular running tests in CI ensures existing functionality does not become unusable if changes are made.
27+
28+
**5. Reduced integration issues:**
29+
By regularly integrating and testing the code in CI, you reduce the risk of conflicts when merging large patches of code.
30+
31+
**6. Automated process:**
32+
CI systems enable developers to save time and effort testing things.
33+
34+
## 📘 About the Project
35+
36+
![Login page of the Project](/src/assets/githubAction/images/project_login_page.png "momo application")
37+
38+
In this blog, I have taken simple applications built using Vue.js. The GitHub repository is available at: https://github.com/nabim777/momo-restro-list.git
39+
40+
This is a basic application that includes login and logout functionality. E2E test is written using Playwright to verify the login feature.
41+
42+
## 🛠️ Running App Locally
43+
Before setting up CI, let's run the application and tests locally.
44+
45+
**1. Install dependencies**
46+
47+
```bash
48+
npm install
49+
```
50+
51+
**2. Start the frontend and backend servers**
52+
53+
54+
```bash
55+
npm run serve # Start frontend
56+
npm run backend # Start backend
57+
```
58+
59+
## 🧪 Running UI Tests Locally
60+
61+
> **_NOTE:_** Make sure both the frontend and backend are running before running the tests.
62+
63+
To run the UI tests locally, use the following command:
64+
65+
```bash
66+
npm run test:e2e tests
67+
```
68+
69+
70+
71+
## ⚙️ Setting Up CI in GitHub Actions
72+
After verifying the app locally, the next step is to set up CI using GitHub Actions. First, create a file named `ci.yml` in a project using the following folder structure:
73+
74+
```
75+
📦momo-restro-list
76+
┗ 📂.github
77+
┃ ┣ 📂workflows
78+
┃ ┃ ┗ 📜ci.yml
79+
```
80+
81+
Then, add the following code in the `ci.yml`.
82+
83+
```yml
84+
name: Run-project
85+
86+
on:
87+
push:
88+
branches:
89+
- master
90+
pull_request:
91+
branches:
92+
- master
93+
94+
jobs:
95+
run-Restro-project:
96+
runs-on: ubuntu-latest
97+
steps:
98+
- name: Checkout repo code
99+
uses: actions/checkout@v3
100+
101+
- name: Set up node
102+
uses: actions/setup-node@v3
103+
with:
104+
node-version: 20.x
105+
106+
- name: Run the project
107+
run: |
108+
npm run serve &
109+
npm run backend &
110+
111+
- name: Wait for services
112+
run: |
113+
sudo apt-get install wait-for-it -y
114+
wait-for-it -h localhost -p 8080 -t 10
115+
wait-for-it -h localhost -p 3000 -t 10
116+
117+
- name: Install playwright and run web-ui tests
118+
run: |
119+
npx playwright install
120+
npm run test:e2e tests
121+
```
122+
123+
124+
## 🔍 What this Workflow Does?
125+
This GitHub Actions file runs when you push to the `master` branch or create a pull request to `master`
126+
127+
It has one job called `run-Restro-project` with these steps:
128+
1. **Checkout repo code** - Gets the project code from GitHub.
129+
2. **Set up node** - Installs Node.js version 20.
130+
3. **Run the project** - Starts the Vue app, and starts the backend using json-server.
131+
4. **Wait for services** - Waits for the frontend (port 8080) and backend (port 3000) to be ready.
132+
5. **Install playwright and run web-ui tests** - Installs Playwright and runs e2e tests to check if the UI works properly.
133+
134+
## 📝 Conclusion
135+
Using GitHub Actions to run your Playwright UI tests ensures your app is always tested in a clean, repeatable environment. It helps catch bugs early, improves collaboration, and keeps your project in a healthy state.

0 commit comments

Comments
 (0)