|
| 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 | + ``` |
0 commit comments