@probolabs/playwright 0.4.19 → 0.4.20

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/README.md CHANGED
@@ -1,136 +1,136 @@
1
- # Probolib: drive your playwright scripts with AI superpowers
2
-
3
- Probolib is a powerful AI-driven automation library that enhances Playwright testing and automation by making your scripts more robust and maintainable. Instead of relying on brittle CSS selectors or complex XPath expressions, Probolib uses natural language to interact with web elements.
4
-
5
- ## Why Probolib?
6
-
7
- - **Natural Language Automation**: Write human-readable instructions instead of complex selectors
8
- - **More Resilient Tests**: AI-powered element detection that adapts to UI changes
9
- - **Simpler Maintenance**: Reduce the need to update selectors when the UI changes
10
- - **Faster Development**: Write automation scripts in plain English
11
-
12
- ## Example
13
-
14
- Instead of writing:
15
-
16
- ```
17
- page.click('some > super > complex > css > and non robust selector')
18
- ```
19
-
20
- You can simply write:
21
-
22
- ```
23
- probo.runStep(page, 'click on the save button')
24
- ```
25
-
26
- ## Quickstart
27
-
28
- ```
29
- npm install @probolabs/playwright
30
- ```
31
-
32
- ## Accessing our backend
33
-
34
- the heavy lifting of the AI reasoning is done at the moment on our backend server. in order to access it you would need to tell the library how to access it.
35
-
36
- ## easyiest - set ENV var
37
-
38
- probolib expects the existance of 2 env vars:
39
-
40
- ```
41
- export PROBO_API_ENDPOINT=api.probolabs.ai
42
- export PROBO_API_KEY=<api key we will give you>
43
-
44
- ```
45
-
46
- Or use dotenv
47
-
48
- ```
49
- // npm install dotenv
50
- // in your script add this line
51
- import 'dotenv/config' // ES6
52
-
53
- // .env file located in the root of your project (the same level as your package.json)
54
- PROBO_API_ENDPOINT=https://api.probolabs.ai
55
- PROBO_API_KEY=<api key we will give you>
56
-
57
- ```
58
-
59
- ## A complete example for Playwright integration. step by step
60
-
61
- **step 1:** init a playwright project
62
-
63
- ```
64
- # from your work directory
65
- mkdir probo-example
66
- cd probo-example
67
- npm init playwright@latest
68
- # follow the instructions and wait till the installation is finished
69
- # verify that playwright is installed properly
70
- npx playwright test --project chromium
71
- ```
72
-
73
- **step 2**: integrate probolabs
74
-
75
- ```
76
- npm install @probolabs/playwright dotenv
77
- ```
78
-
79
- **step 3:** configure the env with our endpoint and api key
80
-
81
- ```
82
- touch .env
83
- ```
84
-
85
- edit the .env file
86
-
87
- ```
88
- #.env
89
- PROBO_API_ENDPOINT=https://api.probolabs.ai
90
- PROBO_API_KEY=<api key we will give you>
91
-
92
- ```
93
-
94
- **step 4:** create a file under the tests folder named `probo-example-todo-mvc.spec.mjs`
95
-
96
- ```
97
- // tests/probo-example-todo-mvc.spec.mjs
98
- import 'dotenv/config';
99
- import { test} from '@playwright/test';
100
- import { Probo } from '@probolabs/playwright';
101
-
102
- //
103
- // Important: Before running this script set PROBO_API_KEY and PROBO_API_ENDPOINT
104
- //
105
-
106
- test.describe('Todo MVC', () => {
107
- test('basic example', async ({ page }) => {
108
- try {
109
- // Initialize Probo
110
- const probo = new Probo({
111
- scenarioName: 'probo-example-todo-mvc' // important for caching the AI reasoning
112
- });
113
-
114
- //Goto page
115
- await page.goto('https://demo.playwright.dev/todomvc');
116
-
117
- // Run test steps
118
- console.log('Running test steps...');
119
- await probo.runStep(page, 'enter a new todo item: "Buy groceries"');
120
- await probo.runStep(page, 'press the Enter key');
121
-
122
- console.log('✨ Test completed successfully!');
123
- } catch (error) {
124
- console.error('❌ Test failed:', error);
125
- throw error; // Re-throw to mark the test as failed
126
- }
127
- });
128
- });
129
-
130
- ```
131
-
132
- **run the example**
133
-
134
- ```
135
- npx playwright test tests/probo-example-todo-mvc.spec.mjs --headed --project chromium
136
- ```
1
+ # Probolib: drive your playwright scripts with AI superpowers
2
+
3
+ Probolib is a powerful AI-driven automation library that enhances Playwright testing and automation by making your scripts more robust and maintainable. Instead of relying on brittle CSS selectors or complex XPath expressions, Probolib uses natural language to interact with web elements.
4
+
5
+ ## Why Probolib?
6
+
7
+ - **Natural Language Automation**: Write human-readable instructions instead of complex selectors
8
+ - **More Resilient Tests**: AI-powered element detection that adapts to UI changes
9
+ - **Simpler Maintenance**: Reduce the need to update selectors when the UI changes
10
+ - **Faster Development**: Write automation scripts in plain English
11
+
12
+ ## Example
13
+
14
+ Instead of writing:
15
+
16
+ ```
17
+ page.click('some > super > complex > css > and non robust selector')
18
+ ```
19
+
20
+ You can simply write:
21
+
22
+ ```
23
+ probo.runStep(page, 'click on the save button')
24
+ ```
25
+
26
+ ## Quickstart
27
+
28
+ ```
29
+ npm install @probolabs/playwright
30
+ ```
31
+
32
+ ## Accessing our backend
33
+
34
+ the heavy lifting of the AI reasoning is done at the moment on our backend server. in order to access it you would need to tell the library how to access it.
35
+
36
+ ## easyiest - set ENV var
37
+
38
+ probolib expects the existance of 2 env vars:
39
+
40
+ ```
41
+ export PROBO_API_ENDPOINT=api.probolabs.ai
42
+ export PROBO_API_KEY=<api key we will give you>
43
+
44
+ ```
45
+
46
+ Or use dotenv
47
+
48
+ ```
49
+ // npm install dotenv
50
+ // in your script add this line
51
+ import 'dotenv/config' // ES6
52
+
53
+ // .env file located in the root of your project (the same level as your package.json)
54
+ PROBO_API_ENDPOINT=https://api.probolabs.ai
55
+ PROBO_API_KEY=<api key we will give you>
56
+
57
+ ```
58
+
59
+ ## A complete example for Playwright integration. step by step
60
+
61
+ **step 1:** init a playwright project
62
+
63
+ ```
64
+ # from your work directory
65
+ mkdir probo-example
66
+ cd probo-example
67
+ npm init playwright@latest
68
+ # follow the instructions and wait till the installation is finished
69
+ # verify that playwright is installed properly
70
+ npx playwright test --project chromium
71
+ ```
72
+
73
+ **step 2**: integrate probolabs
74
+
75
+ ```
76
+ npm install @probolabs/playwright dotenv
77
+ ```
78
+
79
+ **step 3:** configure the env with our endpoint and api key
80
+
81
+ ```
82
+ touch .env
83
+ ```
84
+
85
+ edit the .env file
86
+
87
+ ```
88
+ #.env
89
+ PROBO_API_ENDPOINT=https://api.probolabs.ai
90
+ PROBO_API_KEY=<api key we will give you>
91
+
92
+ ```
93
+
94
+ **step 4:** create a file under the tests folder named `probo-example-todo-mvc.spec.mjs`
95
+
96
+ ```
97
+ // tests/probo-example-todo-mvc.spec.mjs
98
+ import 'dotenv/config';
99
+ import { test} from '@playwright/test';
100
+ import { Probo } from '@probolabs/playwright';
101
+
102
+ //
103
+ // Important: Before running this script set PROBO_API_KEY and PROBO_API_ENDPOINT
104
+ //
105
+
106
+ test.describe('Todo MVC', () => {
107
+ test('basic example', async ({ page }) => {
108
+ try {
109
+ // Initialize Probo
110
+ const probo = new Probo({
111
+ scenarioName: 'probo-example-todo-mvc' // important for caching the AI reasoning
112
+ });
113
+
114
+ //Goto page
115
+ await page.goto('https://demo.playwright.dev/todomvc');
116
+
117
+ // Run test steps
118
+ console.log('Running test steps...');
119
+ await probo.runStep(page, 'enter a new todo item: "Buy groceries"');
120
+ await probo.runStep(page, 'press the Enter key');
121
+
122
+ console.log('✨ Test completed successfully!');
123
+ } catch (error) {
124
+ console.error('❌ Test failed:', error);
125
+ throw error; // Re-throw to mark the test as failed
126
+ }
127
+ });
128
+ });
129
+
130
+ ```
131
+
132
+ **run the example**
133
+
134
+ ```
135
+ npx playwright test tests/probo-example-todo-mvc.spec.mjs --headed --project chromium
136
+ ```
package/dist/index.d.ts CHANGED
@@ -1,15 +1,24 @@
1
- import { Page } from 'playwright';
2
- import { PlaywrightAction, ElementTag, ProboLogLevel } from '@probolabs/probo-shared';
1
+ import { Page, Locator } from 'playwright';
2
+ import { PlaywrightAction, ElementTag, PlaywrightTimeoutConfig, AIModel, ServerResponse, ProboLogLevel } from '@probolabs/probo-shared';
3
3
  export { ElementInfo, ElementTag, PlaywrightAction, ProboLogLevel } from '@probolabs/probo-shared';
