Skip to content

Commit c247fd8

Browse files
authored
chore: copy in playwright repo from Enterpise unmodified (#4528)
1 parent ea068fd commit c247fd8

32 files changed

+3259
-0
lines changed

.github/workflows/nightly.yaml

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
name: Playwright Tests
2+
3+
on:
4+
push:
5+
branches: "**"
6+
schedule:
7+
- cron: "30 22 * * *"
8+
workflow_dispatch:
9+
inputs:
10+
chart_version:
11+
description: 'weave gitops enterprise chart version'
12+
required: true
13+
type: string
14+
15+
env:
16+
MANAGEMENT_CLUSTER_TYPE: "kind"
17+
CLUSTER_NAME: run-playwright-tests-${{ github.run_id }}
18+
USER_NAME: wego-admin
19+
PASSWORD: ${{ secrets.CLUSTERS_CONFIG_PASSWORD }}
20+
WEAVE_GITOPS_DEV_SOPS_KEY: ${{ secrets.WEAVE_GITOPS_DEV_SOPS_KEY }}
21+
CLUSTER_ADMIN_PASSWORD_HASH: ${{ secrets.CLUSTERS_CONFIG_PASSWORD }}
22+
WEAVEWORKS_BOT_TOKEN: ${{ secrets.WEAVEWORKS_BOT_TOKEN }}
23+
ENTERPRISE_CHART_VERSION: ${{ inputs.chart_version }}
24+
DEFAULT_ENTERPRISE_CHART_VERSION: "0.31.0-9-gdae6755"
25+
26+
jobs:
27+
build_and_run_tests:
28+
29+
runs-on: ubuntu-latest
30+
31+
permissions:
32+
id-token: write
33+
contents: read
34+
35+
steps:
36+
- uses: actions/checkout@v3
37+
- name : Set URL environment Variable
38+
run: |
39+
echo "URL=http://localhost:8000" >> $GITHUB_ENV
40+
41+
- name: Check if the URL variable is available
42+
run: |
43+
echo ${{ env.URL }}
44+
45+
- name: Set up Python 3.10
46+
uses: actions/setup-python@v3
47+
with:
48+
python-version: "3.10"
49+
- name: Install dependencies
50+
run: |
51+
python -m pip install --upgrade pip
52+
pip install flake8 pytest
53+
pip install pytest_dotenv
54+
pip install pytest-reporter-html1
55+
56+
- name: Install pre-commit
57+
run: |
58+
pip install pre-commit
59+
60+
- name: Install flux
61+
run: |
62+
curl -s https://fluxcd.io/install.sh | sudo bash
63+
flux version --client
64+
65+
- name: Install kubectl
66+
run: |
67+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
68+
chmod +x kubectl
69+
sudo mv ./kubectl /usr/local/bin/kubectl
70+
kubectl version --client
71+
72+
- name: Install kind
73+
run: |
74+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
75+
chmod +x ./kind
76+
sudo mv ./kind /usr/local/bin/kind
77+
which kind
78+
kind version
79+
80+
- name: Install playwright
81+
run: |
82+
pip install pytest-playwright
83+
84+
- name: Install chromium
85+
run: |
86+
playwright install chromium
87+
88+
- name: Lint with flake8
89+
run: |
90+
# stop the build if there are Python syntax errors or undefined names
91+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
92+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
93+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
94+
95+
- name: Setup management cluster
96+
run: |
97+
./utils/scripts/mgmt-cluster-setup.sh ${{ env.MANAGEMENT_CLUSTER_TYPE }} $(pwd) ${{ env.CLUSTER_NAME }}
98+
99+
- name: Extract branch name
100+
run: |
101+
echo "branch_name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
102+
id: extract_branch
103+
104+
- name: Setup wego enterprise
105+
run: |
106+
kubectl create namespace flux-system
107+
flux install
108+
kubectl create secret generic git-provider-credentials -n flux-system --from-literal=username="weave-gitops-bot" --from-literal=password="${WEAVEWORKS_BOT_TOKEN}"
109+
sed -i 's/BRANCH_NAME/${{ steps.extract_branch.outputs.branch_name }}/' ./utils/scripts/resources/flux-system-gitrepo.yaml
110+
./utils/scripts/wego-enterprise.sh setup ./utils/scripts
111+
112+
- name: Install violating-app
113+
run: |
114+
kubectl apply -f ./utils/data/violating-podinfo-kustomization.yaml
115+
116+
- name: Install policies
117+
run: |
118+
kubectl apply -f ./utils/data/policies.yaml
119+
120+
- name: Flux reconcile violating app
121+
run: |
122+
flux reconcile kustomization violating-podinfo -n default --with-source || true
123+
kubectl get pods -A
124+
125+
- name: Install gitopsset-configmaps
126+
run: |
127+
kubectl apply -f ./utils/data/gitops-sets-kustomization.yaml
128+
129+
- name: run tests
130+
if: success()
131+
run: |
132+
pytest -s -v --video=retain-on-failure --screenshot=only-on-failure --template=html1/index.html --report=test-results/test-run-report.html -o junit_family=xunit2 --junit-xml=test-results/junit_test_report.xml
133+
134+
- name: Generate tests report
135+
if: always()
136+
uses: pmeier/pytest-results-action@main
137+
with:
138+
path: test-results/junit_test_report.xml
139+
summary: true
140+
display-options: fEX
141+
fail-on-empty: true
142+
143+
- name: Upload test report
144+
uses: actions/upload-artifact@v3
145+
if: success() || failure()
146+
with:
147+
name: playwright-tests-report
148+
path: test-results/
149+
retention-days: 3
150+
151+
- name: Download test artifacts
152+
uses: actions/[email protected]
153+
if: success() || failure()
154+
with:
155+
name: playwright-tests-report
156+
path: test-results/
157+
158+
- name: Display structure of downloaded files
159+
if: always()
160+
run: ls -R
161+
working-directory: test-results
162+
163+
- name: Publish test report
164+
id: test_summary
165+
uses: mikepenz/[email protected]
166+
if: success() || failure()
167+
with:
168+
report_paths: test-results/junit_test_report.xml
169+
170+
- name: Notify Slack
171+
id: slack
172+
uses: slackapi/[email protected]
173+
with:
174+
channel-id: C058RPVS5DZ
175+
payload: |
176+
{
177+
"blocks": [
178+
{
179+
"type": "section",
180+
"text": {
181+
"type": "mrkdwn",
182+
"text": "*Tests result:*"
183+
}
184+
},
185+
{
186+
"type": "section",
187+
"text": {
188+
"type": "mrkdwn",
189+
"text": "Tests :test_tube:\t\t\tPassed :check:\t\t\tSkipped :arrow_right_hook:\t\t\tFailed :x:\n>executed:*${{steps.test_summary.outputs.total}}*\t\t\tpassed:*${{steps.test_summary.outputs.passed}}*\t\t\tskipped:*${{steps.test_summary.outputs.skipped}}*\t\t\tfailed:*${{steps.test_summary.outputs.failed}}*"
190+
}
191+
},
192+
{
193+
"type": "section",
194+
"text": {
195+
"type": "mrkdwn",
196+
"text": "*View result on Github:* ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
197+
}
198+
}
199+
]
200+
}
201+
if: always()
202+
env:
203+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
204+
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
205+
206+
- name : Delete test cluster
207+
if: success() || failure()
208+
run: |
209+
kind delete clusters --all

playwright/README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Playwright Tests
2+
3+
### How to run tests locally:
4+
5+
This is a guide to quickly setup the environment to run and debug tests locally on a kind cluster.
6+
7+
There are some prerequisites before running tests locally. It includes installing required tools and environment configurations.
8+
9+
## Tools & Utilities
10+
11+
It is recommended to install latest and stable version of these tools. All tools must be on path.
12+
| Tool | Purpose | Installation |
13+
|--|--|--|
14+
| Docker | Containers runtime environment | `https://docs.docker.com/get-docker` |
15+
| Kind | Running local Kubernetes cluster | `https://kind.sigs.k8s.io/docs/user/quick-start#installation` |
16+
|Kubectl|Kubernetes command-line tool| `https://kubernetes.io/docs/tasks/tools/install-kubectl-linux` |
17+
| Playwright | a framework for Web Testing and Automation | `https://playwright.dev/docs/intro#installing-playwright`|
18+
| flux | Command-line interface to bootstrap and interact with Flux | `https://fluxcd.io/docs/installation/#install-the-flux-cli`|
19+
| Playwright chromium browser | a browser binary which playwright needs to operate and run tests | After installing Playwright run `playwright install chromium`<br> you can also check this page for more info. <br> `ghttps://playwright.dev/docs/browsers`
20+
| Pytest | a testing framework that allows users to write test codes using Python programming language. | `https://docs.pytest.org/en/7.1.x/getting-started.html` |
21+
| pytest-reporter-html1 | A basic HTML report for pytest using Jinja2 template engine. | `https://pypi.org/project/pytest-reporter-html1/` |
22+
23+
## Environment Setup
24+
1. Clone the repo<br/>
25+
```bash
26+
git clone [email protected]:weaveworks/playwright-tests.git
27+
```
28+
29+
2. Open it in any IDE like **PyCharm** or **VS Code**<p>&nbsp;</p>
30+
31+
3. Launch **Docker Desktop** , for help check this URL [https://docs.docker.com/desktop/install/ubuntu/#launch-docker-desktop](https://docs.docker.com/desktop/install/ubuntu/#launch-docker-desktop) <p>&nbsp;</p>
32+
33+
4. Delete any existing kind cluster(s).
34+
```bash
35+
kind delete clusters --all
36+
```
37+
38+
5. Create a new clean kind cluster.
39+
```bash
40+
./utils/scripts/mgmt-cluster-setup.sh kind $(pwd) playwright-mgmt-kind
41+
```
42+
43+
6. Make sure that the cluster has been created.
44+
```bash
45+
kind get clusters
46+
```
47+
48+
7. Setup core and enterprise controllers.
49+
```bash
50+
kubectl create namespace flux-system
51+
flux install
52+
kubectl create secret generic git-provider-credentials -n flux-system --from-literal=username="$GITHUB_USER" --from-literal=password="$GITHUB_TOKEN"
53+
sed -i 's/BRANCH_NAME/${{ steps.extract_branch.outputs.branch_name }}/' ./utils/scripts/resources/flux-system-gitrepo.yaml
54+
./utils/scripts/wego-enterprise.sh setup ./utils/scripts
55+
```
56+
57+
8. Install violating-app.
58+
```bash
59+
kubectl apply -f ./utils/data/violating-podinfo-kustomization.yaml
60+
```
61+
62+
9. Install policies.
63+
```bash
64+
kubectl apply -f ./utils/data/policies.yaml
65+
```
66+
67+
10. Flux reconcile violating app.
68+
```bash
69+
flux reconcile kustomization violating-podinfo -n default --with-source || true
70+
kubectl get pods -A
71+
```
72+
73+
11. Install gitopsset.
74+
```bash
75+
kubectl apply -f ./utils/data/gitops-sets-kustomization.yaml
76+
```
77+
78+
## Run Tests
79+
80+
`export URL="http://localhost:8000"`
81+
82+
`export USER_NAME=""` -------> you can get it from [./utils/scripts/resources/cluster-user-auth.yaml](./utils/scripts/resources/cluster-user-auth.yaml)
83+
84+
`export PASSWORD=""` --------> you can get it from [./utils/scripts/resources/cluster-user-auth.yaml](./utils/scripts/resources/cluster-user-auth.yaml)
85+
86+
`export PYTHONPATH=./`
87+
88+
`pytest -s -v --template=html1/index.html --report=test-results/report.html`
89+
90+
## Check the test run report
91+
After running the tests using GitHub Actions, just open the **workflow Summary** page and you will see :
92+
1. a section called **Tests** which contains a table has **Total** number of run tests, many tests with status **Passed**, how many tests with status **Failed** and how many **Skipped** tests.
93+
2. In case there are **Failed** tests you will see in the **failed** section the names of the failed tests with detailed error messages for each test.
94+
95+
## Test Artifacts
96+
It is just a compressed folder produced during runtime,all you need just open the **workflow Summary** page and download it to your machine and extract it then you will find that it contains **3** reports :
97+
1. **test-run-report.html** which is an HTML report displays a graph for **Total** number of running test cases, how many **Passed** tests and how many **Failed** in addition to a List of the **executed tests** by **name** and the **status** for each one. **To open it just double-click**.This is how it looks like :point_down:
98+
99+
![screencapture-file-home-taghreed-Desktop-report-html-2023-11-21-16_45_44](https://github.com/weaveworks/playwright-tests/assets/44777049/7d882812-c7c3-4390-9df9-a6ea74943a37)
100+
101+
2. **junit_test_report.xml** which is an XML report displays a List of the **executed tests** by **name** and the **status** for each one in addition to the **Failure errors** for the **Failed** tests. **To open it just double-click**.
102+
103+
3. **execution-tracing.zip** which is a compressed folder contains **recorded Playwright traces** after the tests have been run. Traces are a great way for **debugging your tests when they fail on CI**. You can **open traces locally or in your browser on** [trace.playwright.dev](https://trace.playwright.dev/).This is how it looks like :point_down:
104+
105+
![trace viewer](https://github.com/weaveworks/playwright-tests/assets/44777049/dd374fc9-f7d8-4ea1-b1c7-0360822010b6)
106+
107+
**For more information about Playwright Trace Viewer check this URL (https://playwright.dev/docs/trace-viewer)**
108+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: violating-podinfo
5+
namespace: default
6+
spec:
7+
minReadySeconds: 3
8+
revisionHistoryLimit: 5
9+
progressDeadlineSeconds: 60
10+
strategy:
11+
rollingUpdate:
12+
maxUnavailable: 0
13+
type: RollingUpdate
14+
selector:
15+
matchLabels:
16+
app: violating-podinfo
17+
template:
18+
metadata:
19+
annotations:
20+
prometheus.io/scrape: "true"
21+
prometheus.io/port: "9797"
22+
labels:
23+
app: violating-podinfo
24+
spec:
25+
containers:
26+
- name: violating-podinfo
27+
imagePullPolicy: Always
28+
image: ghcr.io/stefanprodan/podinfo:latest
29+
securityContext:
30+
allowPrivilegeEscalation: true
31+
ports:
32+
- name: http
33+
containerPort: 9898
34+
protocol: TCP
35+
- name: http-metrics
36+
containerPort: 9797
37+
protocol: TCP
38+
- name: grpc
39+
containerPort: 9999
40+
protocol: TCP
41+
command:
42+
- ./podinfo
43+
- --port=9898
44+
- --port-metrics=9797
45+
- --grpc-port=9999
46+
- --grpc-service-name=podinfo
47+
- --level=info
48+
- --random-delay=false
49+
- --random-error=false
50+
env:
51+
- name: PODINFO_UI_COLOR
52+
value: "#34577c"
53+
livenessProbe:
54+
exec:
55+
command:
56+
- podcli
57+
- check
58+
- http
59+
- localhost:9898/healthz
60+
initialDelaySeconds: 5
61+
timeoutSeconds: 5
62+
readinessProbe:
63+
exec:
64+
command:
65+
- podcli
66+
- check
67+
- http
68+
- localhost:9898/readyz
69+
initialDelaySeconds: 5
70+
timeoutSeconds: 5
71+
resources:
72+
limits:
73+
cpu: 2000m
74+
memory: 512Mi
75+
requests:
76+
cpu: 100m
77+
memory: 64Mi

0 commit comments

Comments
 (0)