@probolabs/playwright 1.0.16 → 1.0.19

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/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Locator, Page } from 'playwright';
2
- import { ElementTag, PlaywrightTimeoutConfig, PlaywrightAction, AIModel, InitialPageState, FindCandidateInput, ServerResponse, ProboLogLevel } from '@probolabs/probo-shared';
3
- export { ElementInfo, ElementTag, PlaywrightAction, ProboLogLevel } from '@probolabs/probo-shared';
2
+ import { SmartSelector, ElementTag, ProboLogLevel, PlaywrightTimeoutConfig, PlaywrightAction, TotpConfig, AIModel, InitialPageState, FindCandidateInput, ServerResponse } from '@probolabs/probo-shared';
3
+ export { AIModel, ElementInfo, ElementTag, PlaywrightAction, ProboLogLevel } from '@probolabs/probo-shared';
4
4
  import { Page as Page$1 } from '@playwright/test';
5
5
 
6
6
  /**
@@ -24,8 +24,10 @@ declare global {
24
24
  highlightElements: (elements: Array<{
25
25
  css_selector: string;
26
26
  iframe_selector: string;
27
- index: string;
28
- }>) => void;
27
+ smart_selector: SmartSelector | null;
28
+ smart_iframe_selector: SmartSelector | null;
29
+ index: number;
30
+ }>, enableSmartSelectors: boolean) => void;
29
31
  unhighlightElements: () => void;
30
32
  findElements: (elementTypes: string) => any[];
31
33
  getElementInfo: (element: Element, index: number) => any;
@@ -34,7 +36,7 @@ declare global {
34
36
  actual?: any;
35
37
  matchingCandidate?: any;
36
38
  findAndCacheCandidateElements?: (elementTypes: string[]) => number;
37
- findAndCacheActualElement?: (cssSelector: string, iframeSelector: string | null, isHover: boolean) => boolean;
39
+ findAndCacheActualElement?: (iframeSelector: string | SmartSelector, elementSelector: string | SmartSelector, isHover: boolean, useSmartSelectors: boolean) => boolean;
38
40
  findAndCacheMatchingCandidate?: () => boolean;
39
41
  highlightCachedElements?: (which: 'candidates' | 'actual' | 'matching') => void;
40
42
  unhighlight?: () => void;
@@ -42,16 +44,19 @@ declare global {
42
44
  getCandidates?: () => any[];
43
45
  getActual?: () => any;
44
46
  getMatchingCandidate?: () => any;
47
+ setLoggerDebugLevel?: (debugLevel: ProboLogLevel) => void;
45
48
  };
46
49
  }
47
50
  }
48
51
  declare class Highlighter {
49
- private enableConsoleLogs;
50
- constructor(enableConsoleLogs?: boolean);
52
+ private readonly enableSmartSelectors;
53
+ private readonly enableConsoleLogs;
54
+ private readonly debugLevel;
55
+ constructor(enableSmartSelectors?: boolean, enableConsoleLogs?: boolean, debugLevel?: ProboLogLevel);
51
56
  private ensureHighlighterScript;
52
57
  highlightElements(page: Page, elementTags: [ElementTagType]): Promise<any>;
53
58
  unhighlightElements(page: Page): Promise<void>;
54
- highlightElement(page: Page, element_css_selector: string, iframe_selector: string, element_index: string): Promise<void>;
59
+ highlightElement(page: Page, element_css_selector: string, iframe_selector: string, smart_selector: SmartSelector | null, smart_iframe_selector: SmartSelector | null, element_index: number): Promise<void>;
55
60
  /**
56
61
  * Find and cache candidate elements of a given type (e.g., 'CLICKABLE').
57
62
  * Returns the number of candidates found.
@@ -61,7 +66,7 @@ declare class Highlighter {
61
66
  * Find and cache the actual interaction element by CSS and iframe selector.
62
67
  * Returns true if found, false otherwise.
63
68
  */
64
- findAndCacheActualElement(page: Page, cssSelector: string, iframeSelector: string | null, isHover?: boolean): Promise<boolean>;
69
+ findAndCacheActualElement(page: Page, iframeSelector: string | SmartSelector, elementSelector: string | SmartSelector, isHover?: boolean): Promise<boolean>;
65
70
  /**
66
71
  * Find and cache the best matching candidate for the actual element.
67
72
  * Returns true if a match was found, false otherwise.
@@ -91,72 +96,106 @@ declare class Highlighter {
91
96
  interface RunStepParams extends Partial<PlaywrightTimeoutConfig> {
92
97
  iframeSelector?: string;
93
98
  elementSelector?: string;
99
+ smartSelector?: SmartSelector | null;
100
+ smartIFrameSelector?: SmartSelector | null;
94
101
  action: PlaywrightAction;
95
102
  argument?: string | string[];
96
103
  annotation?: string;
97
104
  pollingInterval?: number;
98
105
  timeout?: number;
106
+ totpConfig?: TotpConfig;
107
+ }
108
+ interface ProboPlaywrightConfig {
109
+ timeoutConfig?: Partial<PlaywrightTimeoutConfig>;
110
+ enableSmartSelectors?: boolean;
111
+ debugLevel?: ProboLogLevel;
99
112
  }
100
113
  declare class ProboPlaywright {
114
+ private readonly enableSmartSelectors;
101
115
  private readonly timeoutConfig;
102
116
  private page;
103
- constructor(timeoutConfig?: Partial<PlaywrightTimeoutConfig>, page?: Page$1 | null);
117
+ private params;
118
+ constructor({ enableSmartSelectors, timeoutConfig, debugLevel }: ProboPlaywrightConfig, page?: Page$1 | null);
104
119
  /**
105
- * Sets the Playwright page instance for this ProboPlaywright instance.
106
- * Also applies the configured default navigation and action timeouts to the page.
107
- *
108
- * @param page - The Playwright Page instance to use, or null to unset.
109
- */
120
+ * Sets the Playwright page instance for this ProboPlaywright instance.
121
+ * Also applies the configured default navigation and action timeouts to the page.
122
+ *
123
+ * @param page - The Playwright Page instance to use, or null to unset.
124
+ */
110
125
  setPage(page: Page$1 | null): void;
