forked from webdriverio/webdriverio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webdriverio.tpl.d.ts
760 lines (680 loc) · 25.1 KB
/
webdriverio.tpl.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
/// <reference types="node"/>
/// <reference types="webdriver"/>
// See https://github.com/DefinitelyTyped/DefinitelyTyped/issues/24419
interface Element { }
interface Node { }
interface NodeListOf<TNode = Node> { }
declare namespace WebdriverIO {
type LocationParam = 'x' | 'y';
interface LocationReturn {
x: number,
y: number
}
type SizeParam = 'width' | 'height';
interface SizeReturn {
width: number,
height: number
}
interface CSSProperty {
property: string;
value: any;
parsed?: {
// other
unit?: string;
// font-family
value?: any;
string: string;
// color
hex?: string;
alpha?: number;
type?: string;
rgba?: string
}
}
type JsonPrimitive = string | number | boolean | null;
type JsonObject = { [x: string]: JsonPrimitive | JsonObject | JsonArray };
type JsonArray = Array<JsonPrimitive | JsonObject | JsonArray>;
type JsonCompatible = JsonObject | JsonArray;
interface MultiRemoteBrowserOptions {
sessionId?: string
capabilities: WebDriver.DesiredCapabilities;
}
interface MultiRemoteCapabilities {
[instanceName: string]: MultiRemoteBrowserOptions;
}
interface ServiceOption {
[key: string]: any;
}
interface RunnerInstance {
initialise(): Promise<void>
shutdown(): Promise<void>
getWorkerCount(): number
run(args: any): NodeJS.EventEmitter
workerPool: any
}
interface ServiceClass {
new(options: ServiceOption, caps: WebDriver.DesiredCapabilities, config: Options): ServiceInstance
}
interface RunnerClass {
new(configFile: string, config: Omit<WebdriverIO.Config, 'capabilities' | keyof WebdriverIO.Hooks>): RunnerInstance
}
interface ServicePlugin extends ServiceClass {
default: ServiceClass
launcher?: ServiceClass
}
interface RunnerPlugin extends RunnerClass {
default: RunnerClass
launcher?: RunnerClass
}
interface ServiceInstance extends HookFunctions {
options?: Record<string, any>,
capabilities?: WebDriver.DesiredCapabilities,
config?: Config
}
type ServiceEntry = (
/**
* e.g. `services: ['@wdio/sauce-service']`
*/
string |
/**
* e.g. `services: [{ onPrepare: () => { ... } }]`
*/
HookFunctions |
/**
* e.g. `services: [CustomClass]`
*/
ServiceClass |
/**
* e.g. `services: [['@wdio/sauce-service', { ... }]]`
*/
[string, ServiceOption] |
/**
* e.g. `services: [[CustomClass, { ... }]]`
*/
[ServiceClass, ServiceOption]
)
interface Options {
/**
* Define the protocol you want to use for your browser automation.
* Currently only [`webdriver`](https://www.npmjs.com/package/webdriver) and
* [`devtools`](https://www.npmjs.com/package/devtools) are supported,
* as these are the main browser automation technologies available.
*/
automationProtocol?: string;
runner?: string;
/**
* Your cloud service username (only works for Sauce Labs, Browserstack, TestingBot,
* CrossBrowserTesting or LambdaTest accounts). If set, WebdriverIO will automatically
* set connection options for you.
*/
user?: string;
/**
* Your cloud service access key or secret key (only works for Sauce Labs, Browserstack,
* TestingBot, CrossBrowserTesting or LambdaTest accounts). If set, WebdriverIO will
* automatically set connection options for you.
*/
key?: string;
/**
* If running on Sauce Labs, you can choose to run tests between different datacenters:
* US or EU. To change your region to EU, add region: 'eu' to your config.
*/
region?: string;
/**
* Sauce Labs provides a headless offering that allows you to run Chrome and Firefox tests headless.
*/
headless?: boolean;
/**
* Define specs for test execution.
*/
specs?: string[];
/**
* Exclude specs from test execution.
*/
exclude?: string[];
/**
* Files to watch when running `wdio` with the `--watch` flag.
*/
filesToWatch?: string[],
/**
* An object describing various of suites, which you can then specify
* with the --suite option on the wdio CLI.
*/
suites?: Record<string, string[]>;
/**
* Maximum number of total parallel running workers.
*/
maxInstances?: number;
/**
* Maximum number of total parallel running workers per capability.
*/
maxInstancesPerCapability?: number;
capabilities?: WebDriver.DesiredCapabilities[] | MultiRemoteCapabilities;
/**
* Directory to store all testrunner log files (including reporter logs and wdio logs).
* If not set, all logs are streamed to stdout. Since most reporters are made to log to
* stdout, it is recommended to only use this option for specific reporters where it
* makes more sense to push report into a file (like the junit reporter, for example).
*
* When running in standalone mode, the only log generated by WebdriverIO will be the wdio log.
*/
outputDir?: string;
/**
* Shorten url command calls by setting a base URL.
*/
baseUrl?: string;
/**
* If you want your test run to stop after a specific number of test failures, use bail.
* (It defaults to 0, which runs all tests no matter what.) Note: Please be aware that
* when using a third party test runner (such as Mocha), additional configuration might
* be required.
*/
bail?: number;
/**
* The number of retry attempts for an entire specfile when it fails as a whole.
*/
specFileRetries?: number;
/**
* Delay in seconds between the spec file retry attempts
*/
specFileRetriesDelay?: number;
/**
* Whether or not retried specfiles should be retried immediately or deferred to the end of the queue
*/
specFileRetriesDeferred?: boolean
/**
* Default timeout for all `waitFor*` commands. (Note the lowercase f in the option name.)
* This timeout only affects commands starting with `waitFor*` and their default wait time.
*/
waitforTimeout?: number;
/**
* Default interval for all `waitFor*` commands to check if an expected state (e.g.,
* visibility) has been changed.
*/
waitforInterval?: number;
/**
* Defines the test framework to be used by the WDIO testrunner.
*/
framework?: string;
/**
* List of reporters to use. A reporter can be either a string, or an array of
* `['reporterName', { <reporter options> }]` where the first element is a string
* with the reporter name and the second element an object with reporter options.
*/
reporters?: (string | object)[];
/**
* Determines in which interval the reporter should check if they are synchronised
* if they report their logs asynchronously (e.g. if logs are streamed to a 3rd
* party vendor).
*/
reporterSyncInterval?: number;
/**
* Determines the maximum time reporters have to finish uploading all their logs
* until an error is being thrown by the testrunner.
*/
reporterSyncTimeout?: number;
/**
* Services take over a specific job you don't want to take care of. They enhance
* your test setup with almost no effort.
*/
services?: ServiceEntry[];
/**
* Node arguments to specify when launching child processes.
*/
execArgv?: string[];
}
interface RemoteOptions extends WebDriver.Options, HookFunctions, Omit<Options, 'capabilities'> { }
interface MultiRemoteOptions {
[instanceName: string]: WebDriver.DesiredCapabilities;
}
interface Suite {
error?: any;
}
interface Test {}
interface TestResult {
error?: any,
result?: any,
passed: boolean,
duration: number,
retries: { limit: number, attempts: number }
}
interface Results {
finished: number,
passed: number,
failed: number
}
interface HookFunctions {
/**
* Gets executed once before all workers get launched.
* @param config wdio configuration object
* @param capabilities list of capabilities details
*/
onPrepare?(
config: Config,
capabilities: WebDriver.DesiredCapabilities[]
): void;
/**
* Gets executed before a worker process is spawned and can be used to initialise specific service
* for that worker as well as modify runtime environments in an async fashion.
* @param cid capability id (e.g 0-0)
* @param caps object containing capabilities for session that will be spawn in the worker
* @param specs specs to be run in the worker process
* @param args object that will be merged with the main configuration once worker is initialised
* @param execArgv list of string arguments passed to the worker process
*/
onWorkerStart?(
cid: string,
caps: WebDriver.DesiredCapabilities,
specs: string[],
args: Config,
execArgv: string[]
): void;
/**
* Gets executed after all workers got shut down and the process is about to exit. An error
* thrown in the onComplete hook will result in the test run failing.
* @param exitCode runner exit code
* @param config wdio configuration object
* @param capabilities list of capabilities details
* @param results test results
*/
onComplete?(
exitCode: number,
config: Config,
capabilities: WebDriver.DesiredCapabilities,
results: Results
): void;
/**
* Gets executed when a refresh happens.
* @param oldSessionId session id of old session
* @param newSessionId session id of new session
*/
onReload?(
oldSessionId: string,
newSessionId: string
): void;
/**
* Gets executed before test execution begins. At this point you can access to all global
* variables like `browser`. It is the perfect place to define custom commands.
* @param capabilities list of capabilities details
* @param specs specs to be run in the worker process
* @param browser instance of created browser/device session
*/
before?(
capabilities: WebDriver.DesiredCapabilities,
specs: string[],
browser: BrowserObject
): void;
/**
* Runs before a WebdriverIO command gets executed.
* @param commandName command name
* @param args arguments that command would receive
*/
beforeCommand?(
commandName: string,
args: any[]
): void;
/**
* Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling
* beforeEach in Mocha). `stepData` and `world` are Cucumber framework specific properties.
* @param test details to current running test (or step in Cucumber)
* @param context context to current running test
* @param stepData Cucumber step data
* @param world Cucumber world
*/
beforeHook?(test: any, context: any, stepData?: any, world?: any): void;
/**
* Gets executed just before initialising the webdriver session and test framework. It allows you
* to manipulate configurations depending on the capability or spec.
* @param config wdio configuration object
* @param capabilities list of capabilities details
* @param specs list of spec file paths that are to be run
*/
beforeSession?(
config: Config,
capabilities: WebDriver.DesiredCapabilities,
specs: string[]
): void;
/**
* Hook that gets executed before the suite starts.
* @param suite suite details
*/
beforeSuite?(suite: Suite): void;
/**
* Function to be executed before a test (in Mocha/Jasmine) starts.
* @param test details to current running test (or step in Cucumber)
* @param context context to current running test
*/
beforeTest?(test: Test, context: any): void;
/**
* Hook that gets executed _after_ a hook within the suite ends (e.g. runs after calling
* afterEach in Mocha). `stepData` and `world` are Cucumber framework specific.
* @param test details to current running test (or step in Cucumber)
* @param context context to current running test
* @param result test result
* @param stepData Cucumber step data
* @param world Cucumber world
*/
afterHook?(test: any, context: any, result: TestResult, stepData?: any, world?: any): void;
/**
* Gets executed after all tests are done. You still have access to all global variables from
* the test.
* @param result number of total failing tests
* @param capabilities list of capabilities details
* @param specs list of spec file paths that are to be run
*/
after?(
result: number,
capabilities: WebDriver.DesiredCapabilities,
specs: string[]
): void;
/**
* Runs after a WebdriverIO command gets executed
* @param commandName command name
* @param args arguments that command would receive
* @param result result of the command
* @param error error in case something went wrong
*/
afterCommand?(
commandName: string,
args: any[],
result: any,
error?: Error
): void;
/**
* Gets executed right after terminating the webdriver session.
* @param config wdio configuration object
* @param capabilities list of capabilities details
* @param specs list of spec file paths that are to be run
*/
afterSession?(
config: Config,
capabilities: WebDriver.DesiredCapabilities,
specs: string[]
): void;
/**
* Hook that gets executed after the suite has ended
* @param suite suite details
*/
afterSuite?(suite: Suite): void;
/**
* Function to be executed after a test (in Mocha/Jasmine) ends.
* @param test details to current running test (or step in Cucumber)
* @param context context to current running test
* @param result test result
*/
afterTest?(test: Test, context: any, result: TestResult): void;
}
type _HooksArray = {
[K in keyof Pick<HookFunctions, "onPrepare" | "onWorkerStart" | "onComplete" | "before" | "after" | "beforeSession" | "afterSession">]: HookFunctions[K] | Array<HookFunctions[K]>;
};
type _Hooks = Omit<HookFunctions, "onPrepare" | "onWorkerStart" | "onComplete" | "before" | "after" | "beforeSession" | "afterSession">;
interface Hooks extends _HooksArray, _Hooks { }
type ActionTypes = 'press' | 'longPress' | 'tap' | 'moveTo' | 'wait' | 'release';
interface TouchAction {
action: ActionTypes,
x?: number,
y?: number,
element?: Element,
ms?: number
}
type TouchActionParameter = string | string[] | TouchAction | TouchAction[];
type TouchActions = TouchActionParameter | TouchActionParameter[];
type WaitForOptions = {
timeout?: number,
interval?: number,
timeoutMsg?: string,
reverse?: boolean,
}
type Matcher = {
name: string,
args: Array<string | object>
class?: string
}
type ReactSelectorOptions = {
props?: object,
state?: any[] | number | string | object | boolean
}
type MoveToOptions = {
xOffset?: number,
yOffset?: number
}
type DragAndDropOptions = {
duration?: number
}
type NewWindowOptions = {
windowName?: string,
windowFeatures?: string
}
type PDFPrintOptions = {
orientation?: string,
scale?: number,
background?: boolean,
width?: number,
height?: number,
top?: number,
bottom?: number,
left?: number,
right?: number,
shrinkToFit?: boolean,
pageRanges?: object[]
}
type ClickOptions = {
button?: number | string,
x?: number,
y?: number
}
type WaitUntilOptions = {
timeout?: number,
timeoutMsg?: string,
interval?: number
}
type DragAndDropCoordinate = {
x: number,
y: number
}
/**
* HTTP request data. (copied from the puppeteer-core package as there is currently
* no way to access these types otherwise)
*/
type ResourcePriority = 'VeryLow' | 'Low' | 'Medium' | 'High' | 'VeryHigh';
type MixedContentType = 'blockable' | 'optionally-blockable' | 'none';
type ReferrerPolicy = 'unsafe-url' | 'no-referrer-when-downgrade' | 'no-referrer' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin';
interface Request {
/**
* Request URL (without fragment).
*/
url: string;
/**
* Fragment of the requested URL starting with hash, if present.
*/
urlFragment?: string;
/**
* HTTP request method.
*/
method: string;
/**
* HTTP request headers.
*/
headers: Record<string, string>;
/**
* HTTP POST request data.
*/
postData?: string;
/**
* True when the request has POST data. Note that postData might still be omitted when this flag is true when the data is too long.
*/
hasPostData?: boolean;
/**
* The mixed content type of the request.
*/
mixedContentType?: MixedContentType;
/**
* Priority of the resource request at the time request is sent.
*/
initialPriority: ResourcePriority;
/**
* The referrer policy of the request, as defined in https://www.w3.org/TR/referrer-policy/
*/
referrerPolicy: ReferrerPolicy;
/**
* Whether is loaded via link preload.
*/
isLinkPreload?: boolean;
}
interface Matches extends Request {
/**
* body response of actual resource
*/
body: string | Buffer | JsonCompatible
/**
* HTTP response headers.
*/
responseHeaders: Record<string, string>;
/**
* HTTP response status code.
*/
statusCode: number;
}
type PuppeteerBrowser = Partial<import('puppeteer').Browser>;
type CDPSession = Partial<import('puppeteer').CDPSession>;
type MockOverwriteFunction = (request: Matches, client: CDPSession) => Promise<string | Record<string, any>>;
type MockOverwrite = string | Record<string, any> | MockOverwriteFunction;
type MockResponseParams = {
statusCode?: number | ((request: Matches) => number),
headers?: Record<string, string> | ((request: Matches) => Record<string, string>),
/**
* fetch real response before responding with mocked data. Default: true
*/
fetchResponse?: boolean
}
type MockFilterOptions = {
method?: string | ((method: string) => boolean),
headers?: Record<string, string> | ((headers: Record<string, string>) => boolean),
requestHeaders?: Record<string, string> | ((headers: Record<string, string>) => boolean),
responseHeaders?: Record<string, string> | ((headers: Record<string, string>) => boolean),
statusCode?: number | ((statusCode: number) => boolean),
postData?: string | ((payload: string | undefined) => boolean)
}
type ErrorCode = 'Failed' | 'Aborted' | 'TimedOut' | 'AccessDenied' | 'ConnectionClosed' | 'ConnectionReset' | 'ConnectionRefused' | 'ConnectionAborted' | 'ConnectionFailed' | 'NameNotResolved' | 'InternetDisconnected' | 'AddressUnreachable' | 'BlockedByClient' | 'BlockedByResponse'
type ThrottlePreset = 'offline' | 'GPRS' | 'Regular2G' | 'Good2G' | 'Regular3G' | 'Good3G' | 'Regular4G' | 'DSL' | 'WiFi' | 'online'
interface CustomThrottle {
offline: boolean,
downloadThroughput: number,
uploadThroughput: number,
latency: number
}
type ThrottleOptions = ThrottlePreset | CustomThrottle
type AddCommandFn<IsElement extends boolean = false> = (this: IsElement extends true ? Element : BrowserObject, ...args: any[]) => any
type OverwriteCommandFn<ElementKey extends keyof Element, BrowserKey extends keyof BrowserObject, IsElement extends boolean = false> = (this: IsElement extends true ? Element : BrowserObject, origCommand: IsElement extends true ? Element[ElementKey] : BrowserObject[BrowserKey], ...args: any[]) => any
interface Element extends BrowserObject {
selector: string;
elementId: string;
/**
* w3c
*/
"element-6066-11e4-a52e-4f735466cecf"?: string;
/**
* jsonwp
*/
ELEMENT?: string;
/**
* index in array of elements
* only applicable if the element found with `$$` command
*/
index?: number;
/**
* WebdriverIO.Element or WebdriverIO.BrowserObject
*/
parent: Element | WebdriverIO.BrowserObject;
/**
* true if element is a React component
*/
isReactElement?: boolean
/**
* add command to `element` scope
*/
addCommand(
name: string,
func: AddCommandFn<false>
): void;
// ... element commands ...
}
interface Mock {
/**
* list of requests made by the browser to that mock
*/
calls: Matches[];
// ... mock commands ...
}
interface ElementArray extends Array<Element> {
selector: string | Function;
parent: Element | WebdriverIO.BrowserObject;
foundWith: string;
props: any[];
}
interface Timeouts {
implicit?: number,
pageLoad?: number,
script?: number
}
interface Browser extends WebDriver.BaseClient {
config: Config;
options: RemoteOptions;
/**
* add command to `browser` or `element` scope
*/
addCommand<IsElement extends boolean = false>(
name: string,
func: AddCommandFn<IsElement>,
attachToElement?: IsElement
): void;
/**
* overwrite `browser` or `element` command
*/
overwriteCommand<ElementKey extends keyof Element, BrowserKey extends keyof BrowserObject, IsElement extends boolean = false>(
name: IsElement extends true ? ElementKey : BrowserKey,
func: OverwriteCommandFn<ElementKey, BrowserKey, IsElement>,
attachToElement?: IsElement
): void;
/**
* create custom selector
*/
addLocatorStrategy(
name: string,
func: (selector: string) => HTMLElement | HTMLElement[] | NodeListOf<HTMLElement>
): void
// ... browser commands ...
}
interface BrowserObject {
isMultiremote?: false;
/**
* @private
*/
_NOT_FIBER?: boolean
/**
* @private
*/
wdioRetries?: number
}
type MultiRemoteBrowserReference = Record<string, BrowserObject>
interface MultiRemoteBrowser extends Browser {
/**
* multiremote browser instance names
*/
instances: string[];
/**
* flag to indicate multiremote browser session
*/
isMultiremote: boolean;
}
type MultiRemoteBrowserObject = MultiRemoteBrowser & MultiRemoteBrowserReference
interface Config extends Options, Omit<WebDriver.Options, "capabilities">, Hooks {
/**
* internal usage only. To run in watch mode see https://webdriver.io/docs/watcher.html
*/
watch?: boolean;
runnerEnv?: Record<string, any>;
}
interface AddValueOptions {
translateToUnicode?: boolean
}
}