UNPKG

109 kBTypeScriptView Raw
1/// <reference types="node" />
2
3declare module 'testcafe' {
4 global {
5
6 interface KeyModifiers {
7 ctrl?: boolean;
8 alt?: boolean;
9 shift?: boolean;
10 meta?: boolean;
11 }
12
13 interface CropOptions {
14 /**
15 * The top edge of the cropping rectangle. The coordinate is calculated from the element's top edge.
16 * If a negative number is passed, the coordinate is calculated from the element's bottom edge.
17 */
18 left?: number;
19 /**
20 * The left edge of the cropping rectangle. The coordinate is calculated from the element's left edge.
21 * If a negative number is passed, the coordinate is calculated from the element's right edge.
22 */
23 right?: number;
24 /**
25 * The bottom edge of the cropping rectangle. The coordinate is calculated from the element's top edge.
26 * If a negative number is passed, the coordinate is calculated from the element's bottom edge.
27 */
28 top?: number;
29 /**
30 * The right edge of the cropping rectangle. The coordinate is calculated from the element's left edge.
31 * If a negative number is passed, the coordinate is calculated from the element's right edge.
32 */
33 bottom?: number;
34 }
35
36 interface ActionOptions {
37 /**
38 * The speed of action emulation. Defines how fast TestCafe performs the action when running tests.
39 * A value between 1 (the maximum speed) and 0.01 (the minimum speed). If test speed is also specified in the CLI or
40 * programmatically, the action speed setting overrides test speed. Default is 1.
41 */
42 speed?: number;
43 }
44
45 interface TakeScreenshotOptions {
46 /**
47 * Specifies the path where the screenshots are saved.
48 */
49 path?: string;
50 /**
51 * Specifies that TestCafe should take full-page screenshots.
52 */
53 fullPage?: boolean;
54 }
55
56 interface TakeElementScreenshotOptions extends ActionOptions {
57 /**
58 * Allows to crop the target element on the screenshot.
59 */
60 crop?: CropOptions;
61 /**
62 * Controls if element's margins should be included in the screenshot.
63 * Set this property to `true` to include target element's margins in the screenshot.
64 * When it is enabled, the `scrollTargetX`, `scrollTargetY` and `crop` rectangle coordinates are calculated from
65 * the corners where top and left (or bottom and right) margins intersect
66 */
67 includeMargins?: boolean;
68 /**
69 * Controls if element's borders should be included in the screenshot.
70 * Set this property to `true` to include target element's borders in the screenshot.
71 * When it is enabled, the `scrollTargetX`, `scrollTargetY` and `crop` rectangle coordinates are calculated from
72 * the corners where top and left (or bottom and right) internal edges of the element intersect
73 */
74 includeBorders?: boolean;
75 /**
76 * Controls if element's paddings should be included in the screenshot.
77 * Set this property to `true` to include target element's paddings in the screenshot.
78 * When it is enabled, the `scrollTargetX`, `scrollTargetY` and `crop` rectangle coordinates are calculated from
79 * the corners where top and left (or bottom and right) edges of the element's content area intersect
80 */
81 includePaddings?: boolean;
82 /**
83 * Specifies the X coordinate of the scrolling target point.
84 * If the target element is too big to fit into the browser window, the page will be scrolled to put this point
85 * to the center of the viewport. The coordinates of this point are calculated relative to the target element.
86 * If the numbers are positive, the point is positioned relative to the top-left corner of the element.
87 * If the numbers are negative, the point is positioned relative to the bottom-right corner.
88 * If the target element fits into the browser window, these properties have no effect.
89 */
90 scrollTargetX?: number;
91 /**
92 * Specifies the Y coordinate of the scrolling target point.
93 * If the target element is too big to fit into the browser window, the page will be scrolled to put this point
94 * to the center of the viewport. The coordinates of this point are calculated relative to the target element.
95 * If the numbers are positive, the point is positioned relative to the top-left corner of the element.
96 * If the numbers are negative, the point is positioned relative to the bottom-right corner.
97 * If the target element fits into the browser window, these properties have no effect.
98 */
99 scrollTargetY?: number;
100 }
101
102 interface MouseActionOptions extends ActionOptions {
103 /**
104 * Mouse pointer X coordinate that define a point where the action is performed or started.
105 * If an offset is a positive integer, coordinates are calculated relative to the top-left corner of the target element.
106 * If an offset is a negative integer, they are calculated relative to the bottom-right corner.
107 * The default is the center of the target element.
108 */
109 offsetX?: number;
110 /**
111 * Mouse pointer Y coordinate that define a point where the action is performed or started.
112 * If an offset is a positive integer, coordinates are calculated relative to the top-left corner of the target element.
113 * If an offset is a negative integer, they are calculated relative to the bottom-right corner.
114 * The default is the center of the target element.
115 */
116 offsetY?: number;
117 /**
118 * Indicate which modifier keys are to be pressed during the mouse action.
119 */
120 modifiers?: KeyModifiers;
121 }
122
123 interface ClickActionOptions extends MouseActionOptions {
124 /**
125 * The initial caret position if the action is performed on a text input field. A zero-based integer.
126 * The default is the length of the input field content.
127 */
128 caretPos?: number;
129 }
130
131 interface TypeActionOptions extends ClickActionOptions {
132 /**
133 * `true` to remove the current text in the target element, and false to leave the text as it is.
134 */
135 replace?: boolean;
136 /**
137 * `true` to insert the entire block of current text in a single keystroke (similar to a copy & paste function),
138 * and false to insert the current text character by character.
139 */
140 paste?: boolean;
141 }
142
143 interface DragToElementOptions extends MouseActionOptions {
144 /**
145 * Mouse pointer X coordinate that defines a point where the dragToElement action is finished.
146 * If an offset is a positive integer, coordinates are calculated relative to the top-left corner of the destination element.
147 * If an offset is a negative integer, they are calculated relative to the bottom-right corner.
148 * By default, the dragToElement action is finished in the center of the destination element.
149 */
150 destinationOffsetX?: number;
151 /**
152 * Mouse pointer Y coordinate that defines a point where the dragToElement action is finished.
153 * If an offset is a positive integer, coordinates are calculated relative to the top-left corner of the destination element.
154 * If an offset is a negative integer, they are calculated relative to the bottom-right corner.
155 * By default, the dragToElement action is finished in the center of the destination element.
156 */
157 destinationOffsetY?: number;
158 }
159
160 interface ResizeToFitDeviceOptions {
161 /**
162 * `true` for portrait screen orientation; `false` for landscape.
163 */
164 portraitOrientation?: boolean;
165 }
166
167 interface AssertionOptions {
168 /**
169 * The amount of time, in milliseconds, allowed for an assertion to pass before the test fails if a
170 * selector property or a client function was used in assertion.
171 */
172 timeout?: number;
173 /**
174 * By default, a Promise is not allowed to be passed to an assertion unless it is a selector property
175 * or the result of a client function. Setting this property to `true` overrides that default.
176 */
177 allowUnawaitedPromise?: boolean;
178 }
179
180 interface Assertion<E = any> {
181 /**
182 * Asserts that `actual` is deeply equal to `expected`.
183 *
184 * @param expected - An expected value.
185 * @param message - An assertion message that will be displayed in the report if the test fails.
186 * @param options - Assertion options.
187 */
188 eql(expected: E, message?: string, options?: AssertionOptions): TestControllerPromise;
189 /**
190 * Asserts that actual is deeply equal to expected.
191 *
192 * @param expected - An expected value.
193 * @param options - Assertion options.
194 */
195 eql(expected: E, options?: AssertionOptions): TestControllerPromise;
196 /**
197 * Assert that `actual` is not deeply equal to `unexpected`.
198 *
199 * @param unexpected - An unexpected value.
200 * @param message - An assertion message that will be displayed in the report if the test fails.
201 * @param options - Assertion options.
202 */
203 notEql(unexpected: E, message?: string, options?: AssertionOptions): TestControllerPromise;
204 /**
205 * Assert that `actual` is not deeply equal to `unexpected`.
206 *
207 * @param unexpected - An unexpected value.
208 * @param options - Assertion options.
209 */
210 notEql(unexpected: E, options?: AssertionOptions): TestControllerPromise;
211 /**
212 * Asserts that `actual` is truthy.
213 *
214 * @param message - An assertion message that will be displayed in the report if the test fails.
215 * @param options - Assertion options.
216 */
217 ok(message?: string, options?: AssertionOptions): TestControllerPromise;
218 /**
219 * Asserts that `actual` is truthy.
220 *
221 * @param options - Assertion options.
222 */
223 ok(options?: AssertionOptions): TestControllerPromise;
224 /**
225 * Asserts that `actual` is falsy.
226 *
227 * @param message - An assertion message that will be displayed in the report if the test fails.
228 * @param options - Assertion options.
229 */
230 notOk(message?: string, options?: AssertionOptions): TestControllerPromise;
231 /**
232 * Asserts that `actual` is falsy.
233 *
234 * @param options - Assertion options.
235 */
236 notOk(options?: AssertionOptions): TestControllerPromise;
237 /**
238 * Asserts that `actual` contains `expected`.
239 *
240 * @param expected - An expected value.
241 * @param message - An assertion message that will be displayed in the report if the test fails.
242 * @param options - Assertion options.
243 */
244 contains<R>(expected: EnsureString<E> | ElementOf<E> | Extend<E, R>, message?: string, options?: AssertionOptions): TestControllerPromise;
245 /**
246 * Asserts that `actual` contains `expected`.
247 *
248 * @param expected - An expected value.
249 * @param options - Assertion options.
250 */
251 contains<R>(expected: EnsureString<E> | ElementOf<E> | Extend<E, R>, options?: AssertionOptions): TestControllerPromise;
252 /**
253 * Asserts that `actual` not contains `unexpected`.
254 *
255 * @param unexpected - An unexpected value.
256 * @param message - An assertion message that will be displayed in the report if the test fails.
257 * @param options - Assertion options.
258 */
259 notContains<R>(unexpected: EnsureString<E> | ElementOf<E> | Extend<E, R>, message?: string, options?: AssertionOptions): TestControllerPromise;
260 /**
261 * Asserts that `actual` not contains `unexpected`.
262 *
263 * @param unexpected - An unexpected value.
264 * @param options - Assertion options.
265 */
266 notContains<R>(unexpected: EnsureString<E> | ElementOf<E> | Extend<E, R>, options?: AssertionOptions): TestControllerPromise;
267 /**
268 * Asserts that type of `actual` is `typeName`.
269 *
270 * @param typeName - The expected type of an `actual` value.
271 * @param message - An assertion message that will be displayed in the report if the test fails.
272 * @param options - Assertion options.
273 */
274 typeOf(typeName: 'function' | 'object' | 'number' | 'string' | 'boolean' | 'undefined' | 'null' | 'regexp', message?: string, options?: AssertionOptions): TestControllerPromise;
275 /**
276 * Asserts that type of `actual` is `typeName`.
277 *
278 * @param typeName - The expected type of an `actual` value.
279 * @param options - Assertion options.
280 */
281 typeOf(typeName: 'function' | 'object' | 'number' | 'string' | 'boolean' | 'undefined' | 'null' | 'regexp', options?: AssertionOptions): TestControllerPromise;
282 /**
283 * Asserts that type of `actual` is not `typeName`.
284 *
285 * @param typeName - An unexpected type of an `actual` value.
286 * @param message - An assertion message that will be displayed in the report if the test fails.
287 * @param options - Assertion options.
288 */
289 notTypeOf(typeName: 'function' | 'object' | 'number' | 'string' | 'boolean' | 'undefined' | 'null' | 'regexp', message?: string, options?: AssertionOptions): TestControllerPromise;
290 /**
291 * Asserts that type of `actual` is not `typeName`.
292 *
293 * @param typeName - An unexpected type of an `actual` value.
294 * @param options - Assertion options.
295 */
296 notTypeOf(typeName: 'function' | 'object' | 'number' | 'string' | 'boolean' | 'undefined' | 'null' | 'regexp', options?: AssertionOptions): TestControllerPromise;
297 /**
298 * Asserts that `actual` is strictly greater than `expected`.
299 *
300 * @param expected - A value that should be less than or equal to `actual`.
301 * @param message - An assertion message that will be displayed in the report if the test fails.
302 * @param options - Assertion options.
303 */
304 gt(expected: number, message?: string, options?: AssertionOptions): TestControllerPromise;
305 /**
306 * Asserts that `actual` is strictly greater than `expected`.
307 *
308 * @param expected - A value that should be less than or equal to `actual`.
309 * @param options - Assertion options.
310 */
311 gt(expected: number, options?: AssertionOptions): TestControllerPromise;
312 /**
313 * Asserts that `actual` is greater than or equal to `expected`.
314 *
315 * @param expected - A value that should be less than `actual`.
316 * @param message - An assertion message that will be displayed in the report if the test fails.
317 * @param options - Assertion options.
318 */
319 gte(expected: number, message?: string, options?: AssertionOptions): TestControllerPromise;
320 /**
321 * Asserts that `actual` is greater than or equal to `expected`.
322 *
323 * @param expected - A value that should be less than `actual`.
324 * @param options - Assertion options.
325 */
326 gte(expected: number, options?: AssertionOptions): TestControllerPromise;
327 /**
328 * Asserts that `actual` is less than `expected`.
329 *
330 * @param expected - A value that should be greater than or equal to `actual`.
331 * @param message - An assertion message that will be displayed in the report if the test fails.
332 * @param options - Assertion options.
333 */
334 lt(expected: number, message?: string, options?: AssertionOptions): TestControllerPromise;
335 /**
336 * Asserts that `actual` is less than `expected`.
337 *
338 * @param expected - A value that should be greater than or equal to `actual`.
339 * @param options - Assertion options.
340 */
341 lt(expected: number, options?: AssertionOptions): TestControllerPromise;
342 /**
343 * Asserts that `actual` is less than or equal to `expected`.
344 *
345 * @param expected - A value that should be greater than `actual`.
346 * @param message - An assertion message that will be displayed in the report if the test fails.
347 * @param options - Assertion options.
348 */
349 lte(expected: number, message?: string, options?: AssertionOptions): TestControllerPromise;
350 /**
351 * Asserts that `actual` is less than or equal to `expected`.
352 *
353 * @param expected - A value that should be greater than `actual`.
354 * @param options - Assertion options.
355 */
356 lte(expected: number, options?: AssertionOptions): TestControllerPromise;
357 /**
358 * Asserts that `actual` is within a range from `start` to `finish`. Bounds are inclusive.
359 *
360 * @param start - A lower bound of range (included).
361 * @param finish - An upper bound of range (included).
362 * @param message - An assertion message that will be displayed in the report if the test fails.
363 * @param options - Assertion options.
364 */
365 within(start: number, finish: number, message?: string, options?: AssertionOptions): TestControllerPromise;
366 /**
367 * Asserts that `actual` is within a range from `start` to `finish`. Bounds are inclusive.
368 *
369 * @param start - A lower bound of range (included).
370 * @param finish - An upper bound of range (included).
371 * @param options - Assertion options.
372 */
373 within(start: number, finish: number, options?: AssertionOptions): TestControllerPromise;
374 /**
375 * Asserts that `actual` is not within a range from `start` to `finish`. Bounds are inclusive.
376 *
377 * @param start - A lower bound of range (included).
378 * @param finish - An upper bound of range (included).
379 * @param message - An assertion message that will be displayed in the report if the test fails.
380 * @param options - Assertion options.
381 */
382 notWithin(start: number, finish: number, message?: string, options?: AssertionOptions): TestControllerPromise;
383 /**
384 * Asserts that `actual` is not within a range from `start` to `finish`. Bounds are inclusive.
385 *
386 * @param start - A lower bound of range (included).
387 * @param finish - An upper bound of range (included).
388 * @param options - Assertion options.
389 */
390 notWithin(start: number, finish: number, options?: AssertionOptions): TestControllerPromise;
391 /**
392 * Asserts that `actual` matches the regular expression.
393 *
394 * @param re - A regular expression that is expected to be matched.
395 * @param message - An assertion message that will be displayed in the report if the test fails.
396 * @param options - Assertion options.
397 */
398 match(re: RegExp, message?: string, options?: AssertionOptions): TestControllerPromise;
399 /**
400 * Asserts that `actual` matches the regular expression.
401 *
402 * @param re - A regular expression that is expected to be matched.
403 * @param options - Assertion options.
404 */
405 match(re: RegExp, options?: AssertionOptions): TestControllerPromise;
406 /**
407 * Asserts that `actual` does not match the regular expression.
408 *
409 * @param re - A regular expression that is expected to be matched.
410 * @param message - An assertion message that will be displayed in the report if the test fails.
411 * @param options - Assertion options.
412 */
413 notMatch(re: RegExp, message?: string, options?: AssertionOptions): TestControllerPromise;
414 /**
415 * Asserts that `actual` does not match the regular expression.
416 *
417 * @param re - A regular expression that is expected to be matched.
418 * @param options - Assertion options.
419 */
420 notMatch(re: RegExp, options?: AssertionOptions): TestControllerPromise;
421 }
422
423 interface ClientFunctionOptions {
424 /**
425 * Contains functions, variables or objects used by the client function internally.
426 * Properties of the `dependencies` object will be added to the client function's scope as variables.
427 */
428 dependencies?: {[key: string]: any};
429 /**
430 * If you need to call a client function from a Node.js callback, assign the current test controller to the `boundTestRun` option.
431 */
432 boundTestRun?: TestController;
433 }
434
435 interface ClientFunction<R = any, A extends any[]= any[]> {
436 /**
437 * Client function
438 *
439 * @param args - Function arguments.
440 */
441 (...args: A): Promise<R>;
442 /**
443 * Returns a new client function with a different set of options that includes options from the
444 * original function and new `options` that overwrite the original ones.
445 *
446 * @param options - New options.
447 */
448 with(options: ClientFunctionOptions): ClientFunction<R, A>;
449 }
450
451 interface ClientFunctionFactory {
452 <R, A extends any[]>(fn: (...args: A) => R, options?: ClientFunctionOptions): ClientFunction<R, A>
453 }
454
455 interface ClientScriptCommon {
456 page?: any;
457 }
458
459 interface ClientScriptContent extends ClientScriptCommon {
460 content?: string;
461 }
462
463 interface ClientScriptModule extends ClientScriptCommon {
464 module?: string;
465 }
466
467 interface ClientScriptPath extends ClientScriptCommon {
468 path?: string;
469 }
470
471 type ClientScript = ClientScriptContent | ClientScriptModule | ClientScriptPath;
472
473 interface TextRectangle {
474 /**
475 * Y-coordinate, relative to the viewport origin, of the bottom of the rectangle box.
476 */
477 bottom: number;
478 /**
479 * X-coordinate, relative to the viewport origin, of the left of the rectangle box.
480 */
481 left: number;
482 /**
483 * X-coordinate, relative to the viewport origin, of the right of the rectangle box.
484 */
485 right: number;
486 /**
487 * Y-coordinate, relative to the viewport origin, of the top of the rectangle box.
488 */
489 top: number;
490 /**
491 * Width of the rectangle box (This is identical to `right` minus `left`).
492 */
493 width: number;
494 /**
495 * Height of the rectangle box (This is identical to `bottom` minus `top`).
496 */
497 height: number;
498 }
499
500 interface NodeSnapshot {
501 /**
502 * The number of child HTML elements.
503 */
504 childElementCount: number;
505 /**
506 * The number of child nodes.
507 */
508 childNodeCount: number;
509 /**
510 * `true` if this node has child HTML elements.
511 */
512 hasChildElements: boolean;
513 /**
514 * `true` if this node has child nodes.
515 */
516 hasChildNodes: boolean;
517 /**
518 * The type of the node.
519 * See https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
520 */
521 nodeType: number;
522 /**
523 * The text content of the node and its descendants.
524 * See https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent
525 */
526 textContent: string;
527 /**
528 * Attributes of the element.
529 */
530 attributes?: {[name: string]: string};
531 /**
532 * The size of the element and its position relative to the viewport.
533 */
534 boundingClientRect?: TextRectangle;
535 /**
536 * For checkbox and radio input elements, their current state. For other elements, `undefined`.
537 */
538 checked?: boolean | undefined;
539 /**
540 * The list of element's classes.
541 */
542 classNames?: string[];
543 /**
544 * The inner height of the element, including padding but not the horizontal scrollbar height, border, or margin.
545 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/clientHeight
546 */
547 clientHeight?: number;
548 /**
549 * The width of the left border of the element.
550 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/clientLeft
551 */
552 clientLeft?: number;
553 /**
554 * The width of the top border of the element.
555 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/clientTop
556 */
557 clientTop?: number;
558 /**
559 * The inner width of the element, including padding but not the vertical scrollbar width, border, or margin.
560 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/clientWidth
561 */
562 clientWidth?: number;
563 /**
564 * `true` if the element is focused.
565 */
566 focused?: boolean;
567 /**
568 * The element's identifier.
569 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/id
570 */
571 id?: string;
572 /**
573 * The element's text content "as rendered".
574 * See https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute
575 */
576 innerText?: string;
577 /**
578 * The namespace URI of the element. If the element does not have a namespace, this property is set to null.
579 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/namespaceURI
580 */
581 namespaceURI?: string | null;
582 /**
583 * The height of the element including vertical padding and borders.
584 * See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetHeight
585 */
586 offsetHeight?: number;
587 /**
588 * The number of pixels that the upper left corner of the element is offset by to the left within the `offsetParent` node.
589 * See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetLeft
590 */
591 offsetLeft?: number;
592 /**
593 * The number of pixels that the upper left corner of the element is offset by to the top within the offsetParent node.
594 * See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetTop
595 */
596 offsetTop?: number;
597 /**
598 * The width of the element including vertical padding and borders.
599 * See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetWidth
600 */
601 offsetWidth?: number;
602 /**
603 * Indicates that `<option>` element is currently selected. For other elements, `undefined`.
604 */
605 selected?: boolean | undefined;
606 /**
607 * For `<select>` element, the index of the first selected `<option>` element. For other elements, `undefined`.
608 */
609 selectedIndex?: number | undefined;
610 /**
611 * The height of the element's content, including content not visible on the screen due to overflow.
612 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight
613 */
614 scrollHeight?: number;
615 /**
616 * The number of pixels that the element's content is scrolled to the left.
617 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollLeft
618 */
619 scrollLeft?: number;
620 /**
621 * The number of pixels that the element's content is scrolled upward.
622 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTop
623 */
624 scrollTop?: number;
625 /**
626 * Either the width in pixels of the element's content or the width of the element itself, whichever is greater.
627 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollWidth
628 */
629 scrollWidth?: number;
630 /**
631 * The computed values of element's CSS properties.
632 */
633 style?: {[prop: string]: string};
634 /**
635 * The name of the element.
636 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/tagName
637 */
638 tagName?: string;
639 /**
640 * For input elements, the current value in the control. For other elements, `undefined`.
641 */
642 value?: string | undefined;
643 /**
644 * `true` if the element is visible.
645 */
646 visible?: boolean;
647 /**
648 * `true` if the element has the specified class name.
649 *
650 * @param className - Name of the class.
651 */
652 hasClass?(className: string): boolean;
653 /**
654 * Returns the computed value of the CSS property.
655 *
656 * @param propertyName - The name of the CSS property.
657 */
658 getStyleProperty?(propertyName: string): string;
659 /**
660 * Returns the value of the attribute.
661 *
662 * @param attributeName - The name of the attribute.
663 */
664 getAttribute?(attributeName: string): string;
665 /**
666 * Returns the value of the property from the `boundingClientRect` object.
667 *
668 * @param propertyName - The name of the property.
669 */
670 getBoundingClientRectProperty?(propertyName: string): number;
671 /**
672 * `true` if the element has the attribute.
673 *
674 * @param attributeName - The name of the attribute.
675 */
676 hasAttribute?(attributeName: string): boolean;
677 }
678
679 // Request Hook
680 //----------------------------------------------------------------------------------------------------------------------
681
682 interface RequestHook {
683 /**
684 * The `onRequest` method is called before sending the request.
685 */
686 onRequest(requestEvent: object): Promise<void>;
687
688 /**
689 * The `onResponse` method is called after sending the request
690 */
691 onResponse(responseEvent: object): Promise<void>;
692 }
693
694 interface RequestHookConstructor {
695 /**
696 * Creates a request hook
697 * @param requestFilterRules - determines which requests the hook handles
698 * @param responseEventConfigureOpts - defines whether to pass the response headers and body to the onResponse method
699 * @returns {RequestHook}
700 */
701 new (requestFilterRules?: Array<any>, responseEventConfigureOpts?: object): RequestHook;
702 }
703
704 // Request Logger
705 //----------------------------------------------------------------------------------------------------------------------
706
707 interface RequestLoggerOptions {
708 /**
709 * Specifies whether the request headers should be logged.
710 */
711 logRequestHeaders?: boolean;
712 /**
713 * Specifies whether the request body should be logged.
714 */
715 logRequestBody?: boolean;
716 /**
717 * Specifies whether the request body should be stored as a String or a Buffer.
718 */
719 stringifyRequestBody?: boolean;
720 /**
721 * Specifies whether the response headers should be logged.
722 */
723 logResponseHeaders?: boolean;
724 /**
725 * Specifies whether the response body should be logged.
726 */
727 logResponseBody?: boolean;
728 /**
729 * Specifies whether the response body should be stored as a string or a Buffer.
730 */
731 stringifyResponseBody?: boolean;
732 }
733
734 interface LoggedRequest {
735 /**
736 * The user agent that sent the request.
737 */
738 userAgent: string;
739 /**
740 * The request part of the logged request
741 */
742 request: RequestData;
743 /**
744 * The response part of the logged request
745 */
746 response: ResponseData;
747 }
748
749 interface RequestData {
750 /**
751 * The URL where the request is sent.
752 */
753 url: string;
754 /**
755 * The request's HTTP method.
756 */
757 method: string;
758 /**
759 * Request headers in the property-value form. Logged if the `logRequestHeaders` option is set to `true`.
760 */
761 headers: Record<string, string>;
762 /**
763 * The response body. Logged if the `logResponseBody` option is set to `true`.
764 * A [Buffer](https://nodejs.org/api/buffer.html) or string depending on the `stringifyResponseBody` option.
765 */
766 body: string | any;
767 /**
768 * The timestamp that specifies when the request was intercepted.
769 */
770 timestamp: number;
771 }
772
773 interface ResponseData {
774 /**
775 * The status code received in the response.
776 */
777 statusCode: number;
778 /**
779 * Response headers in the property-value form. Logged if the `logResponseHeaders` option is set to true.
780 */
781 headers: Record<string, string>;
782 /**
783 * The response body.
784 * Logged if the `logResponseBody` option is set to true.
785 * A Buffer or string depending on the `stringifyResponseBody` option.
786 */
787 body: string | any;
788 /**
789 * The timestamp that specifies when the response was intercepted.
790 */
791 timestamp: number;
792 }
793
794 interface RequestLogger extends RequestHook {
795 /**
796 * Returns whether the logger contains a request that matches the predicate.
797 * @param predicate - The predicate
798 */
799 contains(predicate: (request: LoggedRequest) => boolean): Promise<boolean>;
800 /**
801 * Returns the number of requests that match the predicate.
802 * @param predicate - The predicate
803 */
804 count(predicate: (request: LoggedRequest) => boolean): Promise<number>;
805 /**
806 * Clears all logged requests.
807 */
808 clear(): void;
809 /**
810 * Returns an array of logged requests.
811 */
812 requests: Array<LoggedRequest>;
813 }
814
815 interface RequestLoggerFactory {
816 (
817 filter?: string | RegExp | object | ((req: any) => boolean),
818 options?: RequestLoggerOptions
819 ): RequestLogger;
820 }
821
822 // Request Mock
823 //----------------------------------------------------------------------------------------------------------------------
824
825 interface RequestMock {
826 /**
827 * Specifies requests to intercept
828 * @param filter - Specifies which requests should be mocked with a response that follows in the `respond` method.
829 */
830 onRequestTo(filter: string | RegExp | object | ((req: RequestOptions) => boolean)): RequestMock;
831 /**
832 * Specifies the mocked response.
833 * @param body - The mocked response body.
834 * @param statusCode - The response status code.
835 * @param headers - Custom headers added to the response in the property-value form.
836 */
837 respond(body?: object | string | ((req: RequestOptions, res: ResponseMock) => any), statusCode?: number, headers?: Record<string, string>): RequestMock;
838 }
839
840 interface RequestMockFactory {
841 (): RequestMock;
842 }
843
844 /**
845 * {@link https://devexpress.github.io/testcafe/documentation/reference/test-api/requestmock/respond.html#requestoptions See documentation}.
846 */
847 interface RequestOptions {
848 /** The request headers in the property-value form. */
849 headers: Record<string, string>;
850 /** The request body. */
851 body: Buffer;
852 /** The URL of the resource. */
853 url: string;
854 /** The protocol to use. Default: http:. */
855 protocol: string;
856 /** The alias for the host. */
857 hostname: string;
858 /** The domain name or IP address of the server to issue the request to. Default: localhost. */
859 host: string;
860 /** The port of the remote server. Default: 80. */
861 port: number;
862 /**
863 * The request path. Should include query string if any. E.G. '/index.html?page=12'. An exception
864 * is thrown when the request path contains illegal characters. Currently, only spaces are
865 * rejected but that may change in the future. Default: '/'.
866 */
867 path: string;
868 /** The HTTP request method. Default: 'GET'. */
869 method: string;
870 /**
871 * Credentials that were used for authentication in the current session using NTLM or Basic
872 * authentication. For HTTP Basic authentication, these are `username` and `password`. NTLM
873 * authentication additionally specifies `workstation` and `domain`.
874 * See {@link https://devexpress.github.io/testcafe/documentation/guides/advanced-guides/authentication.html#http-authentication HTTP Authentication}.
875 */
876 credentials: Record<string, string>;
877 /**
878 * If a proxy is used, the property contains information about its `host`, `hostname`, `port`,
879 * `proxyAuth`, `authHeader` and `bypassRules`.
880 */
881 proxy: Record<string, unknown>;
882 /**
883 * Specifies whether the request is an AJAX request (xhr or fetch).
884 */
885 isAjax: Boolean;
886 }
887
888 interface ResponseMock {
889 headers: Record<string, string>;
890 statusCode: number;
891 setBody(value: string): void;
892 }
893
894 interface Role {
895
896 }
897
898 interface RoleOptions {
899 /**
900 * Use this option to control which page is opened after you switch to the role.
901 *
902 * By default, TestCafe navigates back to the page that was opened previously to switching to the role.
903 * Set the `preserveUrl` option to true to save the URL to which the browser was redirected after logging in.
904 * TestCafe will navigate to the saved URL each time after you switch to this role.
905 *
906 * This option is useful if you store session-related data (like session ID) in the URL.
907 */
908 preserveUrl?: boolean;
909 }
910
911 interface RoleFactory {
912 (url: String, fn: (t: TestController) => Promise<any>, options?: RoleOptions): Role;
913 /**
914 * Creates an anonymous user role.
915 */
916 anonymous(): Role;
917 }
918
919 interface SelectorOptions {
920 /**
921 * If you need to call a selector from a Node.js callback, assign the current test
922 * controller to the `boundTestRun` option.
923 */
924 boundTestRun?: TestController;
925 /**
926 * The amount of time, in milliseconds, allowed for an element returned by the
927 * selector to appear in the DOM before the test fails.
928 */
929 timeout?: number;
930 /**
931 * Use this option to pass functions, variables or objects to selectors initialized with a function.
932 * The `dependencies` object's properties are added to the function's scope as variables.
933 */
934 dependencies?: {[key: string]: any};
935 /**
936 * `true` to additionally require the returned element to become visible within `options.timeout`.
937 */
938 visibilityCheck?: boolean;
939 }
940
941 interface SelectorAPI {
942 /**
943 * The number of child HTML elements.
944 */
945 childElementCount: Promise<number>;
946 /**
947 * The number of child nodes.
948 */
949 childNodeCount: Promise<number>;
950 /**
951 * `true` if this node has child HTML elements.
952 */
953 hasChildElements: Promise<boolean>;
954 /**
955 * `true` if this node has child nodes.
956 */
957 hasChildNodes: Promise<boolean>;
958 /**
959 * The type of the node.
960 * See https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
961 */
962 nodeType: Promise<number>;
963 /**
964 * The text content of the node and its descendants.
965 * See https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent
966 */
967 textContent: Promise<string>;
968 /**
969 * Attributes of the element.
970 */
971 attributes: Promise<{[name: string]: string}>;
972 /**
973 * The size of the element and its position relative to the viewport.
974 */
975 boundingClientRect: Promise<TextRectangle>;
976 /**
977 * For checkbox and radio input elements, their current state. For other elements, `undefined`.
978 */
979 checked: Promise<boolean | undefined>;
980 /**
981 * The list of element's classes.
982 */
983 classNames: Promise<string[]>;
984 /**
985 * The inner height of the element, including padding but not the horizontal scrollbar height, border, or margin.
986 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/clientHeight
987 */
988 clientHeight: Promise<number>;
989 /**
990 * The width of the left border of the element.
991 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/clientLeft
992 */
993 clientLeft: Promise<number>;
994 /**
995 * The width of the top border of the element.
996 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/clientTop
997 */
998 clientTop: Promise<number>;
999 /**
1000 * The inner width of the element, including padding but not the vertical scrollbar width, border, or margin.
1001 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/clientWidth
1002 */
1003 clientWidth: Promise<number>;
1004 /**
1005 * `true` if the element is focused.
1006 */
1007 focused: Promise<boolean>;
1008 /**
1009 * The element's identifier.
1010 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/id
1011 */
1012 id: Promise<string>;
1013 /**
1014 * The element's text content "as rendered".
1015 * See https://html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute
1016 */
1017 innerText: Promise<string>;
1018 /**
1019 * The namespace URI of the element. If the element does not have a namespace, this property is set to null.
1020 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/namespaceURI
1021 */
1022 namespaceURI: Promise<string | null>;
1023 /**
1024 * The height of the element including vertical padding and borders.
1025 * See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetHeight
1026 */
1027 offsetHeight: Promise<number>;
1028 /**
1029 * The number of pixels that the upper left corner of the element is offset by to the left within the `offsetParent` node.
1030 * See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetLeft
1031 */
1032 offsetLeft: Promise<number>;
1033 /**
1034 * The number of pixels that the upper left corner of the element is offset by to the top within the offsetParent node.
1035 * See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetTop
1036 */
1037 offsetTop: Promise<number>;
1038 /**
1039 * The width of the element including vertical padding and borders.
1040 * See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetWidth
1041 */
1042 offsetWidth: Promise<number>;
1043 /**
1044 * Indicates that `<option>` element is currently selected. For other elements, `undefined`.
1045 */
1046 selected: Promise<boolean | undefined>;
1047 /**
1048 * For `<select>` element, the index of the first selected `<option>` element. For other elements, `undefined`.
1049 */
1050 selectedIndex: Promise<number | undefined>;
1051 /**
1052 * The height of the element's content, including content not visible on the screen due to overflow.
1053 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight
1054 */
1055 scrollHeight: Promise<number>;
1056 /**
1057 * The number of pixels that the element's content is scrolled to the left.
1058 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollLeft
1059 */
1060 scrollLeft: Promise<number>;
1061 /**
1062 * The number of pixels that the element's content is scrolled upward.
1063 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollTop
1064 */
1065 scrollTop: Promise<number>;
1066 /**
1067 * Either the width in pixels of the element's content or the width of the element itself, whichever is greater.
1068 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollWidth
1069 */
1070 scrollWidth: Promise<number>;
1071 /**
1072 * The computed values of element's CSS properties.
1073 */
1074 style: Promise<{[prop: string]: string}>;
1075 /**
1076 * The name of the element.
1077 * See https://developer.mozilla.org/en-US/docs/Web/API/Element/tagName
1078 */
1079 tagName: Promise<string>;
1080 /**
1081 * For input elements, the current value in the control. For other elements, `undefined`.
1082 */
1083 value: Promise<string | undefined>;
1084 /**
1085 * `true` if the element is visible.
1086 */
1087 visible: Promise<boolean>;
1088 /**
1089 * `true` if the element has the specified class name.
1090 *
1091 * @param className - The name of the class.
1092 */
1093 hasClass(className: string): Promise<boolean>;
1094 /**
1095 * Returns the computed value of the CSS property.
1096 *
1097 * @param propertyName - The name of the CSS property.
1098 */
1099 getStyleProperty(propertyName: string): Promise<string>;
1100 /**
1101 * Returns the value of the attribute.
1102 *
1103 * @param attributeName - The name of the attribute.
1104 */
1105 getAttribute(attributeName: string): Promise<string>;
1106 /**
1107 * Returns the value of the property from the `boundingClientRect` object.
1108 *
1109 * @param propertyName - The name of the property.
1110 */
1111 getBoundingClientRectProperty(propertyName: string): Promise<number>;
1112 /**
1113 * `true` if the element has the attribute.
1114 *
1115 * @param attributeName - The name of the attribute.
1116 */
1117 hasAttribute(attributeName: string): Promise<boolean>;
1118 /**
1119 * Creates a selector that returns an element's `shadowRoot`.
1120 */
1121 shadowRoot(): Selector;
1122 /**
1123 * Creates a selector that returns an element by its index in the matching set.
1124 *
1125 * @param index - A zero-based index of the element. If negative, then counted from the end of the matching set.
1126 */
1127 nth(index: number): Selector;
1128 /**
1129 * Creates a selector that filters a matching set by the specified text.
1130 *
1131 * @param text - The text in the element.
1132 */
1133 withText(text: string): Selector;
1134 /**
1135 * Creates a selector that filters a matching set using the specified regular expression.
1136 *
1137 * @param re - The regular expression for the text in the element.
1138 */
1139 withText(re: RegExp): Selector;
1140 /**
1141 * Creates a selector that filters a matching set by the specified text. Selects elements whose text content *strictly matches* this text.
1142 *
1143 * @param text - The text in the element.
1144 */
1145 withExactText(text: string): Selector;
1146 /**
1147 * Creates a selector that filters a matching set by the specified attribute and, optionally, attribute value.
1148 *
1149 * @param attrName - The attribute name.
1150 * @param attrValue - The attribute value.You can omit this parameter to select elements that have
1151 * the `attrName` attribute regardless of the value.
1152 */
1153 withAttribute(attrName: string | RegExp, attrValue?: string | RegExp): Selector;
1154 /**
1155 * Creates a selector that filters a matching set by cssSelector.
1156 *
1157 * @param cssSelector - A CSS selector string.
1158 */
1159 filter(cssSelector: string): Selector;
1160 /**
1161 * Creates a selector that filters a matching set by the `filterFn` predicate.
1162 *
1163 * @param filterFn - The predicate.
1164 * @param filterFn `node` - The current DOM node.
1165 * @param filterFn `idx` - Index of the current node among other nodes in the matching set.
1166 * @param dependencies - Predicate dependencies.
1167 */
1168 filter(filterFn: (node: Element, idx: number) => boolean,
1169 dependencies?: {[key: string]: any}): Selector;
1170 /**
1171 * Creates a selector that filters a matching set leaving only visible elements.
1172 */
1173 filterVisible(): Selector;
1174 /**
1175 * Creates a selector that filters a matching set leaving only hidden elements.
1176 */
1177 filterHidden(): Selector;
1178 /**
1179 * Finds all descendants of all nodes in the matching set and filters them by `cssSelector`.
1180 *
1181 * @param cssSelector - A CSS selector string.
1182 */
1183 find(cssSelector: string): Selector;
1184 /**
1185 * Finds all descendants of all nodes in the matching set and filters them using `filterFn` predicate.
1186 *
1187 * @param filterFn - The predicate.
1188 * @param filterFn `node` - The current descendant node.
1189 * @param filterFn `idx` - A zero-based index of `node` among other descendant nodes.
1190 * @param filterFn `originNode` - A node from the left-hand selector's matching set whose descendants are being iterated.
1191 * @param dependencies - Predicate dependencies.
1192 */
1193 find(filterFn: (node: Element, idx: number, originNode: Element) => boolean,
1194 dependencies?: {[key: string]: any}): Selector;
1195 /**
1196 * Finds all parents of all nodes in the matching set (first element in the set will be the closest parent).
1197 */
1198 parent(): Selector;
1199 /**
1200 * Finds all parents of all nodes in the matching set and filters them by `index`.
1201 *
1202 * @param index - A zero-based index of the parent (0 is the closest). If negative, then counted from the end of the matching set.
1203 */
1204 parent(index: number): Selector;
1205 /**
1206 * Finds all parents of all nodes in the matching set and filters them by `cssSelector`.
1207 *
1208 * @param cssSelector - A CSS selector string.
1209 */
1210 parent(cssSelector: string): Selector;
1211 /**
1212 * Finds all parents of all nodes in the matching set and filters them by the `filterFn` predicate.
1213 *
1214 * @param filterFn - The predicate.
1215 * @param filterFn `node` - The current parent node.
1216 * @param filterFn `idx` - A zero-based index of `node` among other parent nodes.
1217 * @param filterFn `originNode` - A node from the left-hand selector's matching set whose parents are being iterated.
1218 * @param dependencies - Predicate dependencies.
1219 */
1220 parent(filterFn: (node: Element, idx: number, originNode: Element) => boolean,
1221 dependencies?: {[key: string]: any}): Selector;
1222 /**
1223 * Finds all child elements (not nodes) of all nodes in the matching set.
1224 */
1225 child(): Selector;
1226 /**
1227 * Finds all child elements (not nodes) of all nodes in the matching set and filters them by `index`.
1228 *
1229 * @param index - A zero-based index of the child. If negative, then counted from the end of the matching set.
1230 */
1231 child(index: number): Selector;
1232 /**
1233 * Finds all child elements (not nodes) of all nodes in the matching set and filters them by `cssSelector`.
1234 *
1235 * @param cssSelector - A CSS selector string.
1236 */
1237 child(cssSelector: string): Selector;
1238 /**
1239 * Finds all child elements (not nodes) of all nodes in the matching set and filters them by the `filterFn` predicate.
1240 *
1241 * @param filterFn - The predicate.
1242 * @param filterFn `node` - The current child node.
1243 * @param filterFn `idx` - A zero-based index of `node` among other child nodes.
1244 * @param filterFn `originNode` - A node from the left-hand selector's matching set children parents are being iterated.
1245 * @param dependencies - Predicate dependencies.
1246 */
1247 child(filterFn: (node: Element, idx: number, originNode: Element) => boolean,
1248 dependencies?: {[key: string]: any}): Selector;
1249 /**
1250 * Finds all sibling elements (not nodes) of all nodes in the matching set.
1251 */
1252 sibling(): Selector;
1253 /**
1254 * Finds all sibling elements (not nodes) of all nodes in the matching set and filters them by `index`.
1255 *
1256 * @param index - a zero-based index of the sibling. If negative, then counted from the end of the matching set.
1257 */
1258 sibling(index: number): Selector;
1259 /**
1260 * nds all sibling elements (not nodes) of all nodes in the matching set and filters them by `cssSelector`.
1261 *
1262 * @param cssSelector - A CSS selector string.
1263 */
1264 sibling(cssSelector: string): Selector;
1265 /**
1266 * Finds all sibling elements (not nodes) of all nodes in the matching set and filters them by the `filterFn` predicate.
1267 *
1268 * @param filterFn - The predicate.
1269 * @param filterFn `node` - The current sibling node.
1270 * @param filterFn `idx` - A zero-based index of `node` among other sibling nodes.
1271 * @param filterFn `originNode` - A node from the left-hand selector's matching set whose siblings are being iterated.
1272 * @param dependencies - Predicate dependencies.
1273 */
1274 sibling(filterFn: (node: Element, idx: number, originNode: Element) => boolean,
1275 dependencies?: {[key: string]: any}): Selector;
1276 /**
1277 * Finds all succeeding sibling elements (not nodes) of all nodes in the matching set.
1278 */
1279 nextSibling(): Selector;
1280 /**
1281 * Finds all succeeding sibling elements (not nodes) of all nodes in the matching set and filters them by `index`.
1282 *
1283 * @param index - A zero-based index of the succeeding sibling. If negative, then counted from the end of the matching set.
1284 */
1285 nextSibling(index: number): Selector;
1286 /**
1287 * Finds all succeeding sibling elements (not nodes) of all nodes in the matching set and filters them by `cssSelector`.
1288 *
1289 * @param cssSelector - A CSS selector string.
1290 */
1291 nextSibling(cssSelector: string): Selector;
1292 /**
1293 * Finds all succeeding sibling elements (not nodes) of all nodes in the matching set and filters them by the `filterFn` predicate.
1294 *
1295 * @param filterFn - The predicate.
1296 * @param filterFn `node` - The current succeeding sibling node.
1297 * @param filterFn `idx` - A zero-based index of `node` among other succeeding sibling nodes.
1298 * @param filterFn `originNode` - A node from the left-hand selector's matching set whose succeeding siblings are being iterated.
1299 * @param dependencies - Predicate dependencies.
1300 */
1301 nextSibling(filterFn: (node: Element, idx: number, originNode: Element) => boolean,
1302 dependencies?: {[key: string]: any}): Selector;
1303 /**
1304 * Finds all preceding sibling elements (not nodes) of all nodes in the matching set.
1305 */
1306 prevSibling(): Selector;
1307 /**
1308 * Finds all preceding sibling elements (not nodes) of all nodes in the matching set and filters them by `index`.
1309 *
1310 * @param index - A zero-based index of the preceding sibling. If negative, then counted from the end of the matching set.
1311 */
1312 prevSibling(index: number): Selector;
1313 /**
1314 * Finds all preceding sibling elements (not nodes) of all nodes in the matching set and filters them by `cssSelector`.
1315 *
1316 * @param cssSelector - A CSS selector string.
1317 */
1318 prevSibling(cssSelector: string): Selector;
1319 /**
1320 * Finds all preceding sibling elements (not nodes) of all nodes in the matching set and filters them by the `filterFn` predicate.
1321 *
1322 * @param filterFn - The predicate.
1323 * @param filterFn `node` - The current preceding sibling node.
1324 * @param filterFn `idx` - A zero-based index of `node` among other preceding sibling nodes.
1325 * @param filterFn `originNode` - A node from the left-hand selector's matching set whose preceding siblings are being iterated.
1326 * @param dependencies - Predicate dependencies.
1327 */
1328 prevSibling(filterFn: (node: Element, idx: number, originNode: Element) => boolean,
1329 dependencies?: {[key: string]: any}): Selector;
1330 /**
1331 * `true if` at least one matching element exists.
1332 */
1333 exists: Promise<boolean>;
1334 /**
1335 * The number of matching elements.
1336 */
1337 count: Promise<number>;
1338 /**
1339 * Adds custom selector properties.
1340 *
1341 * @param props - Property descriptors.
1342 * @param props `prop` - Property name.
1343 * @param props `[prop]` - The function that calculate property values. Executed on the client side in the browser.
1344 * @param props `node` - The matching DOM node for which custom property is calculated.
1345 */
1346 addCustomDOMProperties(props: {[prop: string]: (node: Element) => any}): Selector;
1347 /**
1348 * Adds custom selector methods.
1349 *
1350 * @param methods - Method descriptors.
1351 * @param methods `method` - The method name.
1352 * @param methods `[method]` - The function that contains method code. Executed on the client side in the browser.
1353 * @param methods `node` - The matching DOM node for which custom method is executed.
1354 * @param methods `methodParams` - Custom method parameters.
1355 */
1356 addCustomMethods(methods: {[method: string]: (node: Element, ...methodParams: any[]) => any }, opts?: {returnDOMNodes?: boolean}): Selector;
1357 /**
1358 * Returns a new selector with a different set of options that includes options from the
1359 * original selector and new `options` that overwrite the original ones.
1360 *
1361 * @param options - New options.
1362 */
1363 with(options?: SelectorOptions): Selector;
1364 }
1365
1366 interface Selector extends SelectorAPI {
1367 /**
1368 * Creates parametrized selector.
1369 *
1370 * @param args - Selector parameters.
1371 */
1372 (...args: any[]): SelectorPromise;
1373 }
1374
1375 interface SelectorPromise extends SelectorAPI, Promise<NodeSnapshot> {
1376 }
1377
1378 interface SelectorFactory {
1379 (
1380 init:
1381 | string
1382 | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection)
1383 | Selector
1384 | NodeSnapshot
1385 | SelectorPromise,
1386 options?: SelectorOptions
1387 ): Selector;
1388 }
1389
1390 interface HTTPAuthCredentials {
1391 /**
1392 * The user name for the account.
1393 */
1394 username: string;
1395 /**
1396 * The password for the account.
1397 */
1398 password: string;
1399 /**
1400 * The domain name.
1401 */
1402 domain?: string;
1403 /**
1404 * The workstation's ID in the local network.
1405 */
1406 workstation?: string;
1407 }
1408
1409 interface FixtureFn {
1410 /**
1411 * Declares a test fixture.
1412 *
1413 * @param name - The name of the fixture.
1414 * @param tagArgs - tag function arguments required to support the "fixture`${x}`" syntax
1415 */
1416 (name: string | TemplateStringsArray, ...tagArgs: any[]): this;
1417 /**
1418 * Specifies a webpage at which all tests in a fixture start.
1419 *
1420 * @param url - The URL of the webpage where tests start.
1421 * @param tagArgs - tag function arguments required to support the "fixture.page`${x}`" syntax
1422 * To test webpages in local directories, you can use the `file://` scheme or relative paths.
1423 */
1424 page(url: string | TemplateStringsArray, ...tagArgs: any[]): this;
1425 /**
1426 * Specifies HTTP Basic or Windows (NTLM) authentication credentials for all tests in the fixture.
1427 *
1428 * @param credentials - Contains credentials used for authentication.
1429 */
1430 httpAuth(credentials: HTTPAuthCredentials): this;
1431 /**
1432 * Specifies the fixture hook that is executed before the start of the first test in the fixture.
1433 *
1434 * @param fn - An asynchronous hook function that contains initialization or clean-up code.
1435 * @param fn `ctx` - A fixture context object used to share variables between fixture hooks and test code.
1436 */
1437 before(fn: (ctx: {[key: string]: any}) => Promise<any>): this;
1438 /**
1439 * Specifies the fixture hook that is executed after the end of the last test in the fixture.
1440 *
1441 * @param fn - An asynchronous hook function that contains initialization or clean-up code.
1442 * @param fn `ctx` - A fixture context object used to share variables between fixture hooks and test code.
1443 */
1444 after(fn: (ctx: {[key: string]: any}) => Promise<any>): this;
1445 /**
1446 * Specifies the hook that is executed on the start of each test in the fixture.
1447 *
1448 * @param fn - An asynchronous hook function that contains initialization or clean-up code.
1449 * @param fn `t` - The test controller used to access test run API.
1450 */
1451 beforeEach(fn: (t: TestController) => Promise<any>): this;
1452 /**
1453 * Specifies the hook that is executed on the end of each test in the fixture.
1454 *
1455 * @param fn - An asynchronous hook function that contains initialization or clean-up code.
1456 * @param fn `t` - The test controller used to access test run API.
1457 */
1458 afterEach(fn: (t: TestController) => Promise<any>): this;
1459 /**
1460 * Skips execution of all tests in the fixture.
1461 */
1462 skip: this;
1463 /**
1464 * Skips execution of all tests, except whose that are in this fixture.
1465 */
1466 only: this;
1467 /**
1468 * Disables page caching for tests in this fixture.
1469 */
1470 disablePageCaching: this;
1471 /**
1472 * WARNING: This feature is experimental and is not recommended for everyday use. It can be removed in the future TestCafe versions.
1473 *
1474 * Disables page reloading which would happen right before each test in this fixture.
1475 */
1476 disablePageReloads: this;
1477 /**
1478 * Specifies the additional information for all tests in the fixture. This information can be used in reports.
1479 *
1480 * @param key - The name of the metadata entry
1481 * @param value - The value of the metadata entry
1482 */
1483 meta(key: string, value: string): this;
1484 /**
1485 * Specifies the additional information for all tests in the fixture. This information can be used in reports.
1486 *
1487 * @param data - Key-value pairs
1488 */
1489 meta(data: object): this;
1490 /**
1491 * Attaches hooks to all tests in the fixture
1492 *
1493 * @param hooks - The set of the RequestHook subclasses
1494 */
1495 requestHooks(...hooks: object[]): this;
1496 /**
1497 * Injects scripts into pages visited during the fixture execution.
1498 *
1499 * @param scripts - Scripts that should be added to the tested pages.
1500 */
1501 clientScripts (scripts: ClientScript | ClientScript[]): this;
1502 }
1503
1504 interface TestFn {
1505 /**
1506 * Declares a test.
1507 *
1508 * @param name - The name of the test.
1509 * @param fn - An asynchronous function that contains test code.
1510 * @param fn `t` - The test controller used to access test run API.
1511 */
1512 (name: string, fn: (t: TestController) => Promise<any>): this;
1513 /**
1514 * Specifies a webpage at which test starts.
1515 *
1516 * @param url - The URL of the webpage at which this test starts.
1517 * To test webpages in local directories, you can use the `file://` scheme or relative paths.
1518 */
1519 page(url: string): this;
1520 /**
1521 * Specifies HTTP Basic or Windows (NTLM) authentication credentials for the test.
1522 *
1523 * @param credentials - Contains credentials used for authentication.
1524 */
1525 httpAuth(credentials: HTTPAuthCredentials): this;
1526 /**
1527 * Specifies hook that is executed on the start of the test.
1528 *
1529 * @param fn - An asynchronous hook function that contains initialization or clean-up code.
1530 * @param fn `t` - The test controller used to access test run API.
1531 */
1532 before(fn: (t: TestController) => Promise<any>): this;
1533 /**
1534 * Specifies hook that is executed on the end of the test.
1535 *
1536 * @param fn - An asynchronous hook function that contains initialization or clean-up code.
1537 * @param fn `t` - The test controller used to access test run API.
1538 */
1539 after(fn: (t: TestController) => Promise<any>): this;
1540 /**
1541 * Skips test execution.
1542 */
1543 skip: this;
1544 /**
1545 * Skips execution of all tests, except this one.
1546 */
1547 only: this;
1548 /**
1549 * Disables page caching for this test.
1550 */
1551 disablePageCaching: this;
1552 /**
1553 * WARNING: This feature is experimental and is not recommended for everyday use. It can be removed in the future TestCafe versions.
1554 *
1555 * Disables page reloading which would happen right before this test.
1556 */
1557 disablePageReloads: this;
1558 /**
1559 * Specifies the additional information for the test. This information can be used in reports.
1560 *
1561 * @param key - The name of the metadata entry
1562 * @param value - The value of the metadata entry
1563 */
1564 meta(key: string, value: string): this;
1565 /**
1566 * Specifies the additional information for the test. This information can be used in reports.
1567 *
1568 * @param data - Key-value pairs
1569 */
1570 meta(data: object): this;
1571 /**
1572 * Attaches hooks to the test
1573 *
1574 * @param hooks - The set of the RequestHook subclasses
1575 */
1576 requestHooks(...hooks: object[]): this;
1577 /**
1578 * Injects scripts into pages visited during the test execution.
1579 *
1580 * @param scripts - Scripts that should be added to the tested pages.
1581 */
1582 clientScripts (scripts: ClientScript | ClientScript[]): this;
1583 }
1584
1585 interface NativeDialogHistoryItem {
1586 /**
1587 * The type of the native dialog.
1588 */
1589 type: 'alert' | 'confirm' | 'beforeunload' | 'prompt';
1590 /**
1591 * Text of the dialog message.
1592 */
1593 text: string;
1594 /**
1595 * The URL of the page that invoked the dialog. Use it to determine if the dialog originated
1596 * from the main window or an `<iframe>`.
1597 */
1598 url: string;
1599 }
1600
1601 interface BrowserConsoleMessages {
1602 /**
1603 * Messages output to the browser console by the console.log() method.
1604 */
1605 log: string[];
1606 /**
1607 * Warning messages output to the browser console by the console.warn() method.
1608 */
1609 warn: string[];
1610 /**
1611 * Error messages output to the browser console by the console.error() method.
1612 */
1613 error: string[];
1614 /**
1615 * Information messages output to the browser console by the console.info() method.
1616 */
1617 info: string[];
1618 }
1619
1620 interface Browser {
1621 /**
1622 * The browser alias string specified when tests were launched.
1623 */
1624 alias: string;
1625 /**
1626 * The browser name.
1627 */
1628 name: string;
1629 /**
1630 * The browser version.
1631 */
1632 version: string;
1633 /**
1634 * The platform type.
1635 */
1636 platform: string;
1637 /**
1638 * `true` if the browser runs in headless mode.
1639 */
1640 headless: boolean;
1641 /**
1642 * The name and version of the operating system.
1643 */
1644 os: { name: string; version: string };
1645 /**
1646 * The name and version of the browser engine.
1647 */
1648 engine: { name: string; version: string };
1649 /**
1650 * The user agent string.
1651 */
1652 userAgent: string;
1653 /**
1654 * Formatted string with the browser's and operating system's name and version.
1655 */
1656 prettyUserAgent: string;
1657 }
1658
1659 type WindowDescriptor = unknown;
1660
1661 interface WindowFilterData {
1662 /**
1663 * The window title.
1664 */
1665 title: string;
1666
1667 /**
1668 * The window URL.
1669 */
1670 url: URL;
1671 }
1672
1673 interface TestController {
1674 /**
1675 * Dictionary that is shared between test hook functions and test code.
1676 */
1677 ctx: {[key: string]: any};
1678 /**
1679 * Dictionary that is shared between `fixture.before` and `fixture.after`, test hook functions and test code.
1680 */
1681 readonly fixtureCtx: {[key: string]: any};
1682 /**
1683 * Returns an object that contains browser information.
1684 */
1685 readonly browser: Browser;
1686 /**
1687 * Clicks a webpage element.
1688 *
1689 * @param selector - Identifies the webpage element being clicked.
1690 * @param options - A set of options that provide additional parameters for the action.
1691 */
1692 click(selector: string | Selector | NodeSnapshot | SelectorPromise | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection),
1693 options?: ClickActionOptions): TestControllerPromise;
1694 /**
1695 * Right-clicks a webpage element.
1696 *
1697 * @param selector - Identifies the webpage element being right-clicked.
1698 * @param options - A set of options that provide additional parameters for the action.
1699 */
1700 rightClick(selector: string | Selector | NodeSnapshot | SelectorPromise | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection),
1701 options?: ClickActionOptions): TestControllerPromise;
1702 /**
1703 * Double-clicks a webpage element.
1704 *
1705 * @param selector - Identifies the webpage element being double-clicked.
1706 * @param options - A set of options that provide additional parameters for the action.
1707 */
1708 doubleClick(selector: string | Selector | NodeSnapshot | SelectorPromise | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection),
1709 options?: ClickActionOptions): TestControllerPromise;
1710 /**
1711 * Hovers the mouse pointer over a webpage element.
1712 *
1713 * @param selector - Identifies the webpage element being hovered over.
1714 * @param options - A set of options that provide additional parameters for the action.
1715 */
1716 hover(selector: string | Selector | NodeSnapshot | SelectorPromise | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection),
1717 options?: MouseActionOptions): TestControllerPromise;
1718 /**
1719 * Drags an element by an offset.
1720 *
1721 * @param selector - Identifies the webpage element being dragged
1722 * @param dragOffsetX - An X-offset of the drop coordinates from the mouse pointer's initial position.
1723 * @param dragOffsetY - An Y-offset of the drop coordinates from the mouse pointer's initial position.
1724 * @param options - A set of options that provide additional parameters for the action.
1725 */
1726 drag(selector: string | Selector | NodeSnapshot | SelectorPromise | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection),
1727 dragOffsetX: number,
1728 dragOffsetY: number,
1729 options?: MouseActionOptions): TestControllerPromise;
1730 /**
1731 * Drags an element onto another one.
1732 *
1733 * @param selector - Identifies the webpage element being dragged.
1734 * @param destinationSelector - Identifies the webpage element that serves as the drop location.
1735 * @param options - A set of options that provide additional parameters for the action.
1736 */
1737 dragToElement(selector: string | Selector | NodeSnapshot | SelectorPromise | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection),
1738 destinationSelector: string | Selector | NodeSnapshot | SelectorPromise | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection),
1739 options?: DragToElementOptions): TestControllerPromise;
1740 /**
1741 * Types the specified text into an input element.
1742 *
1743 * @param selector - Identifies the webpage element that will receive input focus.
1744 * @param text - The text to be typed into the specified webpage element.
1745 * @param options - A set of options that provide additional parameters for the action.
1746 */
1747 typeText(selector: string | Selector | NodeSnapshot | SelectorPromise | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection),
1748 text: string,
1749 options?: TypeActionOptions): TestControllerPromise;
1750 /**
1751 * Selects text in input elements.
1752 *
1753 * @param selector - Identifies the webpage element whose text will be selected.
1754 * @param startPos - The start position of the selection. A zero-based integer.
1755 * @param endPos - The end position of the selection. A zero-based integer.
1756 * @param options - A set of options that provide additional parameters for the action.
1757 */
1758 selectText(selector: string | Selector | NodeSnapshot | SelectorPromise | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection),
1759 startPos?: number,
1760 endPos?: number,
1761 options?: ActionOptions): TestControllerPromise;
1762 /**
1763 * Selects `<textarea>` content.
1764 *
1765 * @param selector
1766 * @param startLine
1767 * @param startPos
1768 * @param endLine
1769 * @param endPos
1770 * @param options
1771 */
1772 selectTextAreaContent(selector: string | Selector | NodeSnapshot | SelectorPromise | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection),
1773 startLine?: number,
1774 startPos?: number,
1775 endLine?: number,
1776 endPos?: number,
1777 options?: ActionOptions): TestControllerPromise;
1778 /**
1779 * Performs selection within editable content
1780 *
1781 * @param startSelector - Identifies a webpage element from which selection starts. The start position of selection is the first character of the element's text.
1782 * @param endSelector - Identifies a webpage element at which selection ends. The end position of selection is the last character of the element's text.
1783 * @param options - A set of options that provide additional parameters for the action.
1784 */
1785 selectEditableContent(startSelector: string | Selector | NodeSnapshot | SelectorPromise | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection),
1786 endSelector: string | Selector | NodeSnapshot | SelectorPromise | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection),
1787 options?: ActionOptions): TestControllerPromise;
1788 /**
1789 * Presses the specified keyboard keys.
1790 *
1791 * @param keys - The sequence of keys and key combinations to be pressed.
1792 * @param options - A set of options that provide additional parameters for the action.
1793 */
1794 pressKey(keys: string, options?: ActionOptions): TestControllerPromise;
1795 /**
1796 * Pauses a test for a specified period of time.
1797 *
1798 * @param timeout - The pause duration, in milliseconds.
1799 */
1800 wait(timeout: number): TestControllerPromise;
1801 /**
1802 * Navigates to the specified URL.
1803 *
1804 * @param url - The URL to navigate to. Absolute or relative to the current page.
1805 * You can use the `file://` scheme or relative paths to navigate to a webpage in a local directory.
1806 */
1807 navigateTo(url: string): TestControllerPromise;
1808 /**
1809 * Populates the specified file upload input with file paths.
1810 *
1811 * @param selector - Identifies the input field to which file paths are written.
1812 * @param filePath - The path to the uploaded file, or several such paths. Relative paths resolve from the folder with the test file.
1813 */
1814 setFilesToUpload(selector: string | Selector | NodeSnapshot | SelectorPromise | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection),
1815 filePath: String | String[]): TestControllerPromise;
1816 /**
1817 * Removes all file paths from the specified file upload input.
1818 *
1819 * @param selector - Identifies the input field that needs to be cleared.
1820 */
1821 clearUpload(selector: string | Selector | NodeSnapshot | SelectorPromise | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection)): TestControllerPromise;
1822 /**
1823 * Takes a screenshot of the tested page.
1824 *
1825 * @param path - relative path to the screenshot file. Resolved from the screenshot directory specified by
1826 * using the `runner.screenshots` API method or the `screenshots-path` command line option.
1827 * If path doesn't have .png extension, it will be added automatically.
1828 */
1829 takeScreenshot(path?: string): TestControllerPromise;
1830 /**
1831 * Takes a screenshot of the tested page.
1832 *
1833 * @param options - TakeScreenshot Options
1834 */
1835 takeScreenshot(options: TakeScreenshotOptions): TestControllerPromise;
1836 /**
1837 * Takes a screenshot of the specified element.
1838 *
1839 * @param selector - Identifies the element for screenshot capturing.
1840 * @param path - relative path to the screenshot file. Resolved from the screenshot directory specified by
1841 * using the `runner.screenshots` API method or the `screenshots-path` command line option.
1842 * If path doesn't have .png extension, it will be added automatically.
1843 */
1844 takeElementScreenshot(selector: string | Selector | NodeSnapshot | SelectorPromise | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection),
1845 path?: string,
1846 options?: TakeElementScreenshotOptions): TestControllerPromise;
1847 /**
1848 * Sets the browser window size.
1849 *
1850 * @param width - The new width, in pixels.
1851 * @param height - The new height, in pixels.
1852 */
1853 resizeWindow(width: number, height: number): TestControllerPromise;
1854
1855 /**
1856 * Fits the browser window into a particular device.
1857 *
1858 * @param deviceName - The name of the device as listed at https://github.com/DevExpress/device-specs/blob/master/viewport-sizes.json.
1859 * @param options - Provide additional information about the device.
1860 */
1861 resizeWindowToFitDevice(deviceName: string, options?: ResizeToFitDeviceOptions): TestControllerPromise;
1862 /**
1863 * Maximizes the browser window.
1864 */
1865 maximizeWindow(): TestControllerPromise;
1866 /**
1867 * Switches the test's browsing context to the specified `<iframe>`.
1868 *
1869 * @param selector - Identifies an `<iframe>` on the tested page.
1870 */
1871 switchToIframe(selector: string | Selector | NodeSnapshot | SelectorPromise | ((...args: any[]) => Node | Node[] | NodeList | HTMLCollection)): TestControllerPromise;
1872 /**
1873 * Switches the test's browsing context from an `<iframe>` back to the main window.
1874 */
1875 switchToMainWindow(): TestControllerPromise;
1876
1877 /**
1878 * Opens a new browser window.
1879 *
1880 * @param url - The URL to open. Can be local or remote, absolute or relative.
1881 */
1882 openWindow(url: string): WindowDescriptorPromise;
1883
1884 /**
1885 * Closes a browser window.
1886 *
1887 * @param windowDescriptor - The target window. If this parameter is omitted, the currently active window is selected.
1888 */
1889 closeWindow(windowDescriptor?: WindowDescriptor): TestControllerPromise;
1890
1891 /**
1892 * Retrieves a `window` object that corresponds to the currently open window.
1893 */
1894 getCurrentWindow(): WindowDescriptorPromise;
1895
1896 /**
1897 * Activates the window that corresponds to the `window` object.
1898 *
1899 * @param windowDescriptor - The target window.
1900 */
1901 switchToWindow(windowDescriptor: WindowDescriptor): TestControllerPromise;
1902
1903 /**
1904 * Activates the first window that matches the criteria passed to the `filterFn` function
1905 *
1906 * @param filterFn - The predicate used to select windows.
1907 */
1908 switchToWindow(filterFn: (data: WindowFilterData) => boolean): TestControllerPromise;
1909
1910 /**
1911 * Activates the window that launched, or was active during the launch of, the currently active window.
1912 */
1913 switchToParentWindow(): TestControllerPromise;
1914
1915 /**
1916 * Activates the most recent of the previously active windows.
1917 */
1918 switchToPreviousWindow(): TestControllerPromise;
1919
1920 /**
1921 * Executes function on client and returns it's result.
1922 *
1923 * @param fn - A function to be executed on the client side.
1924 * @param options - Function options.
1925 */
1926 eval(fn: Function, options?: ClientFunctionOptions): Promise<any>;
1927 /**
1928 * Specifies handler function for the browser native dialogs.
1929 *
1930 * @param fn - A regular or client function that will be triggered whenever a native dialog is invoked. null to
1931 * remove the native dialog handler.
1932 * @param fn `type` - The type of the native dialog.
1933 * @param fn `text` - Text of the dialog message.
1934 * @param fn `url` - The URL of the page that invoked the dialog. Use it to determine if the dialog originated from
1935 * the main window or an `<iframe>`.
1936 * @param options - Handler options.
1937 */
1938 setNativeDialogHandler(fn: ((type: 'alert' | 'confirm' | 'beforeunload' | 'prompt', text: string, url: string) => any) | null,
1939 options?: ClientFunctionOptions): TestControllerPromise;
1940 /**
1941 * Returns a stack of history entries (i.e., an array in which the latest dialog has an index of 0). Each entry
1942 * corresponds to a certain native dialog that appears in the main window or in an `<iframe>`.
1943 */
1944 getNativeDialogHistory(): Promise<NativeDialogHistoryItem[]>;
1945 /**
1946 * Returns an object that contains messages output to the browser console.
1947 */
1948 getBrowserConsoleMessages(): Promise<BrowserConsoleMessages>;
1949 /**
1950 * Starts an assertion chain and specifies assertion actual value.
1951 *
1952 * @param actual - An actual value of the assertion.
1953 */
1954 expect<A>(actual: A | Promise<A>): Assertion<A>;
1955 /**
1956 * Pauses the test and switches to the step-by-step execution mode.
1957 */
1958 debug(): TestControllerPromise;
1959 /**
1960 * Specifies the speed of test execution.
1961 *
1962 * @param speed - Specifies the test speed. Must be a number between 1 (the fastest) and 0.01 (the slowest).
1963 */
1964 setTestSpeed(speed: number): TestControllerPromise;
1965 /**
1966 * Specifies the amount of time within which TestCafe waits for the `window.load` event to fire before starting the test.
1967 *
1968 * @param duration - Specifies the amount of time within which TestCafe waits for the `window.load` event to fire before starting the test.
1969 */
1970 setPageLoadTimeout(duration: number): TestControllerPromise;
1971 /**
1972 * Switches user role.
1973 *
1974 * @param role - The role you need to use further in the test.
1975 */
1976 useRole(role: Role): TestControllerPromise;
1977 /**
1978 * Attaches the hooks during a test run
1979 *
1980 * @param hooks - The set of RequestHook subclasses
1981 */
1982 addRequestHooks(...hooks: object[]): TestControllerPromise;
1983 /**
1984 * Detaches the hooks during a test run
1985 *
1986 * @param hooks - The set of RequestHook subclasses
1987 */
1988 removeRequestHooks(...hooks: object[]): TestControllerPromise;
1989 }
1990
1991 interface TestControllerPromise<T=any> extends TestController, Promise<T> {
1992 }
1993
1994 interface WindowDescriptorPromise extends TestControllerPromise<WindowDescriptor> {
1995 }
1996
1997 type ElementOf<T> = T extends (infer E)[] ? E : never;
1998 type Extend<T, E> = T extends E ? E : never;
1999 type EnsureString<T> = T extends string ? string : never;
2000
2001 type TlsOptions = import('tls').TlsOptions;
2002
2003 interface ScreenshotsOptions extends TakeScreenshotOptions {
2004 /**
2005 * Specifies the base directory where the screenshots are saved.
2006 */
2007 path: string;
2008 /**
2009 * Specifies that a screenshot should be taken whenever a test fails.
2010 */
2011 takeOnFails?: boolean;
2012 /**
2013 * Specifies a custom pattern to compose screenshot files' relative path and name.
2014 */
2015 pathPattern?: string;
2016 }
2017
2018 interface VideoOptions {
2019 /**
2020 * Specifies whether to save the entire recording as a single file.
2021 */
2022 singleFile?: boolean;
2023 /**
2024 * Specifies whether to record only failed tests.
2025 */
2026 failedOnly?: boolean;
2027 /**
2028 * Specifies the path to the FFmpeg codec executable.
2029 */
2030 ffmpegPath?: string;
2031 /**
2032 * Specifies a custom pattern that defines how TestCafe composes the relative path to a video file.
2033 */
2034 pathPattern?: string;
2035 }
2036
2037 interface DefaultEncodingOptions {
2038 /**
2039 * **NOTE:** overwrite output files without asking for a confirmation
2040 * @default true
2041 */
2042 y: boolean;
2043 /**
2044 * **NOTE:** use the time when a frame is read from the source as its timestamp
2045 *
2046 * **IMPORTANT:** must be specified before configuring the source
2047 * @default 1
2048 */
2049 'use_wallclock_as_timestamps': number;
2050 /**
2051 * **NOTE:** use stdin as a source
2052 * @default 'pipe:0'
2053 */
2054 i: string;
2055 /**
2056 * **NOTE:** use the H.264 video codec
2057 * @default 'libx264'
2058 */
2059 'c:v': string;
2060 /**
2061 * **NOTE:** use the `ultrafast` compression preset
2062 * @default 'ultrafast'
2063 */
2064 preset: string;
2065
2066 /**
2067 * **NOTE:** use the yuv420p pixel format (the most widely supported)
2068 * @default 'yuv420p'
2069 */
2070 'pix_fmt': string;
2071 /**
2072 * **NOTE:** scale input frames to make the frame height divisible by 2 (yuv420p's requirement)
2073 * @default 'scale=trunc(iw/2)*2:trunc(ih/2)*2'
2074 */
2075 vf: string;
2076 /**
2077 * Specifies a custom frame rate (FPS).
2078 * @default 30
2079 */
2080 r: number;
2081 }
2082
2083 interface VideoEncodingOptions extends Partial<DefaultEncodingOptions> {
2084 /**
2085 * https://ffmpeg.org/ffmpeg.html#Options
2086 *
2087 * custom ffmpeg options
2088 */
2089 [option: string]: unknown;
2090
2091 /**
2092 * Specifies the video's aspect ratio.
2093 *
2094 * Can be set to '4:3', '16:9', etc.
2095 */
2096 aspect?: string;
2097 }
2098
2099 type CompilerOptions = {
2100 [key in 'typescript']: object;
2101 };
2102
2103 interface TestCafe {
2104 /**
2105 * Creates the test runner that is used to configure and launch test tasks.
2106 */
2107 createRunner(): Runner;
2108
2109 /**
2110 * Creates the live mode test runner that is used to configure and launch test tasks.
2111 */
2112 createLiveModeRunner(): Runner;
2113
2114 /**
2115 * Creates a remote browser connection.
2116 */
2117 createBrowserConnection(): Promise<BrowserConnection>;
2118
2119 /**
2120 * Stops the TestCafe server. Forcibly closes all connections and pending test runs immediately.
2121 */
2122 close(): Promise<void>;
2123 }
2124
2125 interface Runner {
2126 /**
2127 * Configures the test runner to run tests from the specified files.
2128 *
2129 * @param source - The relative or absolute path to a test fixture file, or several such paths. You can use glob patterns to include (or exclude) multiple files.
2130 */
2131 src(source: string | string[]): this;
2132
2133 /**
2134 * Allows you to select which tests should be run.
2135 *
2136 * @param callback - The callback that determines if a particular test should be run.
2137 * @param callback `testName` - The name of the test.
2138 * @param callback `fixtureName` - The name of the test fixture.
2139 * @param callback `fixturePath` - The path to the test fixture file.
2140 * @param callback `testMeta` - The test metadata.
2141 * @param callback `fixtureMeta` - The fixture metadata.
2142 */
2143 filter(
2144 callback: (
2145 testName: string,
2146 fixtureName: string,
2147 fixturePath: string,
2148 testMeta: Record<string, string>,
2149 fixtureMeta: Record<string, string>
2150 ) => boolean
2151 ): this;
2152
2153 /**
2154 * Configures the test runner to run tests in the specified browsers.
2155 *
2156 * @param browser - A different browser alias for each browser type.
2157 */
2158 browsers(browser: string | string[]): this;
2159
2160 /**
2161 * Configures the test runner to run tests in the specified browsers.
2162 *
2163 * @param browser - The path to the browser's executable (path) and command line parameters (cmd).
2164 */
2165 browsers(browser: { path: string; cmd?: string }): this;
2166
2167 /**
2168 * Configures the test runner to run tests in the specified browsers.
2169 *
2170 * @param browser - The remote browser connection.
2171 */
2172 browsers(browser: BrowserConnection): this;
2173
2174 /**
2175 * Enables TestCafe to take screenshots of the tested webpages.
2176 *
2177 * @param path - The base path where the screenshots are saved. Note that to construct a complete path to these screenshots, TestCafe uses default path patterns.
2178 * @param takeOnFails - Specifies if screenshots should be taken automatically when a test fails.
2179 * @param pathPattern - The pattern to compose screenshot files' relative path and name.
2180 */
2181 screenshots(path: string, takeOnFails?: boolean, pathPattern?: string): this;
2182
2183 /**
2184 *
2185 * Enables TestCafe to take screenshots of the tested webpages.
2186 *
2187 * @param options - Screenshots options
2188 */
2189 screenshots(options: ScreenshotsOptions): this;
2190
2191 /**
2192 * https://devexpress.github.io/testcafe/documentation/using-testcafe/common-concepts/screenshots-and-videos.html#basic-video-options
2193 *
2194 * Enables TestCafe to take videos of the tested webpages.
2195 *
2196 * @param path - Output directory
2197 * @param options - Video options
2198 * @param encodingOptions - Video encoding options
2199 */
2200 video(path: string, options?: VideoOptions, encodingOptions?: VideoEncodingOptions): this;
2201
2202 /**
2203 * Configures TestCafe's reporting feature.
2204 *
2205 * @param name - The name of the reporter to use.
2206 * @param output - The stream or the name of the file to which the report is written.
2207 */
2208 reporter(name: string, output?: string | NodeJS.WritableStream): this;
2209
2210 /**
2211 * Configures TestCafe's reporting feature.
2212 *
2213 * @param reporters An array of reporters
2214 */
2215 reporter(reporters: Array<string | { name: string, output?: string | NodeJS.WritableStream }>): this;
2216
2217 /**
2218 * Specifies that tests should run concurrently.
2219 *
2220 * @param n - The number of browser instances that are invoked.
2221 */
2222 concurrency(n: number): this;
2223
2224 /**
2225 * Specifies a shell command that is executed before running tests. Use it to launch or deploy the application that is tested.
2226 *
2227 * @param command - The shell command to be executed.
2228 * @param initDelay - The amount of time (in milliseconds) allowed for the command to initialize the tested application.
2229 */
2230 startApp(command: string, initDelay?: number): this;
2231
2232 /**
2233 * Specifies the proxy server used in your local network to access the Internet. Allows you to bypass the proxy when accessing specific resources.
2234 *
2235 * @param host - The proxy server host.
2236 * @param bypassRules - A set of rules that specify which resources are accessed bypassing the proxy.
2237 */
2238 useProxy(host: string, bypassRules?: string | string[]): this;
2239
2240 /**
2241 * Injects scripts into pages visited during the test execution.
2242 *
2243 * @param scripts - Scripts that should be added to the tested pages.
2244 */
2245 clientScripts (scripts: ClientScript | ClientScript[]): this;
2246
2247 /**
2248 * Runs tests according to the current configuration. Returns the number of failed tests.
2249 */
2250 run(options?: Partial<RunOptions>): Promise<number>;
2251
2252 /**
2253 * Stops all the pending test tasks.
2254 */
2255 stop(): void;
2256
2257 /**
2258 * The absolute or relative path to the TypeScript configuration file. Relative paths resolve from the current directory (the directory from which you run TestCafe).
2259 */
2260 tsConfigPath(path: string): this;
2261
2262 /**
2263 * Specifies custom compiler options for built-in test file compilers.
2264 */
2265 compilerOptions(compilerOptions: CompilerOptions): this;
2266 }
2267
2268 interface BrowserConnection {
2269 /**
2270 * A URL that should be visited from a remote browser in order to connect it to the TestCafe server.
2271 */
2272 url: string;
2273
2274 /**
2275 * Fires when a remote browser connects to the TestCafe server.
2276 */
2277 once(event: 'ready', callback: Function): void;
2278 }
2279
2280 interface RunOptions {
2281 /**
2282 * Defines whether to continue running a test after a JavaScript error occurs on a page (`true`), or consider such a test failed (`false`).
2283 */
2284 skipJsErrors: boolean;
2285 /**
2286 * Defines whether to continue running a test after an uncaught error or unhandled promise rejection occurs on the server (`true`), or consider such a test failed (`false`).
2287 */
2288 skipUncaughtErrors: boolean;
2289 /**
2290 * Defines whether to enable the quarantine mode.
2291 */
2292 quarantineMode: boolean;
2293 /**
2294 * Specifies if tests run in the debug mode. If this option is enabled, test execution is paused before the first action or assertion allowing you to invoke the developer tools and debug. In the debug mode, you can execute the test step-by-step to reproduce its incorrect behavior. You can also use the Unlock Page switch in the footer to unlock the tested page and interact with its elements.
2295 */
2296 debugMode: boolean;
2297 /**
2298 * Specifies whether to enter the debug mode when a test fails. If enabled, the test is paused at the moment it fails, so that you can explore the tested page to determine what caused the failure.
2299 */
2300 debugOnFail: boolean;
2301 /**
2302 * Specifies the time (in milliseconds) within which selectors make attempts to obtain a node to be returned.
2303 */
2304 selectorTimeout: number;
2305 /**
2306 * Specifies the time (in milliseconds) within which TestCafe makes attempts to successfully execute an assertion if a selector property or a client function was passed as an actual value.
2307 */
2308 assertionTimeout: number;
2309 /**
2310 * Specifies the time (in milliseconds) TestCafe waits for the window.load event to fire after the DOMContentLoaded event. After the timeout passes or the window.load event is raised (whichever happens first), TestCafe starts the test. You can set this timeout to 0 to skip waiting for window.load.
2311 */
2312 pageLoadTimeout: number;
2313 /**
2314 * Specifies the test execution speed. A number between 1 (fastest) and 0.01 (slowest). If an individual action's speed is also specified, the action speed setting overrides the test speed.
2315 */
2316 speed: number;
2317 /**
2318 * Defines whether to stop a test run if a test fails. This allows you not to wait for all the tests to finish and to focus on the first error.
2319 */
2320 stopOnFirstFail: boolean;
2321 /**
2322 * Defines whether to disable checks for test and fixture directives in test files. Use this option to run dynamically loaded tests.
2323 */
2324 disableTestSyntaxValidation: boolean;
2325 /**
2326 * Defines whether to disable page caching during test execution.
2327 */
2328 disablePageCaching: boolean;
2329 }
2330
2331 interface TestCafeFactory {
2332 (
2333 hostname?: string,
2334 port1?: number,
2335 port2?: number,
2336 sslOptions?: TlsOptions,
2337 developmentMode?: boolean
2338 ): Promise<TestCafe>;
2339 }
2340 }
2341
2342
2343 /**
2344 * Creates a selector.
2345 *
2346 * @param init - Selector initializer.
2347 * @param options - Selector options.
2348 */
2349 export const Selector: SelectorFactory;
2350
2351 /**
2352 * Creates a client function.
2353 *
2354 * @param fn - Function code.
2355 * @param options - Function options.
2356 */
2357 export const ClientFunction: ClientFunctionFactory;
2358
2359 /**
2360 * Creates a request mock
2361 */
2362 export const RequestMock: RequestMockFactory;
2363
2364 /**
2365 * Creates a request logger
2366 */
2367 export const RequestLogger: RequestLoggerFactory;
2368
2369 /** The RequestHook class used to create a custom HTTP request hook **/
2370 export const RequestHook: RequestHookConstructor;
2371
2372 /**
2373 * Creates a user role.
2374 *
2375 * @param url - The URL of the login page.
2376 * @param fn - An asynchronous function that contains logic that authenticates the user.
2377 * @param fn `t` - The test controller used to access test run API.
2378 * @param options - Role options.
2379 */
2380 export const Role: RoleFactory;
2381
2382 /**
2383 * The test controller used to access test run API.
2384 */
2385 export const t: TestController;
2386
2387 const createTestCafe: TestCafeFactory;
2388
2389 export default createTestCafe;
2390}
2391
2392
2393
2394//
2395
2396declare const fixture: FixtureFn;
2397declare const test: TestFn;
2398
\No newline at end of file