111
126
  /**
112
- * Executes a single step in the test scenario with the specified action on the target element.
113
- * Handles iframe navigation, element highlighting, and various Playwright actions like click, fill, validate, etc.
114
- *
115
- * @param params - Configuration object containing element selectors, action type, arguments, and display options
116
- * @returns Promise that resolves to a result object for extract actions, or void for other actions
117
- * @throws Error if element is not found or validation fails
127
+ * Sets the parameters object for template literal interpolation
128
+ * Stores a reference to the params object so mutations are automatically reflected
129
+ * @param params The parameters object containing values to use for interpolation
118
130
  */
119
- runStep(params: RunStepParams): Promise<string | void>;
131
+ setParams(params: Record<string, any>): void;
120
132
  /**
121
- * Creates a visual highlight overlay on the target element with optional annotation text.
122
- * The highlight appears as a red border around the element and can include descriptive text.
123
- *
124
- * @param locator - The Playwright locator for the element to highlight
125
- * @param annotation - Optional text annotation to display above/below the highlighted element
133
+ * Interpolates a string using the current params and optional additional context
134
+ * @param str The string to interpolate (may contain ${variable} syntax)
135
+ * @param additionalContext Optional additional context to merge with params
136
+ * @returns The interpolated string
126
137
  */
127
- private highlight;
138
+ private interpolate;
139
+ /**
140
+ * Executes a single step in the test scenario with the specified action on the target element.
141
+ * Handles iframe navigation, element highlighting, and various Playwright actions like click, fill, validate, etc.
142
+ *
143
+ * @param params - Configuration object containing element selectors, action type, arguments, and display options
144
+ * @returns Promise that resolves to a string for extract actions, boolean for assert actions, or void for other actions
145
+ * @throws Error if element is not found or validation fails
146
+ */
147
+ runStep(params: RunStepParams): Promise<string | boolean | void>;
128
148
  /**
129
- * Removes the highlight overlay from the target element.
130
- * Cleans up the visual highlighting created by the highlight method.
131
- *
132
- * @param locator - The Playwright locator for the element to unhighlight
149
+ * Public method to generate TOTP code using the provided secret, digits, and algorithm
150
+ * @param secret - The TOTP secret (base32 encoded)
151
+ * @param digits - Number of digits in the TOTP code (default: 6)
152
+ * @param algorithm - Hash algorithm to use (default: 'SHA1')
153
+ * @returns The generated TOTP code
133
154
  */
155
+ generateOTP(secret: string, digits?: number, algorithm?: string): string;
156
+ private getLocator;
157
+ private getLocatorOrFrame;
158
+ /**
159
+ * Creates a visual highlight overlay on the target element with optional annotation text.
160
+ * The highlight appears as a red border around the element and can include descriptive text.
161
+ *
162
+ * @param locator - The Playwright locator for the element to highlight
163
+ * @param annotation - Optional text annotation to display above/below the highlighted element
164
+ */
165
+ private highlight;
166
+ /**
167
+ * Removes the highlight overlay from the target element.
168
+ * Cleans up the visual highlighting created by the highlight method.
169
+ *
170
+ * @param locator - The Playwright locator for the element to unhighlight
171
+ */
134
172
  private unhighlight;
135
173
  /**
136
- * Attempts to fill a form field with the specified value using multiple fallback strategies.
137
- * First tries the standard fill method, then falls back to click + type if needed.
138
- *
139
- * @param locator - The Playwright locator for the input element
140
- * @param value - The text value to fill into the input field
141
- */
174
+ * Attempts to fill a form field with the specified value using multiple fallback strategies.
175
+ * First tries the standard fill method, then falls back to click + type if needed.
176
+ *
177
+ * @param locator - The Playwright locator for the input element
178
+ * @param value - The text value to fill into the input field
179
+ */
142
180
  private robustFill;
143
181
  private robustTypeKeys;
