-
-
Notifications
You must be signed in to change notification settings - Fork 737
/
Copy pathindex.d.ts
639 lines (585 loc) · 15.9 KB
/
index.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
// Project: https://github.com/codeception/codeceptjs/
/// <reference path="./types.d.ts" />
/// <reference path="./promiseBasedTypes.d.ts" />
/// <reference types="webdriverio" />
/// <reference path="./Mocha.d.ts" />
/// <reference types="joi" />
/// <reference types="playwright" />
declare namespace CodeceptJS {
type WithTranslation<T> = T &
// @ts-ignore
import("./utils").Translate<T, Translation.Actions>;
type Cookie = {
name: string;
value: string | boolean;
domain?: string,
path?: string,
};
type RetryConfig = {
/** Filter tests by string or regexp pattern */
grep?: string | RegExp;
/** Number of times to repeat scenarios of a Feature */
Feature?: number;
/** Number of times to repeat scenarios */
Scenario?: number;
/** Number of times to repeat Before hook */
Before?: number;
/** Number of times to repeat After hook */
After?: number;
/** Number of times to repeat BeforeSuite hook */
BeforeSuite?: number;
/** Number of times to repeat AfterSuite hook */
AfterSuite?: number;
};
type TimeoutConfig = {
/** Filter tests by string or regexp pattern */
grep: string | RegExp;
/** Set timeout for a scenarios of a Feature */
Feature: number;
/** Set timeout for scenarios */
Scenario: number;
};
type AiPrompt = {
role: string;
content: string;
}
type AiConfig = {
/** request function to send prompts to AI provider */
request: (messages: any) => Promise<string>,
/** custom prompts */
prompts?: {
/** Returns prompt to write CodeceptJS steps inside pause mode */
writeStep?: (html: string, input: string) => Array<AiPrompt>;
/** Returns prompt to heal step when test fails on CI if healing is on */
healStep?: (html: string, object) => Array<AiPrompt>;
/** Returns prompt to generate page object inside pause mode */
generatePageObject?: (html: string, extraPrompt?: string, rootLocator?: string) => Array<AiPrompt>;
},
/** max tokens to use */
maxTokens?: number,
/** configuration for processing HTML for GPT */
html?: {
/** max size of HTML to be sent to OpenAI to avoid token limit */
maxLength?: number,
/** should HTML be changed by removing non-interactive elements */
simplify?: boolean,
/** should HTML be minified before sending */
minify?: boolean,
interactiveElements?: Array<string>,
textElements?: Array<string>,
allowedAttrs?: Array<string>,
allowedRoles?: Array<string>,
}
}
type MainConfig = {
/** Pattern to locate CodeceptJS tests.
* Allows to enter glob pattern or an Array<string> of patterns to match tests / test file names.
*
* For tests in JavaScript:
*
* ```js
* tests: 'tests/**.test.js'
* ```
* For tests in TypeScript:
*
* ```js
* tests: 'tests/**.test.ts'
* ```
*/
tests: string;
/**
* Where to store failure screenshots, artifacts, etc
*
* ```js
* output: './output'
* ```
*/
output: string;
/**
* empty output folder for next run
*
* ```js
* emptyOutputFolder: true
* ```
*/
emptyOutputFolder?: boolean;
/**
* Pattern to filter tests by name.
* This option is useful if you plan to use multiple configs for different environments.
*
* To execute only tests with @firefox tag
*
* ```js
* grep: '@firefox'
* ```
*/
grep?: string;
/**
* Enable and configure helpers:
*
* ```js
* helpers: {
* Playwright: {
* url: 'https://mysite.com',
* browser: 'firefox'
* }
* }
* ```
*/
helpers?: {
/**
* Run web tests controlling browsers via Playwright engine.
*
* https://codecept.io/helpers/playwright
*
* Available commands:
* ```js
* I.amOnPage('/');
* I.click('Open');
* I.see('Welcome');
* ```
*/
Playwright?: PlaywrightConfig;
/**
* Run web tests controlling browsers via Puppeteer engine.
*
* https://codecept.io/helpers/puppeteer
*
* Available commands:
* ```js
* I.amOnPage('/');
* I.click('Open');
* I.see('Welcome');
* ```
*/
Puppeteer?: PuppeteerConfig;
/**
* Run web tests controlling browsers via WebDriver engine.
*
* Available commands:
* ```js
* I.amOnPage('/');
* I.click('Open');
* I.see('Welcome');
* ```
*
* https://codecept.io/helpers/webdriver
*/
WebDriver?: WebDriverConfig;
/**
* Execute REST API requests for API testing or to assist web testing.
*
* https://codecept.io/helpers/REST
*
* Available commands:
* ```js
* I.sendGetRequest('/');
* ```
*/
REST?: RESTConfig;
/**
* Use JSON assertions for API testing.
* Can be paired with REST or GraphQL helpers.
*
* https://codecept.io/helpers/JSONResponse
*
* Available commands:
* ```js
* I.seeResponseContainsJson({ user: { email: '[email protected]' } });
* ```
*/
JSONResponse?: any;
/** Enable AI features for development purposes */
AI?: any;
[key: string]: any;
},
/**
* Enable CodeceptJS plugins.
*
* https://codecept.io/plugins/
*
* Plugins listen to test events and extend functionality of CodeceptJS.
*
* Example:
*
* ```js
* plugins: {
* autoDelay: {
* enabled: true
* }
}
* ```
*/
plugins?: any;
/**
* Include page objects to access them via dependency injection
*
* ```js
* I: "./custom_steps.js",
* loginPage: "./pages/Login.js",
* User: "./pages/User.js",
* ```
* Configured modules can be injected by name in a Scenario:
*
* ```js
* Scenario('test', { I, loginPage, User })
* ```
*/
include?: any;
/**
* Set default tests timeout in seconds.
* Tests will be killed on no response after timeout.
*
* ```js
* timeout: 20,
* ```
*
* Can be customized to use different timeouts for a subset of tests:
*
* ```js
* timeout: [
* 10,
* {
* grep: '@slow',
* Scenario: 20
* }
* ]
* ```
*/
timeout?: number | Array<TimeoutConfig> | TimeoutConfig;
/**
* Configure retry strategy for tests
*
* To retry all tests 3 times:
*
* ```js
* retry: 3
* ```
*
* To retry only Before hook 3 times:
*
* ```js
* retry: {
* Before: 3
* }
* ```
*
* To retry tests marked as flaky 3 times, other 1 time:
*
* ```js
* retry: [
* {
* Scenario: 1,
* Before: 1
* },
* {
* grep: '@flaky',
* Scenario: 3
* Before: 3
* }
* ]
* ```
*/
retry?: number | Array<RetryConfig> | RetryConfig;
/** Disable registering global functions (Before, Scenario, etc). Not recommended */
noGlobals?: boolean;
/**
* [Mocha test runner options](https://mochajs.org/#configuring-mocha-nodejs), additional [reporters](https://codecept.io/reports/#xml) can be configured here.
*
* Example:
*
* ```js
* mocha: {
* "mocha-junit-reporter": {
* stdout: "./output/console.log",
* options: {
* mochaFile: "./output/result.xml",
* attachments: true //add screenshot for a failed test
* }
* }
* }
* ```
*/
mocha?: any;
/**
* [Execute code before](https://codecept.io/bootstrap/) tests are run.
*
* Can be either JS module file or async function:
*
* ```js
* bootstrap: async () => server.launch(),
* ```
* or
* ```js
* bootstrap: 'bootstrap.js',
* ```
*/
bootstrap?: (() => Promise<void>) | boolean | string;
/**
* [Execute code after tests](https://codecept.io/bootstrap/) finished.
*
* Can be either JS module file or async function:
*
* ```js
* teardown: async () => server.stop(),
* ```
* or
* ```js
* teardown: 'teardown.js',
* ```
*/
teardown?: (() => Promise<void>) | boolean | string;
/**
* [Execute code before launching tests in parallel mode](https://codecept.io/bootstrap/#bootstrapall-teardownall)
*
*/
bootstrapAll?: (() => Promise<void>) | boolean | string;
/**
* [Execute JS code after finishing tests in parallel mode](https://codecept.io/bootstrap/#bootstrapall-teardownall)
*/
teardownAll?: (() => Promise<void>) | boolean | string;
/** Enable [localized test commands](https://codecept.io/translation/) */
translation?: string;
/** Additional vocabularies for [localication](https://codecept.io/translation/) */
vocabularies?: Array<string>;
/**
* [Require additional JS modules](https://codecept.io/configuration/#require)
*
* Example:
* ```
* require: ["should"]
* ```
*/
require?: Array<string>;
/**
* Enable [BDD features](https://codecept.io/bdd/#configuration).
*
* Sample configuration:
* ```js
* gherkin: {
* features: "./features/*.feature",
* steps: ["./step_definitions/steps.js"]
* }
* ```
*/
gherkin?: {
/** load feature files by pattern. Multiple patterns can be specified as array */
features: string | Array<string>,
/** load step definitions from JS files */
steps: string | Array<string>
};
/**
* [AI](https://codecept.io/ai/) features configuration.
*/
ai?: AiConfig,
/**
* Enable full promise-based helper methods for [TypeScript](https://codecept.io/typescript/) project.
* If true, all helper methods are typed as asynchronous;
* Otherwise, it remains as it works in versions prior to 3.3.6
*/
fullPromiseBased?: boolean;
[key: string]: any;
};
type MockRequest = {
method: 'GET'|'PUT'|'POST'|'PATCH'|'DELETE'|string;
path: string;
queryParams?: object;
}
type MockResponse = {
status: number;
body?: object;
}
type MockInteraction = {
request: MockRequest;
response: MockResponse;
}
interface PageScrollPosition {
x: number;
y: number;
}
// Could get extended by user generated typings
interface Methods extends ActorStatic {}
interface I {}
interface IHook {}
interface IScenario {}
interface IFeature {
(title: string): FeatureConfig;
}
interface CallbackOrder extends Array<any> {}
interface SupportObject {
I: CodeceptJS.I;
}
namespace Translation {
interface Actions {}
}
// Extending JSDoc generated typings
interface Step {
isMetaStep(): this is MetaStep;
}
// Types who are not be defined by JSDoc
type actor = <T extends { [action: string]: (...args: any[]) => void }>(
customSteps?: T & ThisType<WithTranslation<Methods & T>>
) => WithTranslation<Methods & T>;
type ILocator =
| { id: string }
| { xpath: string }
| { css: string }
| { name: string }
| { frame: string }
| { android: string }
| { ios: string }
| { android: string; ios: string }
| { react: string }
| { vue: string }
| { shadow: string[] }
| { custom: string }
| { pw: string };
interface CustomLocators {}
interface OtherLocators { props?: object }
type LocatorOrString =
| string
| ILocator
| Locator
| OtherLocators
| CustomLocators[keyof CustomLocators];
type StringOrSecret = string | CodeceptJS.Secret;
interface HookCallback {
(args: SupportObject): void | Promise<void>;
}
interface Scenario extends IScenario {
only: IScenario;
skip: IScenario;
todo: IScenario;
}
interface Feature extends IFeature {
skip: IFeature;
}
interface IData {
Scenario: IScenario;
only: { Scenario: IScenario };
}
interface IScenario {
// Scenario.todo can be called only with a title.
(title: string, callback?: HookCallback): ScenarioConfig;
(
title: string,
opts: { [key: string]: any },
callback: HookCallback
): ScenarioConfig;
}
interface IHook {
(callback: HookCallback): void;
}
interface Globals {
codeceptjs: typeof codeceptjs;
}
interface IParameterTypeDefinition<T> {
name: string
regexp: readonly RegExp[] | readonly string[] | RegExp | string
transformer: (...match: string[]) => T
useForSnippets?: boolean
preferForRegexpMatch?: boolean
}
}
// Globals
declare const codecept_dir: string;
declare const output_dir: string;
declare function tryTo(...fn): Promise<boolean>;
declare function retryTo(...fn): Promise<null>;
declare const actor: CodeceptJS.actor;
declare const codecept_actor: CodeceptJS.actor;
declare const Helper: typeof CodeceptJS.Helper;
declare const codecept_helper: typeof CodeceptJS.Helper;
declare const pause: typeof CodeceptJS.pause;
declare const within: typeof CodeceptJS.within;
declare const session: typeof CodeceptJS.session;
declare const DataTable: typeof CodeceptJS.DataTable;
declare const DataTableArgument: typeof CodeceptJS.DataTableArgument;
declare const codeceptjs: typeof CodeceptJS.index;
declare const locate: typeof CodeceptJS.Locator.build;
declare function inject(): CodeceptJS.SupportObject;
declare function inject<T extends keyof CodeceptJS.SupportObject>(
name: T
): CodeceptJS.SupportObject[T];
declare const secret: typeof CodeceptJS.Secret.secret;
// BDD
declare const Given: typeof CodeceptJS.addStep;
declare const When: typeof CodeceptJS.addStep;
declare const Then: typeof CodeceptJS.addStep;
declare const Feature: typeof CodeceptJS.Feature;
declare const Scenario: CodeceptJS.Scenario;
declare const xScenario: CodeceptJS.IScenario;
declare const xFeature: CodeceptJS.IFeature;
declare function Data(data: any): CodeceptJS.IData;
declare function xData(data: any): CodeceptJS.IData;
declare function defineParameterType(options: CodeceptJS.IParameterTypeDefinition<any>): void
// Hooks
declare const BeforeSuite: CodeceptJS.IHook;
declare const AfterSuite: CodeceptJS.IHook;
declare const Background: CodeceptJS.IHook;
declare const Before: CodeceptJS.IHook;
declare const After: CodeceptJS.IHook;
// Plugins
declare const __: any
interface Window {
resq: any;
}
declare namespace NodeJS {
interface Process {
profile: string;
}
interface Global extends CodeceptJS.Globals {
codecept_dir: typeof codecept_dir;
output_dir: typeof output_dir;
actor: typeof actor;
codecept_actor: typeof codecept_actor;
Helper: typeof Helper;
codecept_helper: typeof codecept_helper;
pause: typeof pause;
within: typeof within;
session: typeof session;
DataTable: typeof DataTable;
DataTableArgument: typeof DataTableArgument;
locate: typeof locate;
inject: typeof inject;
secret: typeof secret;
// plugins
tryTo: typeof tryTo;
retryTo: typeof retryTo;
// BDD
Given: typeof Given;
When: typeof When;
Then: typeof Then;
DefineParameterType: typeof defineParameterType
}
}
declare namespace Mocha {
interface MochaGlobals {
Feature: typeof Feature;
Scenario: typeof Scenario;
xFeature: typeof xFeature;
xScenario: typeof xScenario;
Data: typeof Data;
xData: typeof xData;
BeforeSuite: typeof BeforeSuite;
AfterSuite: typeof AfterSuite;
Background: typeof Background;
Before: typeof Before;
After: typeof After;
}
interface Suite extends SuiteRunnable {
tags: any[];
comment: string;
feature: any;
}
interface Test extends Runnable {
artifacts: [],
tags: any[];
}
}
declare module "codeceptjs" {
export = codeceptjs;
}
declare module "@codeceptjs/helper" {
export = CodeceptJS.Helper;
}