Skip to content

Commit

Permalink
chore: copy in playwright repo from Enterpise unmodified (#4528)
Browse files Browse the repository at this point in the history
  • Loading branch information
casibbald authored Jan 15, 2025
1 parent ea068fd commit c247fd8
Show file tree
Hide file tree
Showing 32 changed files with 3,259 additions and 0 deletions.
209 changes: 209 additions & 0 deletions .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
name: Playwright Tests

on:
push:
branches: "**"
schedule:
- cron: "30 22 * * *"
workflow_dispatch:
inputs:
chart_version:
description: 'weave gitops enterprise chart version'
required: true
type: string

env:
MANAGEMENT_CLUSTER_TYPE: "kind"
CLUSTER_NAME: run-playwright-tests-${{ github.run_id }}
USER_NAME: wego-admin
PASSWORD: ${{ secrets.CLUSTERS_CONFIG_PASSWORD }}
WEAVE_GITOPS_DEV_SOPS_KEY: ${{ secrets.WEAVE_GITOPS_DEV_SOPS_KEY }}
CLUSTER_ADMIN_PASSWORD_HASH: ${{ secrets.CLUSTERS_CONFIG_PASSWORD }}
WEAVEWORKS_BOT_TOKEN: ${{ secrets.WEAVEWORKS_BOT_TOKEN }}
ENTERPRISE_CHART_VERSION: ${{ inputs.chart_version }}
DEFAULT_ENTERPRISE_CHART_VERSION: "0.31.0-9-gdae6755"

jobs:
build_and_run_tests:

runs-on: ubuntu-latest

permissions:
id-token: write
contents: read

steps:
- uses: actions/checkout@v3
- name : Set URL environment Variable
run: |
echo "URL=http://localhost:8000" >> $GITHUB_ENV
- name: Check if the URL variable is available
run: |
echo ${{ env.URL }}
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install pytest_dotenv
pip install pytest-reporter-html1
- name: Install pre-commit
run: |
pip install pre-commit
- name: Install flux
run: |
curl -s https://fluxcd.io/install.sh | sudo bash
flux version --client
- name: Install kubectl
run: |
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
kubectl version --client
- name: Install kind
run: |
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
which kind
kind version
- name: Install playwright
run: |
pip install pytest-playwright
- name: Install chromium
run: |
playwright install chromium
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Setup management cluster
run: |
./utils/scripts/mgmt-cluster-setup.sh ${{ env.MANAGEMENT_CLUSTER_TYPE }} $(pwd) ${{ env.CLUSTER_NAME }}
- name: Extract branch name
run: |
echo "branch_name=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch

- name: Setup wego enterprise
run: |
kubectl create namespace flux-system
flux install
kubectl create secret generic git-provider-credentials -n flux-system --from-literal=username="weave-gitops-bot" --from-literal=password="${WEAVEWORKS_BOT_TOKEN}"
sed -i 's/BRANCH_NAME/${{ steps.extract_branch.outputs.branch_name }}/' ./utils/scripts/resources/flux-system-gitrepo.yaml
./utils/scripts/wego-enterprise.sh setup ./utils/scripts
- name: Install violating-app
run: |
kubectl apply -f ./utils/data/violating-podinfo-kustomization.yaml
- name: Install policies
run: |
kubectl apply -f ./utils/data/policies.yaml
- name: Flux reconcile violating app
run: |
flux reconcile kustomization violating-podinfo -n default --with-source || true
kubectl get pods -A
- name: Install gitopsset-configmaps
run: |
kubectl apply -f ./utils/data/gitops-sets-kustomization.yaml
- name: run tests
if: success()
run: |
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
- name: Generate tests report
if: always()
uses: pmeier/pytest-results-action@main
with:
path: test-results/junit_test_report.xml
summary: true
display-options: fEX
fail-on-empty: true

- name: Upload test report
uses: actions/upload-artifact@v3
if: success() || failure()
with:
name: playwright-tests-report
path: test-results/
retention-days: 3

- name: Download test artifacts
uses: actions/[email protected]
if: success() || failure()
with:
name: playwright-tests-report
path: test-results/

- name: Display structure of downloaded files
if: always()
run: ls -R
working-directory: test-results

- name: Publish test report
id: test_summary
uses: mikepenz/[email protected]
if: success() || failure()
with:
report_paths: test-results/junit_test_report.xml

- name: Notify Slack
id: slack
uses: slackapi/[email protected]
with:
channel-id: C058RPVS5DZ
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Tests result:*"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"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}}*"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*View result on Github:* ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
}
]
}
if: always()
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

- name : Delete test cluster
if: success() || failure()
run: |
kind delete clusters --all
108 changes: 108 additions & 0 deletions playwright/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Playwright Tests

### How to run tests locally:

This is a guide to quickly setup the environment to run and debug tests locally on a kind cluster.

There are some prerequisites before running tests locally. It includes installing required tools and environment configurations.

## Tools & Utilities