144
182
  /**
145
- * Performs a robust click operation using multiple fallback strategies.
146
- * Attempts standard click first, then mouse click at center coordinates, and finally native DOM events.
147
- *
148
- * @param locator - The Playwright locator for the element to click
149
- * @throws Error if all click methods fail
150
- */
151
- private robustClick;
152
- /**
153
- * Extracts text content from an element using multiple strategies.
154
- * Tries textContent first, then inputValue, and finally looks for nested input elements.
155
- * Returns normalized and trimmed text for consistent comparison.
156
- *
157
- * @param locator - The Playwright locator for the element to extract text from
158
- * @returns Normalized text content with consistent whitespace handling
159
- */
183
+ * Performs a robust mouse action (click or hover) using multiple fallback strategies.
184
+ * Attempts standard click first, then mouse click at center coordinates, and finally native DOM events.
185
+ *
186
+ * @param locator - The Playwright locator for the element to click
187
+ * @param action - The mouse action to perform ('click' or 'hover')
188
+ * @throws Error if all mouse action methods fail
189
+ */
190
+ private robustMouseAction;
191
+ /**
192
+ * Extracts text content from an element using multiple strategies.
193
+ * Tries textContent first, then inputValue, and finally looks for nested input elements.
194
+ * Returns normalized and trimmed text for consistent comparison.
195
+ *
196
+ * @param locator - The Playwright locator for the element to extract text from
197
+ * @returns Normalized text content with consistent whitespace handling
198
+ */
160
199
  private getTextValue;
161
200
  private setSliderValue;
162
201
  }
@@ -331,6 +370,7 @@ interface ProboConfig {
331
370
  scenarioName: string;
332
371
  token?: string;
333
372
  apiUrl?: string;
373
+ enableSmartSelectors?: boolean;
334
374
  enableConsoleLogs?: boolean;
335
375
  logToConsole?: boolean;
336
376
  logToFile?: boolean;
@@ -347,27 +387,44 @@ interface AskAIOptions {
347
387
  stepId?: number;
348
388
  createStep?: boolean;
349
389
  }
390
+
350
391
  declare class Probo {
351
392
  private highlighter;
352
393
  private apiClient;
394
+ private readonly debugLevel;
353
395
  private readonly enableConsoleLogs;
354
396
  private readonly scenarioName;
355
397
  private readonly aiModel;
398
+ private readonly enableSmartSelectors;
356
399
  private readonly timeoutConfig;
357
- constructor({ scenarioName, token, apiUrl, enableConsoleLogs, logToConsole, logToFile, debugLevel, aiModel, timeoutConfig }: ProboConfig);
358
- askAI(page: Page, question: string, options: AskAIOptions): Promise<any>;
359
- runStep(page: Page, stepPrompt: string, argument?: string | boolean | null, options?: RunStepOptions): Promise<string | void>;
400
+ private params;
401
+ constructor({ scenarioName, token, apiUrl, enableConsoleLogs, enableSmartSelectors, logToConsole, logToFile, debugLevel, aiModel, timeoutConfig }: ProboConfig);
402
+ /**
403
+ * Sets the parameters object for template literal interpolation
404
+ * Stores a reference to the params object so mutations are automatically reflected
405
+ * @param params The parameters object containing values to use for interpolation
406
+ */
407
+ setParams(params: Record<string, any>): void;
408
+ /**
409
+ * Interpolates a string using the current params and optional additional context
410
+ * @param str The string to interpolate (may contain ${variable} syntax)
411
+ * @param additionalContext Optional additional context to merge with params
412
+ * @returns The interpolated string
413
+ */
414
+ private interpolate;
415
+ askAI(page: Page, question: string, options: AskAIOptions, assertAnswer?: string): Promise<any>;
416
+ runStep(page: Page, stepPrompt: string, argument?: string | boolean | null, options?: RunStepOptions): Promise<string | boolean | void>;
360
417
  private _handleCachedStep;
361
418
  private setupConsoleLogs;
362
419
  getInitialPageState(page: Page): Promise<InitialPageState>;
363
420
  findAndHighlightCandidateElements(page: Page, elementTags: string[]): Promise<FindCandidateInput>;
364
421
  highlightElements(page: Page, elementTags: [ElementTagType]): Promise<any>;
365
422
  unhighlightElements(page: Page): Promise<void>;
366
- highlightElement(page: Page, element_css_selector: string, iframe_selector: string, element_index: string): Promise<void>;
423
+ highlightElement(page: Page, element_css_selector: string, iframe_selector: string, smart_selector: SmartSelector | null, smart_iframe_selector: SmartSelector | null, element_index: number): Promise<void>;
367
424
  waitForMutationsToSettle(page: Page, timeout?: number, initTimeout?: number): Promise<boolean>;
368
425
  screenshot(page: Page): Promise<string>;
369
426
  private _handlePerformAction;
370
- askAIHelper(page: Page, question: string, options: AskAIOptions): Promise<ServerResponse>;
427
+ askAIHelper(page: Page, question: string, options: AskAIOptions, assertAnswer?: string): Promise<ServerResponse>;
371
428
  }
372
429
 
373
430
  export { Highlighter, NavTracker, OTP, Probo, ProboPlaywright, findClosestVisibleElement };