Project

General

Profile

Running Playwright tests in openQA » History » Version 2

rainerkoenig, 2023-06-29 10:03

1 1 rainerkoenig
# Running Playwright tests in openQA
2
3 2 rainerkoenig
**Note:** At the time of writing (2023-06-29) this we're still experementing with an Agama Live-CD, so things might change over time.
4 1 rainerkoenig
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
64 2 rainerkoenig
65
## Clean tumbleweed installation
66
67
[Test 3267958](https://openqa.opensuse.org/tests/3267958) on O3 executes a clean Tumbleweed installation using what is in the `e2e-agama-playwright` repo without updating it. The test run is still `take screenshots`.
68
69
## Install tumbleweed after yupdate
70
71
[Test 3374624](https://openqa.opensuse.org/tests/3374624) attempts a Tumbleweed installation, but Playwright reports the error, that there is no install button and the `click()` method runs into a timeout. The test makes use of `yupdate` by using the `patch_agama` test module, but in fact there shouldn't be updates since `YUPDATE_GIT` is still set to `jknphy/e2e-agama-playwright#main`. ** This needs to be investigated further**, differences to the above clean installation that worked:
72
* we now use the Agama-Live CD from staging, version "agama-2.1-staging". 
73
74
## Install tumbleweed with LVM settings
75
76
[Test 3370827](https://openqa.opensuse.org/tests/3370827) by Lemon does a Tumbleweed installation with a specific `lvm` Playwright test module.
77
For this the `agama_installation` test module got tweaked and uses a direct run of `yupdate` instead of using the `patch_agama` test module in the YAML schedule:
78
~~~
79
assert_script_run("yupdate patch lemon-suse/e2e-agama-playwright add-lvm-installation", timeout => 300);
80
~~~
81
82
# Open questions so far
83
84
## Page Object Model
85
86
Both Lemon and Rainer have made Playwright tests with POM. Lemon places the `pages` directory inside the root of his repo, Rainer has stored it under `tests/`. Which place shall we use to have a common understanding?
87
88
## What is the long term approach?
89
90
On the experiments above we practically launch exactly **one** Playwright test to do an installation. On the other hand wie have tickets that say "Implement XYZ using Page Object Model". So in the long run we should have pages and tests that e.g configure LVM or setup disk encrpytion, but we are lacking of a sort of "Playwright scheduler" that could make use of this in a similar way as we now use the diffeent pages to configure settings from the YaST installation overview when we run install tests in openQA. Shall we provide individual 'agama_installation_xzy' test modules where 'xyz' stands for a combination of different options or shall we think of a method to e.g. submit a YAML file that tells the "Playwright scheduler" to execute the tests in a defined order and then do the installation?