Skip to content

Commit 18e1cd9

Browse files
committed
dev: add screenshot tooling (alpha)
1 parent a63ded3 commit 18e1cd9

File tree

7 files changed

+851
-0
lines changed

7 files changed

+851
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ npm-debug.log*
2121
yarn-debug.log*
2222
yarn-error.log*
2323
/blog
24+
25+
# dotenv files
26+
.env
27+
28+
# tools
29+
.venv
30+
*.pyc

tools/screenshots-python/README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Screenshot generation
2+
3+
**Note** These instructions and tools are still in development/refinement so there are a lot of hacks and manual timing (e.g. sleeps) is used.
4+
5+
The screenshot tool uses [playwright](https://playwright.dev/python/) to automate the task of taking screenshots in a consistent manner.
6+
7+
Since pytest is used as the runner (as this is the when using playwright with python), all of tasks are defined as "tests" although it is not actually testing anything.
8+
9+
## Goals
10+
11+
The goals of the screenshot tool is to:
12+
13+
* Normalize the screenshots (similar screen sizing, consistent cropping)
14+
* Automate most of the tedious tasks (though the automation will likely break from time to time if the UI changes significantly)
15+
* Prevent leaking personal information when taking the screenshot (e.g. type of browser, browser extensions installed, exact URL etc.)
16+
* Use semi-automation for the more complicated screenshots when automation is too costly/fragile (automate spawning a new windows, navigating to the correct page and then let the user manually do the rest)
17+
18+
**Potential future goals**
19+
20+
The following goals are being considered (pending on technical difficulty / quality of the output)
21+
22+
* Use the tasks to also record videos of each feature (this already sort of works, but the video quality is lacking)
23+
24+
## Pre-requisites
25+
26+
The following tools are required:
27+
28+
* python3 (>=3.9)
29+
* [go-c8y-cli](https://goc8ycli.netlify.app/) to handle authentication
30+
* [c8y-tedge](https://github.com/thin-edge/c8y-tedge) (go-c8y-cli extension for thin-edge.io)
31+
* Valid Cumulocity go-c8y-cli session which uses a TOKEN for authentication (currently basic auth is not supported)
32+
33+
Some screenshots require a device, therefore you will need to have at setup two types of devices and connect them to your Cumulocity tenant. The following types of devices are used, where the user can specify the name of each type of device that can then be used to take the screenshots of:
34+
35+
* A real device (ideally a device which is using a Yocto built image from [meta-tedge](https://github.com/thin-edge/meta-tedge/actions/workflows/build.yaml))
36+
37+
* A demo device - You can start a demo device using
38+
39+
```sh
40+
c8y tedge demo start tedge_6c6687b0
41+
```
42+
43+
Once you have these devices, and pre-requisites, then you can proceed to the getting started section.
44+
45+
## Getting Started
46+
47+
Note: The screenshots will be written to symlinked folder of the "next" docs which is referenced under `<project_dir>/docs/...`
48+
49+
1. Install dependencies
50+
51+
```sh
52+
just setup
53+
```
54+
55+
1. Activate the python virtual environment created in the previous step
56+
57+
```sh
58+
. .venv/bin/activate
59+
```
60+
61+
1. Activate your go-c8y-cli session for the tenant you want to
62+
63+
```sh
64+
set-session
65+
```
66+
67+
1. Configure which device names you want to include in your screenshot by editing the `.env` file that was created in step 1
68+
69+
```sh
70+
DEMO_DEVICE=tedge_6c6687b0
71+
REAL_DEVICE=rpi4-d83add90fe56
72+
```
73+
74+
**Note**: The device's must exist in the tenant before taking the screenshots. go-c8y-cli is used to resolve the device name to the managed object id which is used in the API calls.
75+
76+
1. Run the tasks to create the screenshots
77+
78+
**Generate all screenshots**
79+
80+
```sh
81+
just take-screenshots
82+
```
83+
84+
**Generate screenshots**
85+
86+
```sh
87+
just take-screenshots-for "test_getting_started_page"
88+
```
89+
90+
**Run specific task in debug mode**
91+
92+
```sh
93+
just debug "test_getting_started_page"
94+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dummy
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "custom_devmgmt",
3+
"type": "c8y_SmartRest2Template",
4+
"com_cumulocity_model_smartrest_csv_CsvSmartRestTemplate": {
5+
"requestTemplates": [],
6+
"responseTemplates": [
7+
{
8+
"msgId": "dm101",
9+
"condition": "set_wifi",
10+
"base": "set_wifi",
11+
"name": "set_wifi",
12+
"pattern": [
13+
"name",
14+
"ssid",
15+
"type"
16+
]
17+
}
18+
]
19+
},
20+
"__externalId": "custom_devmgmt"
21+
}

tools/screenshots-python/justfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
set dotenv-load
2+
3+
# Setup tooling
4+
setup:
5+
just init-env
6+
just venv
7+
8+
# Init. the dotenv file with some default values
9+
init-env:
10+
[ ! -f .env ] && echo "DEMO_DEVICE=tedge_6c6687b0\nREAL_DEVICE=rpi4-d83add90fe56" > .env
11+
12+
# Install python virtual environment
13+
venv:
14+
[ -d .venv ] || python3 -m venv .venv
15+
.venv/bin/pip3 install -r requirements.txt
16+
.venv/bin/playwright install
17+
18+
19+
# Take all screenshots
20+
take-screenshots *ARGS:
21+
.venv/bin/pytest {{ARGS}}
22+
23+
# Take screenshots for the tests/tasks matching the expression
24+
take-screenshots-for expression *ARGS:
25+
.venv/bin/pytest --headed -k {{expression}} {{ARGS}}
26+
27+
# Start debug mode for the tests/tasks matching the expression
28+
debug expression *ARGS:
29+
PWDEBUG=1 .venv/bin/pytest --headed -s -k {{expression}} {{ARGS}}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pytest
2+
pytest-playwright
3+
pyjwt

0 commit comments

Comments
 (0)