4
+ import { Page as Page$1 } from '@playwright/test';
4
5
 
5
6
  /**
6
7
  * Execute a given Playwright action, mirroring Python's _perform_action
7
8
  */
8
- declare function executePlaywrightAction(page: Page, action: PlaywrightAction, value: string, iframe_selector: string, element_css_selector: string): Promise<boolean>;
9
+ declare function executePlaywrightAction(page: Page, action: PlaywrightAction, value: string | boolean, iframe_selector: string, element_css_selector: string): Promise<boolean | string>;
9
10
  /**
10
11
  * Execute a given Playwright action using native Playwright functions where possible
11
12
  */
12
- declare function executeCachedPlaywrightAction(page: Page, action: PlaywrightAction, value: string, iframe_selector: string, element_css_selector: string): Promise<boolean>;
13
+ declare function executeCachedPlaywrightAction(page: Page, action: PlaywrightAction, value: string | boolean, iframe_selector: string, element_css_selector: string): Promise<boolean | string>;
14
+ /**
15
+ * Traverses up the DOM from the given locator to find the closest visible ancestor.
16
+ * Returns a Locator for the first visible element found, or null if none is visible up to <html>.
17
+ *
18
+ * @param locator - The Playwright locator to start searching from
19
+ * @returns Promise that resolves to a visible ancestor locator or null if none found
20
+ */
21
+ declare function findClosestVisibleElement(locator: Locator): Promise<Locator | null>;
13
22
 