It is recommended to install latest and stable version of these tools. All tools must be on path.
| Tool | Purpose | Installation |
|--|--|--|
| Docker | Containers runtime environment | `https://docs.docker.com/get-docker` |
| Kind | Running local Kubernetes cluster | `https://kind.sigs.k8s.io/docs/user/quick-start#installation` |
|Kubectl|Kubernetes command-line tool| `https://kubernetes.io/docs/tasks/tools/install-kubectl-linux` |
| Playwright | a framework for Web Testing and Automation | `https://playwright.dev/docs/intro#installing-playwright`|
| flux | Command-line interface to bootstrap and interact with Flux | `https://fluxcd.io/docs/installation/#install-the-flux-cli`|
| 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`
| 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` |
| pytest-reporter-html1 | A basic HTML report for pytest using Jinja2 template engine. | `https://pypi.org/project/pytest-reporter-html1/` |

## Environment Setup
1. Clone the repo<br/>
```bash
git clone [email protected]:weaveworks/playwright-tests.git
```

2. Open it in any IDE like **PyCharm** or **VS Code**<p>&nbsp;</p>

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>

4. Delete any existing kind cluster(s).
```bash
kind delete clusters --all
```

5. Create a new clean kind cluster.
```bash
./utils/scripts/mgmt-cluster-setup.sh kind $(pwd) playwright-mgmt-kind
```

6. Make sure that the cluster has been created.
```bash
kind get clusters
```

7. Setup core and enterprise controllers.
```bash
kubectl create namespace flux-system
flux install
kubectl create secret generic git-provider-credentials -n flux-system --from-literal=username="$GITHUB_USER" --from-literal=password="$GITHUB_TOKEN"
sed -i 's/BRANCH_NAME/${{ steps.extract_branch.outputs.branch_name }}/' ./utils/scripts/resources/flux-system-gitrepo.yaml
./utils/scripts/wego-enterprise.sh setup ./utils/scripts
```

8. Install violating-app.
```bash
kubectl apply -f ./utils/data/violating-podinfo-kustomization.yaml
```

9. Install policies.
```bash
kubectl apply -f ./utils/data/policies.yaml
```

10. Flux reconcile violating app.
```bash
flux reconcile kustomization violating-podinfo -n default --with-source || true
kubectl get pods -A
```

11. Install gitopsset.
```bash
kubectl apply -f ./utils/data/gitops-sets-kustomization.yaml
```

## Run Tests

`export URL="http://localhost:8000"`

`export USER_NAME=""` -------> you can get it from [./utils/scripts/resources/cluster-user-auth.yaml](./utils/scripts/resources/cluster-user-auth.yaml)

`export PASSWORD=""` --------> you can get it from [./utils/scripts/resources/cluster-user-auth.yaml](./utils/scripts/resources/cluster-user-auth.yaml)

`export PYTHONPATH=./`

`pytest -s -v --template=html1/index.html --report=test-results/report.html`

## Check the test run report
After running the tests using GitHub Actions, just open the **workflow Summary** page and you will see :
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.
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.

## Test Artifacts
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 :
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:

![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)

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**.

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:

![trace viewer](https://github.com/weaveworks/playwright-tests/assets/44777049/dd374fc9-f7d8-4ea1-b1c7-0360822010b6)

**For more information about Playwright Trace Viewer check this URL (https://playwright.dev/docs/trace-viewer)**

77 changes: 77 additions & 0 deletions playwright/apps/violating-app/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: violating-podinfo
namespace: default
spec:
minReadySeconds: 3
revisionHistoryLimit: 5
progressDeadlineSeconds: 60
strategy:
rollingUpdate:
maxUnavailable: 0
type: RollingUpdate
selector:
matchLabels:
app: violating-podinfo
template:
metadata:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9797"
labels:
app: violating-podinfo
spec:
containers:
- name: violating-podinfo
imagePullPolicy: Always
image: ghcr.io/stefanprodan/podinfo:latest
securityContext:
allowPrivilegeEscalation: true
ports:
- name: http
containerPort: 9898
protocol: TCP
- name: http-metrics
containerPort: 9797
protocol: TCP
- name: grpc
containerPort: 9999
protocol: TCP
command:
- ./podinfo
- --port=9898
- --port-metrics=9797
- --grpc-port=9999
- --grpc-service-name=podinfo
- --level=info
- --random-delay=false
- --random-error=false
env:
- name: PODINFO_UI_COLOR
value: "#34577c"
livenessProbe:
exec:
command:
- podcli
- check
- http
- localhost:9898/healthz
initialDelaySeconds: 5
timeoutSeconds: 5
readinessProbe:
exec:
command:
- podcli
- check
- http
- localhost:9898/readyz
initialDelaySeconds: 5
timeoutSeconds: 5
resources:
limits:
cpu: 2000m
memory: 512Mi
requests:
cpu: 100m
memory: 64Mi
Loading

0 comments on commit c247fd8

Please sign in to comment.