summaryrefslogtreecommitdiffstats
path: root/remote/doc/marionette/SeleniumAtoms.md
blob: be65cb315e68b60896e4ebba1f497354977c5466 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Selenium atoms

Marionette uses a small list of [Selenium atoms] to interact with
web elements.  Initially those have been added to ensure a better
reliability due to a wider usage inside the Selenium project. But
by adding full support for the [WebDriver specification] they will
be removed step by step.

Currently the following atoms are in use:

- `getElementText`
- `isElementDisplayed`

To use one of those atoms Javascript modules will have to import
[atom.sys.mjs].

[Selenium atoms]: https://github.com/SeleniumHQ/selenium/tree/master/javascript/webdriver/atoms
[WebDriver specification]: https://w3c.github.io/webdriver/webdriver-spec.html
[atom.sys.mjs]: https://searchfox.org/mozilla-central/source/remote/marionette/atom.sys.mjs

## Update required Selenium atoms

In regular intervals the atoms, which are still in use, have to
be updated.  Therefore they have to be exported from the Selenium
repository first, and then updated in [atom.sys.mjs].

### Export Selenium Atoms

The canonical GitHub repository for Selenium is

  <https://github.com/SeleniumHQ/selenium.git>

so make sure to have an up-to-date local copy of it. If you have to clone
it first, it is recommended to specify the `--depth=1` argument, so only the
last changeset is getting downloaded (which itself might already be
more than 100 MB).

```bash
git clone --depth=1 https://github.com/SeleniumHQ/selenium.git
```

To export the correct version of the atoms identify the changeset id (SHA1) of
the Selenium repository in the [index section] of the WebDriver specification.

Fetch that changeset and check it out:

```bash
git fetch --depth=1 origin SHA1
git checkout SHA1
```

Now you can export all the required atoms by running the following
commands. Make sure to [install bazelisk] first.

```bash
bazel build //javascript/atoms/fragments:get-text
bazel build //javascript/atoms/fragments:is-displayed
```

For each of the exported atoms a file can now be found in the folder
`bazel-bin/javascript/atoms/fragments/`.  They contain all the
code including dependencies for the atom wrapped into a single function.

[index section]: <https://w3c.github.io/webdriver/#index>
[install bazelisk]: <https://github.com/bazelbuild/bazelisk#installation>

### Update atom.sys.mjs

To update the atoms for Marionette the `atoms.js` file has to be edited. For
each atom to be updated the steps as laid out below have to be performed:

1. Open the Javascript file of the exported atom. See above for
   its location.

2. Add the related function name and `element` as parameters to the wrapper
   function, which can be found at the very beginning of the file so that it
   is equal to the parameters in `atom.sys.mjs`.

3. Copy and paste the whole contents of the file into the left textarea on
   <https://jsonformatter.org/json-stringify-online> to get a stringified
   version of all the required functions.

4. Copy and paste the whole contents of the right textarea, and replace the
   existing code for the atom in `atom.sys.mjs`.

### Test the changes

To ensure that the update of the atoms doesn't cause a regression
a try build should be run including Marionette unit tests, Firefox
ui tests, and all the web-platform-tests.