14
23
  type ElementTagType = typeof ElementTag[keyof typeof ElementTag];
15
24
  declare global {
@@ -87,22 +96,79 @@ declare class Highlighter {
87
96
  getMatchingCandidateCached(page: Page): Promise<any>;
88
97
  }
89
98
 
90
- /**
91
- * Available AI models for LLM operations
92
- */
93
- declare enum AIModel {
94
- AZURE_GPT4 = "AZURE_GPT4",
95
- AZURE_GPT4_MINI = "AZURE_GPT4_MINI",
96
- GEMINI_1_5_FLASH = "GEMINI_1_5_FLASH",
97
- GEMINI_2_5_FLASH = "GEMINI_2_5_FLASH",
98
- GPT4 = "GPT4",
99
- GPT4_MINI = "GPT4_MINI",
100
- CLAUDE_3_5 = "CLAUDE_3_5",
101
- GROK_2 = "GROK_2",
102
- LLAMA_4_SCOUT = "LLAMA_4_SCOUT",
103
- DEEPSEEK_V3 = "DEEPSEEK_V3",
104
- DEFAULT_AI_MODEL = "DEFAULT_AI_MODEL"
99
+ interface RunStepParams extends Partial<PlaywrightTimeoutConfig> {
100
+ iframeSelector: string;
101
+ elementSelector: string;
102
+ action: PlaywrightAction | PlaywrightAction[] | string | string[];
103
+ argument?: string | string[];
104
+ annotation?: string;
105
+ }
106
+ interface RunStepResult {
107
+ key: string;
108
+ value: any;
109
+ }
110
+ declare class ProboPlaywright {
111
+ private readonly config;
112
+ private page;
113
+ constructor(config?: PlaywrightTimeoutConfig, page?: Page$1 | null);
114
+ /**
115
+ * Sets the Playwright page instance for this ProboPlaywright instance.
116
+ * Also applies the configured default navigation and action timeouts to the page.
117
+ *
118
+ * @param page - The Playwright Page instance to use, or null to unset.
119
+ */
120
+ setPage(page: Page$1 | null): void;
121
+ /**
122
+ * Executes a single step in the test scenario with the specified action on the target element.
123
+ * Handles iframe navigation, element highlighting, and various Playwright actions like click, fill, validate, etc.
124
+ *
125
+ * @param params - Configuration object containing element selectors, action type, arguments, and display options
126
+ * @returns Promise that resolves to a result object for extract actions, or void for other actions
127
+ * @throws Error if element is not found or validation fails
128
+ */
129
+ runStep(params: RunStepParams): Promise<RunStepResult | void>;
130
+ /**
131
+ * Creates a visual highlight overlay on the target element with optional annotation text.
132
+ * The highlight appears as a red border around the element and can include descriptive text.
133
+ *
134
+ * @param locator - The Playwright locator for the element to highlight
135
+ * @param annotation - Optional text annotation to display above/below the highlighted element
136
+ */
137
+ private highlight;
138
+ /**
139
+ * Removes the highlight overlay from the target element.
140
+ * Cleans up the visual highlighting created by the highlight method.
141
+ *
142
+ * @param locator - The Playwright locator for the element to unhighlight
143
+ */
144
+ private unhighlight;
145
+ /**
146
+ * Attempts to fill a form field with the specified value using multiple fallback strategies.
147
+ * First tries the standard fill method, then falls back to click + type if needed.
148
+ *
149
+ * @param locator - The Playwright locator for the input element
150
+ * @param value - The text value to fill into the input field
151
+ */
152
+ private robustFill;
153
+ /**
154
+ * Performs a robust click operation using multiple fallback strategies.
155
+ * Attempts standard click first, then mouse click at center coordinates, and finally native DOM events.
156
+ *
157
+ * @param locator - The Playwright locator for the element to click
158
+ * @throws Error if all click methods fail
159
+ */
160
+ private robustClick;
161
+ /**
162
+ * Extracts text content from an element using multiple strategies.
163
+ * Tries textContent first, then inputValue, and finally looks for nested input elements.
164
+ * Returns normalized and trimmed text for consistent comparison.
165
+ *
166
+ * @param locator - The Playwright locator for the element to extract text from
167
+ * @returns Normalized text content with consistent whitespace handling
168
+ */
169
+ private getTextValue;
105
170
  }
171
+
106
172
  /**
107
173
  * Configuration options for Probo client
108
174
  */
@@ -128,16 +194,19 @@ declare class Probo {
128
194
  private readonly scenarioName;
129
195
  private readonly aiModel;
130
196
  constructor({ scenarioName, token, apiUrl, enableConsoleLogs, logToConsole, logToFile, debugLevel, aiModel }: ProboConfig);
131
- runStep(page: Page, stepPrompt: string, argument?: string | null, options?: RunStepOptions): Promise<boolean>;
197
+ askAI(page: Page, question: string): Promise<any>;
198
+ runStep(page: Page, stepPrompt: string, argument?: string | boolean | null, options?: RunStepOptions): Promise<boolean | string>;
132
199
  private _handleCachedStep;
133
200
  private _handleStepCreation;
134
201
  private setupConsoleLogs;
135
202
  highlightElements(page: Page, elementTags: [ElementTagType]): Promise<any>;
136
203
  unhighlightElements(page: Page): Promise<void>;
137
204
  highlightElement(page: Page, element_css_selector: string, iframe_selector: string, element_index: string): Promise<void>;
205
+ waitForMutationsToSettle(page: Page, timeout?: number, initTimeout?: number): Promise<boolean>;
138
206
  screenshot(page: Page): Promise<string>;
139
207
  private _handlePerformAction;
208
+ askAIHelper(page: Page, question: string): Promise<ServerResponse>;
140
209
  }
141
210
 
142
- export { AIModel, Highlighter, Probo, executeCachedPlaywrightAction, executePlaywrightAction };
211
+ export { Highlighter, Probo, ProboPlaywright, executeCachedPlaywrightAction, executePlaywrightAction, findClosestVisibleElement };
143
212
  export type { ElementTagType, RunStepOptions };