testdriverai 6.2.1 → 7.0.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.
- package/.github/workflows/acceptance-linux.yml +75 -0
- package/.github/workflows/acceptance-sdk-tests.yml +133 -0
- package/.vscode/settings.json +5 -1
- package/MIGRATION.md +389 -0
- package/PLUGIN_MIGRATION.md +222 -0
- package/PROMPT_CACHE.md +200 -0
- package/SDK_LOGGING.md +222 -0
- package/SDK_MIGRATION.md +474 -0
- package/SDK_README.md +1122 -0
- package/{testdriver → _testdriver}/acceptance/drag-and-drop.yaml +2 -2
- package/{testdriver → _testdriver}/acceptance/snippets/login.yaml +1 -1
- package/_testdriver/examples/desktop/lifecycle/prerun.yaml +0 -0
- package/{testdriver → _testdriver}/examples/web/lifecycle/prerun.yaml +6 -1
- package/{testdriver → _testdriver}/lifecycle/postrun.yaml +3 -2
- package/_testdriver/lifecycle/prerun.yaml +15 -0
- package/{testdriver → _testdriver}/lifecycle/provision.yaml +7 -2
- package/agent/index.js +258 -68
- package/agent/interface.js +15 -0
- package/agent/lib/cache.js +142 -0
- package/agent/lib/commander.js +1 -39
- package/agent/lib/commands.js +143 -188
- package/agent/lib/redraw.js +6 -3
- package/agent/lib/sandbox.js +19 -5
- package/agent/lib/sdk.js +1 -0
- package/agent/lib/system.js +0 -3
- package/agent/lib/validation.js +1 -7
- package/debug-locate-response.js +82 -0
- package/debug-screenshot-1763401388589.png +0 -0
- package/debugger/index.html +16 -5
- package/docs/ARCHITECTURE.md +424 -0
- package/docs/AWESOME_LOGS_QUICK_REF.md +100 -0
- package/docs/QUICK_START_TEST_RECORDING.md +215 -0
- package/docs/SDK_AWESOME_LOGS.md +468 -0
- package/docs/TEST_RECORDING.md +388 -0
- package/docs/docs.json +232 -152
- package/docs/sdk-browser-rendering.md +167 -0
- package/docs/v6/getting-started/self-hosting.mdx +407 -0
- package/docs/{guide → v6/guide}/dashcam.mdx +1 -1
- package/docs/{guide → v6/guide}/environment-variables.mdx +4 -5
- package/docs/{guide → v6/guide}/lifecycle.mdx +1 -1
- package/docs/v6/overview/comparison.mdx +101 -0
- package/docs/v7/README.md +135 -0
- package/docs/v7/api/ai.mdx +205 -0
- package/docs/v7/api/assert.mdx +285 -0
- package/docs/v7/api/assertions.mdx +403 -0
- package/docs/v7/api/click.mdx +287 -0
- package/docs/v7/api/client.mdx +322 -0
- package/docs/v7/api/elements.mdx +479 -0
- package/docs/v7/api/exec.mdx +346 -0
- package/docs/v7/api/find.mdx +316 -0
- package/docs/v7/api/focusApplication.mdx +294 -0
- package/docs/v7/api/hover.mdx +279 -0
- package/docs/v7/api/pressKeys.mdx +349 -0
- package/docs/v7/api/sandbox.mdx +404 -0
- package/docs/v7/api/scroll.mdx +300 -0
- package/docs/v7/api/type.mdx +314 -0
- package/docs/v7/commands/assert.mdx +45 -0
- package/docs/v7/commands/exec.mdx +282 -0
- package/docs/v7/commands/focus-application.mdx +44 -0
- package/docs/v7/commands/hover-image.mdx +69 -0
- package/docs/v7/commands/hover-text.mdx +47 -0
- package/docs/v7/commands/if.mdx +53 -0
- package/docs/v7/commands/match-image.mdx +67 -0
- package/docs/v7/commands/press-keys.mdx +87 -0
- package/docs/v7/commands/remember.mdx +49 -0
- package/docs/v7/commands/run.mdx +44 -0
- package/docs/v7/commands/scroll-until-image.mdx +66 -0
- package/docs/v7/commands/scroll-until-text.mdx +60 -0
- package/docs/v7/commands/scroll.mdx +69 -0
- package/docs/v7/commands/type.mdx +45 -0
- package/docs/v7/commands/wait-for-image.mdx +54 -0
- package/docs/v7/commands/wait-for-text.mdx +48 -0
- package/docs/v7/commands/wait.mdx +45 -0
- package/docs/v7/getting-started/quickstart.mdx +199 -0
- package/docs/v7/guides/migration.mdx +562 -0
- package/docs/{getting-started → v7/guides}/self-hosting.mdx +11 -12
- package/docs/v7/playwright.mdx +342 -0
- package/eslint.config.js +19 -1
- package/examples/run-tests-with-recording.sh +70 -0
- package/examples/screenshot-example.js +63 -0
- package/examples/sdk-awesome-logs-demo.js +177 -0
- package/examples/sdk-cache-thresholds.js +96 -0
- package/examples/sdk-element-properties.js +155 -0
- package/examples/sdk-simple-example.js +65 -0
- package/examples/test-recording-example.test.js +166 -0
- package/interfaces/cli/lib/base.js +10 -4
- package/interfaces/logger.js +2 -1
- package/interfaces/shared-test-state.mjs +69 -0
- package/interfaces/vitest-plugin.mjs +744 -0
- package/mcp-server/AI_GUIDELINES.md +57 -0
- package/package.json +18 -5
- package/schema.json +8 -29
- package/scripts/view-test-results.mjs +96 -0
- package/sdk-log-formatter.js +714 -0
- package/sdk.d.ts +735 -0
- package/sdk.js +1906 -0
- package/{.github/workflows/self-hosted.yml → self-hosted.yml} +13 -4
- package/setup/aws/cloudformation.yaml +9 -2
- package/test/mcp-example-test.yaml +27 -0
- package/test-find-api.js +73 -0
- package/test-prompt-cache.js +96 -0
- package/test-sandbox-render.js +28 -0
- package/test-sdk-methods.js +15 -0
- package/test-sdk-refactor.js +53 -0
- package/test-stack-trace.mjs +57 -0
- package/testdriver/acceptance-sdk/QUICK_REFERENCE.md +61 -0
- package/testdriver/acceptance-sdk/README.md +128 -0
- package/testdriver/acceptance-sdk/TEST_REPORTING.md +245 -0
- package/testdriver/acceptance-sdk/assert.test.mjs +44 -0
- package/testdriver/acceptance-sdk/drag-and-drop.test.mjs +70 -0
- package/testdriver/acceptance-sdk/element-not-found.test.mjs +38 -0
- package/testdriver/acceptance-sdk/exec-js.test.mjs +55 -0
- package/testdriver/acceptance-sdk/exec-output.test.mjs +71 -0
- package/testdriver/acceptance-sdk/exec-pwsh.test.mjs +69 -0
- package/testdriver/acceptance-sdk/focus-window.test.mjs +48 -0
- package/testdriver/acceptance-sdk/formatted-logging.test.mjs +41 -0
- package/testdriver/acceptance-sdk/hover-image.test.mjs +43 -0
- package/testdriver/acceptance-sdk/hover-text-with-description.test.mjs +50 -0
- package/testdriver/acceptance-sdk/hover-text.test.mjs +41 -0
- package/testdriver/acceptance-sdk/match-image.test.mjs +48 -0
- package/testdriver/acceptance-sdk/press-keys.test.mjs +64 -0
- package/testdriver/acceptance-sdk/prompt.test.mjs +45 -0
- package/testdriver/acceptance-sdk/scroll-keyboard.test.mjs +52 -0
- package/testdriver/acceptance-sdk/scroll-until-image.test.mjs +51 -0
- package/testdriver/acceptance-sdk/scroll-until-text.test.mjs +42 -0
- package/testdriver/acceptance-sdk/scroll.test.mjs +50 -0
- package/testdriver/acceptance-sdk/setup/globalTeardown.mjs +11 -0
- package/testdriver/acceptance-sdk/setup/lifecycleHelpers.mjs +239 -0
- package/testdriver/acceptance-sdk/setup/testHelpers.mjs +648 -0
- package/testdriver/acceptance-sdk/setup/vitestSetup.mjs +40 -0
- package/testdriver/acceptance-sdk/type-checking-demo.js +49 -0
- package/testdriver/acceptance-sdk/type.test.mjs +84 -0
- package/verify-element-api.js +89 -0
- package/verify-types.js +0 -0
- package/vitest.config.example.js +19 -0
- package/vitest.config.mjs +65 -0
- package/vitest.config.mjs.bak +44 -0
- package/.github/workflows/acceptance-v6.yml +0 -169
- package/docs/overview/comparison.mdx +0 -82
- package/testdriver/lifecycle/prerun.yaml +0 -17
- /package/{testdriver/examples/desktop/lifecycle/prerun.yaml → .env.example} +0 -0
- /package/{testdriver → _testdriver}/acceptance/assert.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/dashcam.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/embed.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/exec-js.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/exec-output.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/exec-shell.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/focus-window.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/hover-image.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/hover-text-with-description.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/hover-text.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/if-else.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/match-image.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/press-keys.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/prompt.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/remember.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/screenshots/cart.png +0 -0
- /package/{testdriver → _testdriver}/acceptance/scroll-keyboard.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/scroll-until-image.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/scroll-until-text.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/scroll.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/snippets/match-cart.yaml +0 -0
- /package/{testdriver → _testdriver}/acceptance/type.yaml +0 -0
- /package/{testdriver → _testdriver}/behavior/failure.yaml +0 -0
- /package/{testdriver → _testdriver}/behavior/hover-text.yaml +0 -0
- /package/{testdriver → _testdriver}/behavior/lifecycle/postrun.yaml +0 -0
- /package/{testdriver → _testdriver}/behavior/lifecycle/prerun.yaml +0 -0
- /package/{testdriver → _testdriver}/behavior/lifecycle/provision.yaml +0 -0
- /package/{testdriver → _testdriver}/behavior/secrets.yaml +0 -0
- /package/{testdriver → _testdriver}/edge-cases/dashcam-chrome.yaml +0 -0
- /package/{testdriver → _testdriver}/edge-cases/exec-pwsh-multiline.yaml +0 -0
- /package/{testdriver → _testdriver}/edge-cases/js-exception.yaml +0 -0
- /package/{testdriver → _testdriver}/edge-cases/js-promise.yaml +0 -0
- /package/{testdriver → _testdriver}/edge-cases/lifecycle/postrun.yaml +0 -0
- /package/{testdriver → _testdriver}/edge-cases/prompt-in-middle.yaml +0 -0
- /package/{testdriver → _testdriver}/edge-cases/prompt-nested.yaml +0 -0
- /package/{testdriver → _testdriver}/edge-cases/success-test.yaml +0 -0
- /package/{testdriver → _testdriver}/examples/android/example.yaml +0 -0
- /package/{testdriver → _testdriver}/examples/android/lifecycle/postrun.yaml +0 -0
- /package/{testdriver → _testdriver}/examples/android/lifecycle/provision.yaml +0 -0
- /package/{testdriver → _testdriver}/examples/android/readme.md +0 -0
- /package/{testdriver → _testdriver}/examples/chrome-extension/lifecycle/provision.yaml +0 -0
- /package/{testdriver → _testdriver}/examples/desktop/lifecycle/provision.yaml +0 -0
- /package/{testdriver → _testdriver}/examples/vscode-extension/lifecycle/provision.yaml +0 -0
- /package/{testdriver → _testdriver}/examples/web/lifecycle/postrun.yaml +0 -0
- /package/docs/{account → v6/account}/dashboard.mdx +0 -0
- /package/docs/{account → v6/account}/enterprise.mdx +0 -0
- /package/docs/{account → v6/account}/pricing.mdx +0 -0
- /package/docs/{account → v6/account}/projects.mdx +0 -0
- /package/docs/{account → v6/account}/team.mdx +0 -0
- /package/docs/{action → v6/action}/ami.mdx +0 -0
- /package/docs/{action → v6/action}/performance.mdx +0 -0
- /package/docs/{action → v6/action}/secrets.mdx +0 -0
- /package/docs/{apps → v6/apps}/chrome-extensions.mdx +0 -0
- /package/docs/{apps → v6/apps}/desktop-apps.mdx +0 -0
- /package/docs/{apps → v6/apps}/mobile-apps.mdx +0 -0
- /package/docs/{apps → v6/apps}/static-websites.mdx +0 -0
- /package/docs/{apps → v6/apps}/tauri-apps.mdx +0 -0
- /package/docs/{bugs → v6/bugs}/jira.mdx +0 -0
- /package/docs/{cli → v6/cli}/overview.mdx +0 -0
- /package/docs/{commands → v6/commands}/assert.mdx +0 -0
- /package/docs/{commands → v6/commands}/exec.mdx +0 -0
- /package/docs/{commands → v6/commands}/focus-application.mdx +0 -0
- /package/docs/{commands → v6/commands}/hover-image.mdx +0 -0
- /package/docs/{commands → v6/commands}/hover-text.mdx +0 -0
- /package/docs/{commands → v6/commands}/if.mdx +0 -0
- /package/docs/{commands → v6/commands}/match-image.mdx +0 -0
- /package/docs/{commands → v6/commands}/press-keys.mdx +0 -0
- /package/docs/{commands → v6/commands}/remember.mdx +0 -0
- /package/docs/{commands → v6/commands}/run.mdx +0 -0
- /package/docs/{commands → v6/commands}/scroll-until-image.mdx +0 -0
- /package/docs/{commands → v6/commands}/scroll-until-text.mdx +0 -0
- /package/docs/{commands → v6/commands}/scroll.mdx +0 -0
- /package/docs/{commands → v6/commands}/type.mdx +0 -0
- /package/docs/{commands → v6/commands}/wait-for-image.mdx +0 -0
- /package/docs/{commands → v6/commands}/wait-for-text.mdx +0 -0
- /package/docs/{commands → v6/commands}/wait.mdx +0 -0
- /package/docs/{exporting → v6/exporting}/junit.mdx +0 -0
- /package/docs/{exporting → v6/exporting}/playwright.mdx +0 -0
- /package/docs/{features → v6/features}/auto-healing.mdx +0 -0
- /package/docs/{features → v6/features}/generation.mdx +0 -0
- /package/docs/{features → v6/features}/parallel-testing.mdx +0 -0
- /package/docs/{features → v6/features}/reusable-snippets.mdx +0 -0
- /package/docs/{features → v6/features}/selectorless.mdx +0 -0
- /package/docs/{features → v6/features}/visual-assertions.mdx +0 -0
- /package/docs/{getting-started → v6/getting-started}/ci.mdx +0 -0
- /package/docs/{getting-started → v6/getting-started}/cli.mdx +0 -0
- /package/docs/{getting-started → v6/getting-started}/editing.mdx +0 -0
- /package/docs/{getting-started → v6/getting-started}/playwright.mdx +0 -0
- /package/docs/{getting-started → v6/getting-started}/running.mdx +0 -0
- /package/docs/{getting-started → v6/getting-started}/vscode.mdx +0 -0
- /package/docs/{guide → v6/guide}/assertions.mdx +0 -0
- /package/docs/{guide → v6/guide}/authentication.mdx +0 -0
- /package/docs/{guide → v6/guide}/code.mdx +0 -0
- /package/docs/{guide → v6/guide}/locating.mdx +0 -0
- /package/docs/{guide → v6/guide}/protips.mdx +0 -0
- /package/docs/{guide → v6/guide}/variables.mdx +0 -0
- /package/docs/{guide → v6/guide}/waiting.mdx +0 -0
- /package/docs/{importing → v6/importing}/csv.mdx +0 -0
- /package/docs/{importing → v6/importing}/gherkin.mdx +0 -0
- /package/docs/{importing → v6/importing}/jira.mdx +0 -0
- /package/docs/{importing → v6/importing}/testrail.mdx +0 -0
- /package/docs/{integrations → v6/integrations}/electron.mdx +0 -0
- /package/docs/{integrations → v6/integrations}/netlify.mdx +0 -0
- /package/docs/{integrations → v6/integrations}/vercel.mdx +0 -0
- /package/docs/{interactive → v6/interactive}/explore.mdx +0 -0
- /package/docs/{interactive → v6/interactive}/run.mdx +0 -0
- /package/docs/{interactive → v6/interactive}/save.mdx +0 -0
- /package/docs/{overview → v6/overview}/faq.mdx +0 -0
- /package/docs/{overview → v6/overview}/performance.mdx +0 -0
- /package/docs/{overview → v6/overview}/quickstart.mdx +0 -0
- /package/docs/{overview → v6/overview}/what-is-testdriver.mdx +0 -0
- /package/docs/{scenarios → v6/scenarios}/ai-chatbot.mdx +0 -0
- /package/docs/{scenarios → v6/scenarios}/cookie-banner.mdx +0 -0
- /package/docs/{scenarios → v6/scenarios}/file-upload.mdx +0 -0
- /package/docs/{scenarios → v6/scenarios}/form-filling.mdx +0 -0
- /package/docs/{scenarios → v6/scenarios}/log-in.mdx +0 -0
- /package/docs/{scenarios → v6/scenarios}/pdf-generation.mdx +0 -0
- /package/docs/{scenarios → v6/scenarios}/spell-check.mdx +0 -0
- /package/docs/{security → v6/security}/action.mdx +0 -0
- /package/docs/{security → v6/security}/agent.mdx +0 -0
- /package/docs/{security → v6/security}/platform.mdx +0 -0
- /package/docs/{tutorials → v6/tutorials}/advanced-test.mdx +0 -0
- /package/docs/{tutorials → v6/tutorials}/basic-test.mdx +0 -0
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "pressKeys()"
|
|
3
|
+
sidebarTitle: "pressKeys"
|
|
4
|
+
description: "Press keyboard keys and shortcuts"
|
|
5
|
+
icon: "keyboard"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
|
|
10
|
+
Press one or more keyboard keys simultaneously, useful for keyboard shortcuts, navigation, and special keys.
|
|
11
|
+
|
|
12
|
+
## Syntax
|
|
13
|
+
|
|
14
|
+
```javascript
|
|
15
|
+
await testdriver.pressKeys(keys)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Parameters
|
|
19
|
+
|
|
20
|
+
<ParamField path="keys" type="Array<string>" required>
|
|
21
|
+
Array of keys to press simultaneously
|
|
22
|
+
</ParamField>
|
|
23
|
+
|
|
24
|
+
## Returns
|
|
25
|
+
|
|
26
|
+
`Promise<void>`
|
|
27
|
+
|
|
28
|
+
## Common Keys
|
|
29
|
+
|
|
30
|
+
### Special Keys
|
|
31
|
+
- `'enter'`, `'tab'`, `'escape'`, `'backspace'`, `'delete'`
|
|
32
|
+
- `'space'`, `'up'`, `'down'`, `'left'`, `'right'`
|
|
33
|
+
- `'home'`, `'end'`, `'pageup'`, `'pagedown'`
|
|
34
|
+
|
|
35
|
+
### Modifier Keys
|
|
36
|
+
- `'ctrl'`, `'alt'`, `'shift'`
|
|
37
|
+
- `'command'` (macOS), `'win'` (Windows)
|
|
38
|
+
- `'ctrlleft'`, `'ctrlright'`, `'shiftleft'`, `'shiftright'`
|
|
39
|
+
|
|
40
|
+
### Function Keys
|
|
41
|
+
- `'f1'` through `'f24'`
|
|
42
|
+
|
|
43
|
+
## Examples
|
|
44
|
+
|
|
45
|
+
### Navigation
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
// Tab to next field
|
|
49
|
+
await testdriver.pressKeys(['tab']);
|
|
50
|
+
|
|
51
|
+
// Shift+Tab to previous field
|
|
52
|
+
await testdriver.pressKeys(['shift', 'tab']);
|
|
53
|
+
|
|
54
|
+
// Arrow keys
|
|
55
|
+
await testdriver.pressKeys(['down']);
|
|
56
|
+
await testdriver.pressKeys(['up']);
|
|
57
|
+
await testdriver.pressKeys(['left']);
|
|
58
|
+
await testdriver.pressKeys(['right']);
|
|
59
|
+
|
|
60
|
+
// Home/End
|
|
61
|
+
await testdriver.pressKeys(['home']); // Start of line
|
|
62
|
+
await testdriver.pressKeys(['end']); // End of line
|
|
63
|
+
|
|
64
|
+
// Page navigation
|
|
65
|
+
await testdriver.pressKeys(['pagedown']);
|
|
66
|
+
await testdriver.pressKeys(['pageup']);
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Keyboard Shortcuts
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
// Copy (Ctrl+C / Cmd+C)
|
|
73
|
+
await testdriver.pressKeys(['ctrl', 'c']);
|
|
74
|
+
|
|
75
|
+
// Paste (Ctrl+V / Cmd+V)
|
|
76
|
+
await testdriver.pressKeys(['ctrl', 'v']);
|
|
77
|
+
|
|
78
|
+
// Save (Ctrl+S)
|
|
79
|
+
await testdriver.pressKeys(['ctrl', 's']);
|
|
80
|
+
|
|
81
|
+
// Select All (Ctrl+A)
|
|
82
|
+
await testdriver.pressKeys(['ctrl', 'a']);
|
|
83
|
+
|
|
84
|
+
// Undo (Ctrl+Z)
|
|
85
|
+
await testdriver.pressKeys(['ctrl', 'z']);
|
|
86
|
+
|
|
87
|
+
// Redo (Ctrl+Y)
|
|
88
|
+
await testdriver.pressKeys(['ctrl', 'y']);
|
|
89
|
+
|
|
90
|
+
// Find (Ctrl+F)
|
|
91
|
+
await testdriver.pressKeys(['ctrl', 'f']);
|
|
92
|
+
|
|
93
|
+
// New tab (Ctrl+T)
|
|
94
|
+
await testdriver.pressKeys(['ctrl', 't']);
|
|
95
|
+
|
|
96
|
+
// Close tab (Ctrl+W)
|
|
97
|
+
await testdriver.pressKeys(['ctrl', 'w']);
|
|
98
|
+
|
|
99
|
+
// Refresh (F5 or Ctrl+R)
|
|
100
|
+
await testdriver.pressKeys(['f5']);
|
|
101
|
+
await testdriver.pressKeys(['ctrl', 'r']);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### System Shortcuts
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
// Alt+Tab (Windows - switch apps)
|
|
108
|
+
await testdriver.pressKeys(['alt', 'tab']);
|
|
109
|
+
|
|
110
|
+
// Alt+F4 (Windows - close window)
|
|
111
|
+
await testdriver.pressKeys(['alt', 'f4']);
|
|
112
|
+
|
|
113
|
+
// Win+D (Windows - show desktop)
|
|
114
|
+
await testdriver.pressKeys(['winleft', 'd']);
|
|
115
|
+
|
|
116
|
+
// Win+L (Windows - lock screen)
|
|
117
|
+
await testdriver.pressKeys(['winleft', 'l']);
|
|
118
|
+
|
|
119
|
+
// Cmd+Tab (macOS - switch apps)
|
|
120
|
+
await testdriver.pressKeys(['command', 'tab']);
|
|
121
|
+
|
|
122
|
+
// Cmd+Q (macOS - quit app)
|
|
123
|
+
await testdriver.pressKeys(['command', 'q']);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Form Submission
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
// Submit form
|
|
130
|
+
await testdriver.pressKeys(['enter']);
|
|
131
|
+
|
|
132
|
+
// Cancel/Close
|
|
133
|
+
await testdriver.pressKeys(['escape']);
|
|
134
|
+
|
|
135
|
+
// Check checkbox
|
|
136
|
+
await testdriver.pressKeys(['space']);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Text Editing
|
|
140
|
+
|
|
141
|
+
```javascript
|
|
142
|
+
// Delete selected text
|
|
143
|
+
await testdriver.pressKeys(['delete']);
|
|
144
|
+
|
|
145
|
+
// Backspace
|
|
146
|
+
await testdriver.pressKeys(['backspace']);
|
|
147
|
+
|
|
148
|
+
// Select all and delete
|
|
149
|
+
await testdriver.pressKeys(['ctrl', 'a']);
|
|
150
|
+
await testdriver.pressKeys(['delete']);
|
|
151
|
+
|
|
152
|
+
// Cut text
|
|
153
|
+
await testdriver.pressKeys(['ctrl', 'x']);
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Best Practices
|
|
157
|
+
|
|
158
|
+
<Check>
|
|
159
|
+
**Wait after shortcuts**
|
|
160
|
+
|
|
161
|
+
Some keyboard shortcuts trigger animations or navigation:
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
await testdriver.pressKeys(['ctrl', 't']); // New tab
|
|
165
|
+
await new Promise(r => setTimeout(r, 500)); // Wait for tab
|
|
166
|
+
await testdriver.pressKeys(['ctrl', 'l']); // Focus URL bar
|
|
167
|
+
```
|
|
168
|
+
</Check>
|
|
169
|
+
|
|
170
|
+
<Check>
|
|
171
|
+
**Use Tab for form navigation**
|
|
172
|
+
|
|
173
|
+
Tab is more reliable than clicking multiple fields:
|
|
174
|
+
|
|
175
|
+
```javascript
|
|
176
|
+
const firstField = await testdriver.find('email input');
|
|
177
|
+
await firstField.click();
|
|
178
|
+
await testdriver.type('user@example.com');
|
|
179
|
+
|
|
180
|
+
await testdriver.pressKeys(['tab']);
|
|
181
|
+
await testdriver.type('password123');
|
|
182
|
+
|
|
183
|
+
await testdriver.pressKeys(['tab']);
|
|
184
|
+
await testdriver.pressKeys(['enter']); // Submit
|
|
185
|
+
```
|
|
186
|
+
</Check>
|
|
187
|
+
|
|
188
|
+
<Warning>
|
|
189
|
+
**Platform-specific keys**
|
|
190
|
+
|
|
191
|
+
Use the appropriate modifier key for the platform:
|
|
192
|
+
- Windows/Linux: `'ctrl'`
|
|
193
|
+
- macOS: `'command'`
|
|
194
|
+
|
|
195
|
+
```javascript
|
|
196
|
+
// For cross-platform, you might need to detect OS
|
|
197
|
+
const modKey = process.platform === 'darwin' ? 'command' : 'ctrl';
|
|
198
|
+
await testdriver.pressKeys([modKey, 'c']); // Copy
|
|
199
|
+
```
|
|
200
|
+
</Warning>
|
|
201
|
+
|
|
202
|
+
## Use Cases
|
|
203
|
+
|
|
204
|
+
<AccordionGroup>
|
|
205
|
+
<Accordion title="Form Navigation">
|
|
206
|
+
```javascript
|
|
207
|
+
// Fill form using Tab
|
|
208
|
+
const firstField = await testdriver.find('name field');
|
|
209
|
+
await firstField.click();
|
|
210
|
+
await testdriver.type('John Doe');
|
|
211
|
+
|
|
212
|
+
await testdriver.pressKeys(['tab']);
|
|
213
|
+
await testdriver.type('john@example.com');
|
|
214
|
+
|
|
215
|
+
await testdriver.pressKeys(['tab']);
|
|
216
|
+
await testdriver.type('555-0123');
|
|
217
|
+
|
|
218
|
+
await testdriver.pressKeys(['tab']);
|
|
219
|
+
await testdriver.pressKeys(['enter']); // Submit
|
|
220
|
+
```
|
|
221
|
+
</Accordion>
|
|
222
|
+
|
|
223
|
+
<Accordion title="Text Manipulation">
|
|
224
|
+
```javascript
|
|
225
|
+
const textArea = await testdriver.find('comment textarea');
|
|
226
|
+
await textArea.click();
|
|
227
|
+
|
|
228
|
+
// Select all existing text
|
|
229
|
+
await testdriver.pressKeys(['ctrl', 'a']);
|
|
230
|
+
|
|
231
|
+
// Copy it
|
|
232
|
+
await testdriver.pressKeys(['ctrl', 'c']);
|
|
233
|
+
|
|
234
|
+
// Type new text
|
|
235
|
+
await testdriver.type('New comment');
|
|
236
|
+
|
|
237
|
+
// Undo if needed
|
|
238
|
+
await testdriver.pressKeys(['ctrl', 'z']);
|
|
239
|
+
```
|
|
240
|
+
</Accordion>
|
|
241
|
+
|
|
242
|
+
<Accordion title="Browser Navigation">
|
|
243
|
+
```javascript
|
|
244
|
+
// Open new tab
|
|
245
|
+
await testdriver.pressKeys(['ctrl', 't']);
|
|
246
|
+
await new Promise(r => setTimeout(r, 500));
|
|
247
|
+
|
|
248
|
+
// Focus address bar
|
|
249
|
+
await testdriver.pressKeys(['ctrl', 'l']);
|
|
250
|
+
await testdriver.type('https://example.com');
|
|
251
|
+
await testdriver.pressKeys(['enter']);
|
|
252
|
+
|
|
253
|
+
// Refresh page
|
|
254
|
+
await testdriver.pressKeys(['f5']);
|
|
255
|
+
|
|
256
|
+
// Close tab
|
|
257
|
+
await testdriver.pressKeys(['ctrl', 'w']);
|
|
258
|
+
```
|
|
259
|
+
</Accordion>
|
|
260
|
+
|
|
261
|
+
<Accordion title="Application Shortcuts">
|
|
262
|
+
```javascript
|
|
263
|
+
// Save document
|
|
264
|
+
await testdriver.pressKeys(['ctrl', 's']);
|
|
265
|
+
|
|
266
|
+
// Print
|
|
267
|
+
await testdriver.pressKeys(['ctrl', 'p']);
|
|
268
|
+
|
|
269
|
+
// Find in page
|
|
270
|
+
await testdriver.pressKeys(['ctrl', 'f']);
|
|
271
|
+
await testdriver.type('search term');
|
|
272
|
+
await testdriver.pressKeys(['escape']); // Close find
|
|
273
|
+
```
|
|
274
|
+
</Accordion>
|
|
275
|
+
</AccordionGroup>
|
|
276
|
+
|
|
277
|
+
## Complete Example
|
|
278
|
+
|
|
279
|
+
```javascript
|
|
280
|
+
import { beforeAll, afterAll, describe, it } from 'vitest';
|
|
281
|
+
import TestDriver from 'testdriverai';
|
|
282
|
+
|
|
283
|
+
describe('Keyboard Navigation', () => {
|
|
284
|
+
let testdriver;
|
|
285
|
+
|
|
286
|
+
beforeAll(async () => {
|
|
287
|
+
client = new TestDriver(process.env.TD_API_KEY);
|
|
288
|
+
await testdriver.auth();
|
|
289
|
+
await testdriver.connect({ newSandbox: true });
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
afterAll(async () => {
|
|
293
|
+
await testdriver.disconnect();
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it('should navigate form with keyboard', async () => {
|
|
297
|
+
await testdriver.focusApplication('Google Chrome');
|
|
298
|
+
|
|
299
|
+
// Find first field
|
|
300
|
+
const emailField = await testdriver.find('email input');
|
|
301
|
+
await emailField.click();
|
|
302
|
+
await testdriver.type('user@example.com');
|
|
303
|
+
|
|
304
|
+
// Tab through fields
|
|
305
|
+
await testdriver.pressKeys(['tab']);
|
|
306
|
+
await testdriver.type('John');
|
|
307
|
+
|
|
308
|
+
await testdriver.pressKeys(['tab']);
|
|
309
|
+
await testdriver.type('Doe');
|
|
310
|
+
|
|
311
|
+
await testdriver.pressKeys(['tab']);
|
|
312
|
+
await testdriver.type('password123');
|
|
313
|
+
|
|
314
|
+
// Submit with Enter
|
|
315
|
+
await testdriver.pressKeys(['tab']);
|
|
316
|
+
await testdriver.pressKeys(['enter']);
|
|
317
|
+
|
|
318
|
+
await testdriver.assert('form submitted successfully');
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it('should use keyboard shortcuts', async () => {
|
|
322
|
+
// Open new browser tab
|
|
323
|
+
await testdriver.pressKeys(['ctrl', 't']);
|
|
324
|
+
await new Promise(r => setTimeout(r, 500));
|
|
325
|
+
|
|
326
|
+
// Focus address bar
|
|
327
|
+
await testdriver.pressKeys(['ctrl', 'l']);
|
|
328
|
+
await testdriver.type('https://example.com');
|
|
329
|
+
await testdriver.pressKeys(['enter']);
|
|
330
|
+
|
|
331
|
+
await new Promise(r => setTimeout(r, 2000));
|
|
332
|
+
|
|
333
|
+
// Select all page content
|
|
334
|
+
await testdriver.pressKeys(['ctrl', 'a']);
|
|
335
|
+
|
|
336
|
+
// Copy
|
|
337
|
+
await testdriver.pressKeys(['ctrl', 'c']);
|
|
338
|
+
|
|
339
|
+
// Refresh page
|
|
340
|
+
await testdriver.pressKeys(['f5']);
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## Related Methods
|
|
346
|
+
|
|
347
|
+
- [`type()`](/v7/api/type) - Type text
|
|
348
|
+
- [`click()`](/v7/api/click) - Click elements
|
|
349
|
+
- [`scroll()`](/v7/api/scroll) - Scroll pages
|