Running Playwright tests in openQA » History » Version 1
rainerkoenig, 2023-06-29 09:37
First draft
1 | 1 | rainerkoenig | # Running Playwright tests in openQA |
---|---|---|---|
2 | |||
3 | **Note:** At the time of writing this we're still experementing with an Agama Live-CD, so things might change over time. |
||
4 | |||
5 | # Building blocks |
||
6 | |||
7 | ## e2e-agama-playwright repo on GitHub |
||
8 | |||
9 | The [e2e-agama-playwright repo](https://github.com/jknphy/e2e-agama-playwright) was created by Joaquin and is supposed to be the repository that provides the Playwright tests. |
||
10 | |||
11 | ## yupdate |
||
12 | |||
13 | This is a script provided with the Agama Live-CD. The main purpose (at least for the Yam squad) is to provide a method of updating the playwright code in the Live-CD which is located under `/usr/share/agama-playwright`. For this use case we use `yupdate patch <github_repo> <branch>` which uses the branch on GitHub to update the Playwright and agama configuration. |
||
14 | |||
15 | ## Integration of yupdate into openQA |
||
16 | |||
17 | [PR 17228](https://github.com/os-autoinst/os-autoinst-distri-opensuse/pull/17228/) implements test modules to call `yupdate` from inside openQA. |
||
18 | The test module is stored under `yam/agama/patch_agama.pm` and uses a setting `YUPDATE_GIT` which is describred as follow: |
||
19 | ~~~ |
||
20 | YUPDATE_GIT | string | | Github link used by yast help script yupdate, format is repo#branch such as yast/agama#main. |
||
21 | ~~~ |
||
22 | |||
23 | ## Test module agama_installation |
||
24 | |||
25 | There is a test module `yam/agama/agama-installation` that has the purpose to run the installation. For that it uses the following code: |
||
26 | |||
27 | ~~~ |
||
28 | assert_script_run('RUN_INSTALLATION=1 playwright test --trace on --project chromium --config /usr/share/agama-playwright take_screenshots', timeout => 600); |
||
29 | ~~~ |
||
30 | |||
31 | The `take_screenshots` test for Playwright has some specialties that we need to know: |
||
32 | ~~~ |
||
33 | // check for multiple texts in parallel, avoid waiting for timeouts |
||
34 | let action = await Promise.any([ |
||
35 | page.getByText("Product selection").waitFor().then(() => actions.setProduct), |
||
36 | page.getByText("None authentication method").waitFor().then(() => actions.setPassword), |
||
37 | page.getByText("Root authentication set").waitFor().then(() => actions.done), |
||
38 | ]); |
||
39 | |||
40 | // optional product selection |
||
41 | if (action === actions.setProduct) { |
||
42 | await test.step("Select the product", async () => { |
||
43 | // select openSUSE Tumbleweed |
||
44 | await page.getByText("openSUSE Tumbleweed").click(); |
||
45 | await page.screenshot({ path: "screenshots/product-selection.png" }); |
||
46 | await page.getByRole("button", { name: "Select" }).click(); |
||
47 | }); |
||
48 | ~~~ |
||
49 | This means the test is able to determine if we're still on the product selection page and then select Tumbleweed. |
||
50 | |||
51 | ~~~ |
||
52 | if (process.env.RUN_INSTALLATION === "1") { |
||
53 | await test.step("Run installation", async () => { |
||
54 | // start the installation |
||
55 | await page.getByRole("button", { name: "Install", exact: true }).click(); |
||
56 | await expect(page.getByText("Confirm Installation")).toBeVisible(); |
||
57 | await page.getByRole("button", { name: "Continue" }).click(); |
||
58 | ~~~ |
||
59 | Here we check if we run the test with `RUN_INSTALLATION=1` (as our openQA test module `agama_installation` does, so then we launch the installation by making Playwright click on the install button. |
||
60 | |||
61 | **Keep that in mind if your adapted installation test module will call another Playwright test!** |
||
62 | |||
63 | # Experiments made so far |