Skip to content

Commit 1118df5

Browse files
committed
new: Initial commit
0 parents  commit 1118df5

File tree

11 files changed

+521
-0
lines changed

11 files changed

+521
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
playwrigth/node_modules/
2+
playwright/report

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
### Build the image
2+
3+
4+
To build the image run:
5+
6+
```
7+
docker build -t lowcoder-tests -f docker/Dockerfile docker/ --no-cache
8+
```
9+
10+
If you need to change the default playwright version (currently v1.45) add build argument to the build:
11+
12+
```
13+
docker build -t lowcoder-tests --build-arg=PLAYWRIGHT_VERSION=1.40 -f docker/Dockerfile docker/ --no-cache
14+
```
15+
16+
### Running tests
17+
18+
**Using --ipc=host is recommended when using Chrome (Docker docs). Chrome can run out of memory without this flag.**
19+
20+
```
21+
docker run -it --rm --ipc=host -v ./playwright:/app lowcoder-tests
22+
```
23+
24+
To configure to which lowcoder instance playwright is connecting, set `LOWCODER_BASE_URL` in `playwright/.env` file.
25+
26+
Once tests are finished, you can find html reposrts and videos in `playwright/report` folder.
27+
28+
## Writing tests
29+
30+
To build and run and debug tests on your computer, you can use this setup: https://playwright.dev/docs/getting-started-vscode

docker/Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM node:20-bookworm
2+
3+
# Set this build argument to change the playwright version
4+
ARG PLAYWRIGHT_VERSION=1.45
5+
6+
# Install gosu for dropping privileges
7+
ARG GOSU_VERSION=1.17
8+
RUN dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')" \
9+
&& wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch" \
10+
&& chmod +x /usr/local/bin/gosu \
11+
&& gosu nobody true
12+
13+
# Create user playwright - privileges will be dropped by entrypoint.sh
14+
RUN userdel -rf node \
15+
&& groupadd --gid=1001 playwright \
16+
&& useradd --system --uid=1001 --gid=1001 --create-home --home-dir=/home/playwright playwright
17+
18+
# Install playwright and all its dependencies (browsers etc...)
19+
USER playwright
20+
WORKDIR /home/playwright
21+
RUN npm install @playwright/test \
22+
&& npx -y playwright@${PLAYWRIGHT_VERSION} install
23+
24+
USER root
25+
RUN npx playwright install-deps
26+
27+
# Copy entrypoint script
28+
COPY --chmod=0755 entrypoint.sh /entrypoint.sh
29+
30+
# /app is the home folder of playwright tests root
31+
RUN mkdir -p /app
32+
WORKDIR /app
33+
34+
35+
ENTRYPOINT [ "/entrypoint.sh" ]

docker/entrypoint.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
if [ "$(id -u)" = "0" ]; then
4+
echo "Running as root, dropping privileges..."
5+
TESTS_UID=`ls -n /app/tests | tail -1 | cut -f3 -d' '`
6+
TESTS_GID=`ls -n /app/tests | tail -1 | cut -f4 -d' '`
7+
PUID=`id playwright -u`
8+
PGID=`id playwright -g`
9+
10+
if [ "${TESTS_GID}" != "${PGID}" ]; then
11+
echo " changing GID to ${TESTS_GID}"
12+
groupmod --gid="${TESTS_GID}" -o playwright
13+
fi;
14+
15+
if [ "${TESTS_UID}" != "${PUID}" ]; then
16+
echo " changing UID to ${TESTS_UID}"
17+
usermod --uid="${TESTS_UID}" -o playwright
18+
fi;
19+
fi;
20+
21+
cd /app
22+
if [ ! -e "/app/node_modules" ]; then
23+
gosu playwright npm install
24+
fi;
25+
26+
gosu playwright npx playwright test

playwright/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
LOWCODER_BASE_URL=http://192.168.0.50:3003

playwright/fixtures.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test as base } from '@playwright/test';
2+
import { LoginPage } from './pages/login-page';
3+
4+
// Declare the types of your fixtures.
5+
type MyFixtures = {
6+
loginPage: LoginPage;
7+
};
8+

playwright/package-lock.json

Lines changed: 159 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

playwright/package.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "playwright",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {},
7+
"keywords": [],
8+
"author": "",
9+
"license": "ISC",
10+
"devDependencies": {
11+
"@playwright/test": "^1.45.1",
12+
"@types/node": "^20.14.10"
13+
},
14+
"dependencies": {
15+
"dotenv": "^16.4.5"
16+
}
17+
}

playwright/pages/login-page.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import type { Page, Locator } from '@playwright/test';
2+
3+
export class LoginPage {
4+
private readonly emailInput: Locator;
5+
private readonly passwordInput: Locator;
6+
private readonly confirmPasswordInput: Locator;
7+
private readonly signInButton: Locator;
8+
private readonly signUpButton: Locator;
9+
private readonly signInLink: Locator;
10+
private readonly signUpLink: Locator;
11+
12+
constructor(public readonly page: Page) {
13+
this.emailInput = this.page.getByPlaceholder(/^Please enter your email$/);
14+
this.passwordInput = this.page.getByPlaceholder(/^Please enter your password$/);
15+
this.confirmPasswordInput = this.page.getByPlaceholder(/^Please Confirm Password$/);
16+
this.signInButton = this.page.getByRole('button', { name: 'Sign In' });
17+
this.signUpButton = this.page.getByRole('button', { name: 'Sign Up' });
18+
this.signUpLink = this.page.getByRole('link', { name: 'Sign In' });
19+
this.signUpLink = this.page.getByRole('link', { name: 'Sign Up' });
20+
}
21+
22+
async loadPage() {
23+
await this.page.goto('/user/auth/login');
24+
}
25+
26+
async fillEmail(text: string) {
27+
await this.emailInput.click();
28+
await this.emailInput.fill(text);
29+
}
30+
31+
async fillPassword(text: string) {
32+
await this.passwordInput.click();
33+
await this.passwordInput.fill(text);
34+
}
35+
36+
async fillConfirmPassword(text: string) {
37+
await this.confirmPasswordInput.click();
38+
await this.confirmPasswordInput.fill(text);
39+
}
40+
41+
async clickSignIn() {
42+
await this.signInButton.click();
43+
}
44+
45+
async clickSignUp() {
46+
await this.signUpButton.click();
47+
}
48+
49+
async clickSignUpLink() {
50+
await this.signUpLink.click();
51+
}
52+
53+
async signUp(username: string, password: string, repeatPassword: string) {
54+
if (await this.signUpLink.isVisible()) {
55+
await this.clickSignUpLink();
56+
}
57+
58+
await this.fillEmail(username);
59+
60+
/* disabled because the placeholder is different between sign in and sign up */
61+
//await this.fillPassword(password);
62+
await this.page.getByPlaceholder(/^Please Enter Password$/).click();
63+
await this.page.getByPlaceholder(/^Please Enter Password$/).fill(password);
64+
65+
await this.fillConfirmPassword(repeatPassword);
66+
await this.clickSignUp();
67+
}
68+
69+
async logIn(username: string, password: string) {
70+
await this.loadPage();
71+
await this.fillEmail(username);
72+
await this.fillPassword(password);
73+
await this.clickSignIn();
74+
}
75+
76+
async logOut(username: string) {
77+
await this.page.getByTitle(username, { exact: true }).click();
78+
await this.page.getByText('Log Out').click({delay: 1000});
79+
}
80+
81+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy