craftdriver 1.1.0 → 1.2.0

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.
Files changed (68) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +1 -1
  3. package/dist/cli/snapshot.js +31 -4
  4. package/dist/cli/snapshot.js.map +1 -1
  5. package/dist/lib/bidi/index.d.ts +4 -5
  6. package/dist/lib/bidi/index.d.ts.map +1 -1
  7. package/dist/lib/bidi/index.js +18 -8
  8. package/dist/lib/bidi/index.js.map +1 -1
  9. package/dist/lib/bidi/logs.d.ts +12 -1
  10. package/dist/lib/bidi/logs.d.ts.map +1 -1
  11. package/dist/lib/bidi/logs.js +20 -8
  12. package/dist/lib/bidi/logs.js.map +1 -1
  13. package/dist/lib/browser.d.ts +6 -9
  14. package/dist/lib/browser.d.ts.map +1 -1
  15. package/dist/lib/browser.js +6 -4
  16. package/dist/lib/browser.js.map +1 -1
  17. package/dist/lib/by.d.ts +18 -0
  18. package/dist/lib/by.d.ts.map +1 -1
  19. package/dist/lib/by.js +141 -17
  20. package/dist/lib/by.js.map +1 -1
  21. package/dist/lib/locator.d.ts +28 -0
  22. package/dist/lib/locator.d.ts.map +1 -1
  23. package/dist/lib/locator.js +28 -0
  24. package/dist/lib/locator.js.map +1 -1
  25. package/docs/browser-api.md +4 -2
  26. package/docs/browser-logs.md +8 -23
  27. package/docs/public/examples/a11y.html +44 -0
  28. package/docs/public/examples/clock.html +83 -0
  29. package/docs/public/examples/console-errors.html +344 -0
  30. package/docs/public/examples/dialogs.html +42 -0
  31. package/docs/public/examples/download.html +31 -0
  32. package/docs/public/examples/dynamic.html +131 -0
  33. package/docs/public/examples/emulate.html +127 -0
  34. package/docs/public/examples/evaluate.html +28 -0
  35. package/docs/public/examples/hover-select.html +295 -0
  36. package/docs/public/examples/iframe-child.html +51 -0
  37. package/docs/public/examples/iframes.html +35 -0
  38. package/docs/public/examples/keyboard.html +195 -0
  39. package/docs/public/examples/locator.html +131 -0
  40. package/docs/public/examples/login.html +116 -0
  41. package/docs/public/examples/mobile.html +270 -0
  42. package/docs/public/examples/mouse.html +505 -0
  43. package/docs/public/examples/network.html +293 -0
  44. package/docs/public/examples/popup-target.html +26 -0
  45. package/docs/public/examples/popup.html +50 -0
  46. package/docs/public/examples/screenshot.html +99 -0
  47. package/docs/public/examples/selectors.html +150 -0
  48. package/docs/public/examples/session.html +514 -0
  49. package/docs/public/examples/upload.html +36 -0
  50. package/docs/recipes/accessibility-gate.md +24 -40
  51. package/docs/recipes/console-error-gate.md +27 -39
  52. package/docs/recipes/file-upload-download.md +24 -44
  53. package/docs/recipes/find-elements.md +142 -0
  54. package/docs/recipes/login-once-reuse-session.md +22 -45
  55. package/docs/recipes/mobile-flow-with-network-and-logs.md +22 -41
  56. package/docs/recipes/mock-api-and-assert-network.md +22 -35
  57. package/docs/recipes/multi-user-contexts.md +32 -43
  58. package/docs/recipes/page-objects.md +52 -0
  59. package/docs/recipes/trace-failing-test.md +31 -44
  60. package/docs/recipes/virtual-clock-time-sensitive-ui.md +24 -40
  61. package/docs/recipes/vitest-browser-lifecycle.md +15 -15
  62. package/docs/recipes.md +20 -1
  63. package/docs/selectors.md +291 -229
  64. package/docs/tracing.md +2 -2
  65. package/package.json +5 -1
  66. package/skills/craftdriver/SKILL.md +3 -2
  67. package/skills/craftdriver/cheatsheet.md +2 -1
  68. package/skills/craftdriver/patterns.md +2 -5
package/docs/tracing.md CHANGED
@@ -14,7 +14,7 @@ process crash cannot lose the evidence that led up to it.
14
14
  ```ts
15
15
  import { chromium } from 'craftdriver';
16
16
 
17
- const browser = await chromium.launch({ enableBiDi: true });
17
+ const browser = await chromium.launch();
18
18
 
19
19
  await browser.startTrace({ outDir: './artefacts/login' });
20
20
  try {
@@ -202,7 +202,7 @@ import { autoTrace } from './auto-trace';
202
202
 
203
203
  describe('Login', () => {
204
204
  let browser: Browser;
205
- beforeAll(async () => { browser = await Browser.launch({ enableBiDi: true }); });
205
+ beforeAll(async () => { browser = await Browser.launch(); });
206
206
  afterAll(async () => { await browser.quit(); });
207
207
 
208
208
  autoTrace(() => browser); // ← that's it
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "craftdriver",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Modern WebDriver automation library for NodeJS",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -17,14 +17,18 @@
17
17
  "test:firefox": "BROWSER_NAME=firefox HEADLESS=true vitest run --maxWorkers=2",
18
18
  "test:chrome": "BROWSER_NAME=chrome vitest run",
19
19
  "test:chromium": "BROWSER_NAME=chromium vitest run",
20
+ "test:recipes": "HEADLESS=true vitest run --config vitest.recipes.config.ts",
20
21
  "bench": "HEADLESS=true vitest run --config vitest.perf.config.ts",
21
22
  "bench:realapp": "HEADLESS=true vitest run --config vitest.perf.realapp.config.ts",
22
23
  "clean": "rimraf dist",
23
24
  "serve": "http-server ./examples -a 127.0.0.1 -p 8080 -c-1 --cors",
24
25
  "examples:start": "npm run serve",
26
+ "docs:examples": "node scripts/copy-examples.mjs",
25
27
  "docs:api": "node scripts/gen-api-reference.mjs",
26
28
  "docs:api:check": "node scripts/gen-api-reference.mjs --check",
29
+ "predocs:dev": "npm run docs:examples",
27
30
  "docs:dev": "vitepress dev docs",
31
+ "predocs:build": "npm run docs:examples",
28
32
  "docs:build": "vitepress build docs",
29
33
  "docs:preview": "vitepress preview docs",
30
34
  "docs:check": "npm run docs:api:check && npm run docs:build",
@@ -34,8 +34,9 @@ break the moment markup shifts.
34
34
  3. `instanceof CraftdriverError` is true on every public throw;
35
35
  `instanceof Error` is also true.
36
36
  4. BiDi features (`network`, `logs`, tracing, init scripts, true load
37
- events) require `Browser.launch({ enableBiDi: true })`. The error
38
- code on the wrong transport is `UNSUPPORTED`.
37
+ events) work out of the box — `enableBiDi` defaults to `true`. They only
38
+ break if you explicitly pass `enableBiDi: false`; the error code on the
39
+ wrong transport is `UNSUPPORTED`.
39
40
  5. Tests fetch from the example server. Start it in a separate
40
41
  terminal: `npm run examples:start` before `npm test`.
41
42
 
@@ -12,7 +12,8 @@ import { Browser } from 'craftdriver';
12
12
  const browser = await Browser.launch({
13
13
  browserName: 'chrome', // 'chrome' | 'chromium' | 'firefox'
14
14
  headless: true,
15
- enableBiDi: true, // required for network / logs / tracing / init scripts
15
+ // enableBiDi defaults to true network / logs / tracing / init scripts
16
+ // all need it, so only set enableBiDi: false if you must disable it.
16
17
  });
17
18
  try {
18
19
  await browser.navigateTo('https://example.com');
@@ -6,7 +6,7 @@ Worked recipes. Each is ≤ ~200 tokens; load on demand from
6
6
  ## 1. Login, save storage state for reuse
7
7
 
8
8
  ```ts
9
- const browser = await Browser.launch({ enableBiDi: true });
9
+ const browser = await Browser.launch();
10
10
  await browser.navigateTo('https://app.example.com/login');
11
11
  await browser.locator(By.labelText('Email')).fill('jane@example.com');
12
12
  await browser.locator(By.labelText('Password')).fill(process.env.PW!);
@@ -23,10 +23,7 @@ await browser.quit();
23
23
 
24
24
  ```ts
25
25
  const state = JSON.parse(await fs.readFile('.auth/state.json', 'utf8'));
26
- const browser = await Browser.launch({
27
- enableBiDi: true,
28
- storageState: state,
29
- });
26
+ const browser = await Browser.launch({ storageState: state });
30
27
  await browser.navigateTo('https://app.example.com/dashboard');
31
28
  await browser.locator(By.testId('dashboard')).expect().toBeVisible();
32
29
  ```