@testdriverai/mcp 7.11.14-canary → 7.11.15-test

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/docs/docs.json CHANGED
@@ -90,6 +90,7 @@
90
90
  "/v7/click",
91
91
  "/v7/double-click",
92
92
  "/v7/exec",
93
+ "/v7/extract",
93
94
  "/v7/find",
94
95
  "/v7/focus-application",
95
96
  "/v7/hover",
@@ -0,0 +1,225 @@
1
+ ---
2
+ title: "extract()"
3
+ sidebarTitle: "extract"
4
+ description: "Read information from the screen using AI and return it as a string"
5
+ icon: "wand-magic-sparkles"
6
+ ---
7
+
8
+ ## Overview
9
+
10
+ Extract information from the current screen using AI and return it as a string. Describe what you want in natural language, and the AI reads the screen and returns the matching value — text, numbers, labels, status messages, or any other on-screen content.
11
+
12
+ Unlike [`assert()`](/v7/assert), which returns a boolean verdict, `extract()` returns the actual value so you can store it, compare it, or feed it into later steps and framework assertions.
13
+
14
+ ## Syntax
15
+
16
+ ```javascript
17
+ const value = await testdriver.extract(description)
18
+ const value = await testdriver.extract({ description })
19
+ ```
20
+
21
+ ## Parameters
22
+
23
+ <ParamField path="description" type="string" required>
24
+ Natural language description of the information to read from the screen.
25
+ </ParamField>
26
+
27
+ <Info>
28
+ `extract()` also accepts an options object — `extract({ description })` — which is equivalent to the positional form. The bare string form is the most common.
29
+ </Info>
30
+
31
+ ## Returns
32
+
33
+ `Promise<string>` — The information read from the screen. Returns the extracted value as text; parse or cast it yourself if you need a number or other type.
34
+
35
+ ## Examples
36
+
37
+ ### Basic Extraction
38
+
39
+ ```javascript
40
+ // Read text content
41
+ const title = await testdriver.extract('the page title');
42
+ const heading = await testdriver.extract('the main heading text');
43
+
44
+ // Read numbers and prices
45
+ const price = await testdriver.extract('the total price shown in the cart');
46
+ const count = await testdriver.extract('the number of items in the list');
47
+
48
+ // Read status and confirmation values
49
+ const status = await testdriver.extract('the order status');
50
+ const orderNumber = await testdriver.extract('the order confirmation number');
51
+ ```
52
+
53
+ ### Using the Extracted Value
54
+
55
+ ```javascript
56
+ // Store and reuse across steps
57
+ const orderNumber = await testdriver.extract('the order confirmation number');
58
+ console.log('Order:', orderNumber);
59
+
60
+ // Combine with framework assertions
61
+ import { expect } from 'vitest';
62
+
63
+ const message = await testdriver.extract('the success message text');
64
+ expect(message).toContain('successfully');
65
+
66
+ // Cast to a number when you need to compare
67
+ const totalText = await testdriver.extract('the cart total as a number without currency symbol');
68
+ expect(Number(totalText)).toBeGreaterThan(0);
69
+ ```
70
+
71
+ ## Best Practices
72
+
73
+ <Check>
74
+ **Be specific about what to read**
75
+
76
+ Precise descriptions produce cleaner values:
77
+
78
+ ```javascript
79
+ // ❌ Too vague — may return extra surrounding text
80
+ const price = await testdriver.extract('price');
81
+
82
+ // ✅ Specific — targets a single value
83
+ const price = await testdriver.extract('the total price in the order summary, digits only');
84
+ ```
85
+ </Check>
86
+
87
+ <Check>
88
+ **Ask for the format you want**
89
+
90
+ Steer the output by describing the desired shape in the prompt:
91
+
92
+ ```javascript
93
+ // Strip currency symbols
94
+ const total = await testdriver.extract('the order total as a number without the dollar sign');
95
+
96
+ // Isolate a single field
97
+ const email = await testdriver.extract('the email address shown in the profile header');
98
+ ```
99
+ </Check>
100
+
101
+ <Check>
102
+ **Extract for detailed assertions**
103
+
104
+ Use `extract()` when a boolean [`assert()`](/v7/assert) isn't enough and you need the actual value to inspect:
105
+
106
+ ```javascript
107
+ const confirmation = await testdriver.extract('the confirmation number');
108
+ expect(confirmation).toMatch(/^ORD-\d{6}$/);
109
+ ```
110
+ </Check>
111
+
112
+ ## Use Cases
113
+
114
+ <AccordionGroup>
115
+ <Accordion title="Capturing Confirmation Details">
116
+ ```javascript
117
+ const submitBtn = await testdriver.find('place order button');
118
+ await submitBtn.click();
119
+
120
+ // Read the confirmation the app generated
121
+ const orderNumber = await testdriver.extract('the order confirmation number');
122
+ const eta = await testdriver.extract('the estimated delivery date');
123
+
124
+ console.log(`Order ${orderNumber} arrives ${eta}`);
125
+ ```
126
+ </Accordion>
127
+
128
+ <Accordion title="Reading Tooltip and Hover Content">
129
+ ```javascript
130
+ const icon = await testdriver.find('info icon next to the price');
131
+ await icon.hover();
132
+
133
+ const tooltipText = await testdriver.extract('the tooltip text');
134
+ expect(tooltipText).toContain('tax included');
135
+ ```
136
+ </Accordion>
137
+
138
+ <Accordion title="Verifying Dynamic Values">
139
+ ```javascript
140
+ // Read a value before an action
141
+ const before = await testdriver.extract('the account balance');
142
+
143
+ const addBtn = await testdriver.find('add funds button');
144
+ await addBtn.click();
145
+
146
+ // Read it again after and compare
147
+ const after = await testdriver.extract('the account balance');
148
+ expect(Number(after.replace(/[^0-9.]/g, ''))).toBeGreaterThan(
149
+ Number(before.replace(/[^0-9.]/g, ''))
150
+ );
151
+ ```
152
+ </Accordion>
153
+
154
+ <Accordion title="Passing Data Between Steps">
155
+ ```javascript
156
+ // Read a generated code on one screen...
157
+ const resetCode = await testdriver.extract('the password reset code');
158
+
159
+ // ...and type it into the next
160
+ const codeField = await testdriver.find('reset code input');
161
+ await codeField.click();
162
+ await testdriver.type(resetCode);
163
+ ```
164
+ </Accordion>
165
+ </AccordionGroup>
166
+
167
+ ## Complete Example
168
+
169
+ ```javascript
170
+ import { beforeAll, afterAll, describe, it, expect } from 'vitest';
171
+ import TestDriver from 'testdriverai';
172
+
173
+ describe('Extraction', () => {
174
+ let testdriver;
175
+
176
+ beforeAll(async () => {
177
+ testdriver = new TestDriver(process.env.TD_API_KEY);
178
+ await testdriver.auth();
179
+ await testdriver.connect();
180
+ });
181
+
182
+ afterAll(async () => {
183
+ await testdriver.disconnect();
184
+ });
185
+
186
+ it('should capture the order confirmation', async () => {
187
+ await testdriver.focusApplication('Google Chrome');
188
+
189
+ // Complete a checkout
190
+ const checkoutBtn = await testdriver.find('checkout button');
191
+ await checkoutBtn.click();
192
+
193
+ const placeOrderBtn = await testdriver.find('place order button');
194
+ await placeOrderBtn.click();
195
+
196
+ // Verify we reached confirmation
197
+ await testdriver.assert('the order confirmation page is displayed');
198
+
199
+ // Extract the details the app generated
200
+ const orderNumber = await testdriver.extract('the order confirmation number');
201
+ const total = await testdriver.extract('the order total as a number without currency symbol');
202
+
203
+ // Assert on the extracted values
204
+ expect(orderNumber).toBeTruthy();
205
+ expect(Number(total)).toBeGreaterThan(0);
206
+ });
207
+ });
208
+ ```
209
+
210
+ ## How It Works
211
+
212
+ 1. TestDriver captures a screenshot of the current screen
213
+ 2. The image and your description are sent to the TestDriver API
214
+ 3. The AI reads the requested information from the screenshot
215
+ 4. The extracted value is returned as a string
216
+
217
+ <Note>
218
+ Like [assertions](/v7/making-assertions), `extract()` reads the screen fresh on every call — it is not cached — so it always reflects the current state of the app.
219
+ </Note>
220
+
221
+ ## Related Methods
222
+
223
+ - [`assert()`](/v7/assert) - Verify screen state with a boolean AI judgment
224
+ - [`find()`](/v7/find) - Locate elements to interact with
225
+ - [`parse()`](/v7/parse) - Detect all UI elements on screen
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testdriverai/mcp",
3
- "version": "7.11.14-canary",
3
+ "version": "7.11.15-test",
4
4
  "description": "Next generation autonomous AI agent for end-to-end testing of web & desktop",
5
5
  "main": "sdk.js",
6
6
  "types": "sdk.d.ts",