create-wdio 10.0.0-alpha.149 → 10.0.0-alpha.155
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/templates/wdio-session/SKILL.md +33 -52
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-wdio",
|
|
3
|
-
"version": "10.0.0-alpha.
|
|
3
|
+
"version": "10.0.0-alpha.155+ecb67813a",
|
|
4
4
|
"description": "Install and setup a WebdriverIO project with all its dependencies in a single run",
|
|
5
5
|
"author": "WebdriverIO Team <mail@webdriver.io>",
|
|
6
6
|
"homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/create-wdio",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"publishConfig": {
|
|
77
77
|
"access": "public"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "ecb67813a570e35a3b92a72212af2d0ba5c7410c"
|
|
80
80
|
}
|
|
@@ -5,60 +5,55 @@ description: Drive browsers, mobile apps and desktop apps with WebdriverIO from
|
|
|
5
5
|
|
|
6
6
|
# wdio session
|
|
7
7
|
|
|
8
|
-
`wdio session` keeps
|
|
8
|
+
`wdio session` keeps one WebdriverIO session alive between short shell commands. Use it to see or drive a real browser, mobile app, or desktop app, check a change, and turn the steps that worked into a test. Use `curl` or `fetch` instead when the question is only about an HTTP API.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
## 1. Discover commands with `--help`
|
|
13
|
-
|
|
14
|
-
This file covers the core loop only. The CLI documents itself, and its help always matches the installed version:
|
|
10
|
+
## The loop
|
|
15
11
|
|
|
16
12
|
```sh
|
|
17
|
-
npx wdio session
|
|
18
|
-
npx wdio session
|
|
13
|
+
npx wdio session open chrome https://example.com
|
|
14
|
+
npx wdio session click e3
|
|
15
|
+
npx wdio session fill e5 Ada Lovelace && npx wdio session select e6 Pro && npx wdio session check e7 && npx wdio session click e8
|
|
16
|
+
npx wdio session get text e9
|
|
19
17
|
```
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
- **Open once.** Browsers run headless. `open` prints the page's interactive elements, so you can act right away. It also takes `firefox`, `edge`, `safari`, `android`, `ios`, `electron <app>` and more.
|
|
20
|
+
- **Act on refs.** Elements show up as `button "Add to cart" [ref=e3]`. Refs stay valid while the element exists.
|
|
21
|
+
- **Every action reports what changed:** new or changed lines with their refs (`+ status "Saved"`), or the new page's elements after a navigation. You rarely need a separate `snapshot`.
|
|
22
|
+
- **Chain steps with `&&`.** One shell call for several steps is faster, and a failing step stops the chain.
|
|
23
|
+
- **Big page?** `find <text>` prints only the matching part of the page, with refs. `snapshot` without `-i` also shows text.
|
|
24
|
+
- **No need to close.** The session shuts itself down when idle. Run `close` only to start over.
|
|
22
25
|
|
|
23
|
-
##
|
|
26
|
+
## Actions
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
| Action | Example |
|
|
29
|
+
| --- | --- |
|
|
30
|
+
| Look | `snapshot -i` (interactive only) · `snapshot` (with text) · `find "Add to cart"` · `screenshot` |
|
|
31
|
+
| Click | `click e3` · `click e3 --double` · `hover e3` |
|
|
32
|
+
| Text | `fill e2 Ada Lovelace` (replaces) · `type e2 more` (appends) · `press Enter` |
|
|
33
|
+
| Forms | `select e4 Pro` · `check e5` · `uncheck e5` · `upload e6 ./file.pdf` |
|
|
34
|
+
| Read | `get text e9` · `get value e2` · `get url` · `get title` · `is visible e3` |
|
|
35
|
+
| Wait | `wait e3` · `wait --text "Saved"` · `wait --url /done` · `wait --load networkidle` |
|
|
36
|
+
| Navigate | `navigate https://…` · `back` · `reload` · `tabs` · `tabs switch 1` |
|
|
37
|
+
| Frames | `frame e1` (into the iframe e1) · `frame top` |
|
|
38
|
+
| Code | `exec -e 'console.log(await $("h1").getText())'` |
|
|
32
39
|
|
|
33
|
-
|
|
34
|
-
- **Observe before acting.** `snapshot -i` lists interactive elements with refs like `button "Add to cart" [ref=e3]`. Use `find <text>` on large pages. Take a screenshot only when the question is about layout.
|
|
35
|
-
- **Act on refs.** Refs stay valid while the element exists. After navigation, take a fresh snapshot.
|
|
36
|
-
- **Chain steps with `&&`.** One shell call per act-wait-observe step is faster than separate calls, and a failing step stops the chain.
|
|
37
|
-
- **Wait for a condition, not a time.** Use `wait <ref>`, `wait --text`, `wait --url` or `wait --load networkidle` instead of `sleep`.
|
|
38
|
-
- **Read before you assert.** `get text e1`, `get url` and `is visible e1` print values. Put assertions in `exec`.
|
|
40
|
+
Run `npx wdio session <action> --help` only when an action fails or you need a flag that isn't shown here.
|
|
39
41
|
|
|
40
|
-
##
|
|
42
|
+
## Code
|
|
41
43
|
|
|
42
44
|
Use `exec` for loops, conditions and assertions. Pipe longer code on stdin:
|
|
43
45
|
|
|
44
46
|
```sh
|
|
45
47
|
npx wdio session exec -e 'await expect($("h1")).toHaveText("Cart")'
|
|
46
|
-
npx wdio session <<'JS'
|
|
48
|
+
npx wdio session exec <<'JS'
|
|
47
49
|
await $('aria/Sign in').click()
|
|
48
50
|
await expect(browser).toHaveUrl(expect.stringContaining('/dashboard'))
|
|
49
51
|
JS
|
|
50
52
|
```
|
|
51
53
|
|
|
52
|
-
WebdriverIO v10 rules:
|
|
53
|
-
|
|
54
|
-
- Always `await` commands.
|
|
55
|
-
- `$` returns exactly one element. More than one match throws `StrictSelectorError`. A missing element stays unresolved until a command uses it.
|
|
56
|
-
- There is no sync mode and no `browser.element`.
|
|
57
|
-
- In the shell, wrap code in single quotes so `$(…)` is not run as command substitution.
|
|
54
|
+
WebdriverIO v10 rules: always `await` commands; `$` returns exactly one element and throws `StrictSelectorError` on more than one match; wrap code in single quotes so the shell does not run `$(…)`.
|
|
58
55
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
## 4. Turn it into a test
|
|
56
|
+
## Turn it into a test
|
|
62
57
|
|
|
63
58
|
Every action prints the WebdriverIO code it ran (`→ …`). `export` writes those steps as a spec:
|
|
64
59
|
|
|
@@ -67,13 +62,9 @@ npx wdio session export --out test/specs/cart.e2e.ts
|
|
|
67
62
|
npx wdio run wdio.conf.ts --spec test/specs/cart.e2e.ts
|
|
68
63
|
```
|
|
69
64
|
|
|
70
|
-
No `wdio.conf.ts` yet?
|
|
71
|
-
|
|
72
|
-
```sh
|
|
73
|
-
npm init wdio@latest . -- --yes --typescript --framework mocha --browsers chrome --reporters spec
|
|
74
|
-
```
|
|
65
|
+
No `wdio.conf.ts` yet? `npm init wdio@latest . -- --yes --typescript --framework mocha --browsers chrome --reporters spec`
|
|
75
66
|
|
|
76
|
-
##
|
|
67
|
+
## Debug a failing test
|
|
77
68
|
|
|
78
69
|
```sh
|
|
79
70
|
npx wdio run wdio.conf.ts --debug=agent
|
|
@@ -81,16 +72,6 @@ npx wdio session -s debug-0-0 snapshot -i
|
|
|
81
72
|
npx wdio session -s debug-0-0 resume
|
|
82
73
|
```
|
|
83
74
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
## 6. Errors
|
|
87
|
-
|
|
88
|
-
| Exit | Meaning |
|
|
89
|
-
| --- | --- |
|
|
90
|
-
| 0 | Success |
|
|
91
|
-
| 1 | The action or your code failed |
|
|
92
|
-
| 2 | Usage error: check `<action> --help` |
|
|
93
|
-
| 3 | Missing dependency or credentials |
|
|
94
|
-
| 4 | No session with that name |
|
|
75
|
+
## Errors
|
|
95
76
|
|
|
96
|
-
Errors print a hint on the next line. `npx wdio session doctor` checks the machine
|
|
77
|
+
Exit codes: 1 the action or your code failed, 2 usage error, 3 missing dependency or credentials, 4 no session with that name. Errors print a hint on the next line. `npx wdio session doctor` checks the machine.
|