File: webdriver.md

package info (click to toggle)
cog 0.18.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 964 kB
  • sloc: ansic: 12,941; sh: 101; makefile: 5
file content (66 lines) | stat: -rw-r--r-- 1,648 bytes parent folder | download | duplicates (3)
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
Title: WebDriver support

# WebDriver support

Cog allows remote testing through the WebDriver interface. With Selenium python
bindings, you can use the `selenium.webdriver.remote.WebDriver` class to run
the tests on the target device directly from a host computer.

## Requirements

* `cog` and `WPEWebDriver` installed on the target devices.
* Selenium python bindings on the computer with the test scripts.

## Launching the WebDriver

For example, on a meta-webkit RPi3 image:

```shell
$ export WAYLAND_DISPLAY=wayland-0
$ export XDG_RUNTIME_DIR=/run/user/0
# host=all to allow requests from other machines
$ WPEWebDriver --port=8088 --host=all
```

## Connecting to the driver

In the python script:

```python
from selenium import webdriver

def capabilities():
    return {
        "wpe:browserOptions": {
            "binary": "/usr/bin/cog",
            "args": ["--automation", "--platform=wl"],
        }
    }

driver = webdriver.Remote(
    command_executor="http://YOUR_DEVICE_IP:8088",
    desired_capabilities=capabilities(),
)
```

## Using the driver

```python
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.actions.action_builder import ActionBuilder

driver.get("https://lichess.org/analysis")
board = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.CLASS_NAME, "cg-wrap"))
)

square_size = board.size["height"] / 8
# ...
actions = ActionBuilder(driver)
pointer = actions.pointer_action
pointer.move_to(board, x, y)
pointer.click()
actions.perform()
```