codeceptjs 3.3.6 → 3.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/basics.md +2 -3
- package/docs/bdd.md +33 -0
- package/docs/best.md +8 -8
- package/docs/build/Appium.js +60 -22
- package/docs/build/GraphQL.js +6 -6
- package/docs/build/Nightmare.js +4 -4
- package/docs/build/Playwright.js +102 -39
- package/docs/build/Polly.js +0 -0
- package/docs/build/Protractor.js +25 -25
- package/docs/build/Puppeteer.js +7 -7
- package/docs/build/SeleniumWebdriver.js +0 -0
- package/docs/build/TestCafe.js +12 -12
- package/docs/build/WebDriver.js +32 -32
- package/docs/changelog.md +36 -1
- package/docs/helpers/Appium.md +103 -79
- package/docs/helpers/GraphQL.md +6 -6
- package/docs/helpers/Playwright.md +280 -245
- package/docs/helpers/Puppeteer.md +1 -1
- package/docs/helpers/REST.md +1 -1
- package/docs/helpers/WebDriver.md +2 -2
- package/docs/playwright.md +14 -0
- package/docs/quickstart.md +40 -13
- package/docs/translation.md +83 -56
- package/docs/typescript.md +49 -3
- package/docs/wiki/Books-&-Posts.md +0 -0
- package/docs/wiki/Community-Helpers-&-Plugins.md +0 -0
- package/docs/wiki/Converting-Playwright-to-Istanbul-Coverage.md +0 -0
- package/docs/wiki/Examples.md +0 -0
- package/docs/wiki/Google-Summer-of-Code-(GSoC)-2020.md +0 -0
- package/docs/wiki/Home.md +0 -0
- package/docs/wiki/Release-Process.md +0 -0
- package/docs/wiki/Roadmap.md +0 -0
- package/docs/wiki/Tests.md +0 -0
- package/docs/wiki/Upgrading-to-CodeceptJS-3.md +0 -0
- package/docs/wiki/Videos.md +0 -0
- package/lib/codecept.js +3 -1
- package/lib/command/definitions.js +26 -2
- package/lib/command/generate.js +23 -9
- package/lib/command/init.js +32 -7
- package/lib/command/run.js +5 -1
- package/lib/container.js +15 -15
- package/lib/helper/Appium.js +60 -22
- package/lib/helper/GraphQL.js +6 -6
- package/lib/helper/Nightmare.js +4 -4
- package/lib/helper/Playwright.js +102 -39
- package/lib/helper/Protractor.js +25 -25
- package/lib/helper/Puppeteer.js +7 -7
- package/lib/helper/TestCafe.js +12 -12
- package/lib/helper/WebDriver.js +32 -32
- package/lib/helper/errors/ElementNotFound.js +1 -1
- package/lib/helper/extras/PlaywrightRestartOpts.js +0 -2
- package/lib/interfaces/bdd.js +26 -1
- package/lib/listener/artifacts.js +19 -0
- package/lib/rerun.js +12 -13
- package/lib/step.js +5 -5
- package/lib/translation.js +32 -0
- package/package.json +11 -17
- package/translations/ru-RU.js +1 -0
- package/typings/index.d.ts +29 -1
- package/typings/promiseBasedTypes.d.ts +10466 -0
- package/typings/types.d.ts +62 -12
- package/CHANGELOG.md +0 -2340
|
@@ -2096,7 +2096,7 @@ I.waitUrlEquals('http://127.0.0.1:8000/info');
|
|
|
2096
2096
|
- `sec` **[number][8]** (optional, `1` by default) time in seconds to wait
|
|
2097
2097
|
⚠️ returns a _promise_ which is synchronized internally by recorder
|
|
2098
2098
|
|
|
2099
|
-
: https://github.com/GoogleChrome/puppeteer
|
|
2099
|
+
[1]: https://github.com/GoogleChrome/puppeteer
|
|
2100
2100
|
|
|
2101
2101
|
[2]: https://codecept.io/helpers/Puppeteer-firefox
|
|
2102
2102
|
|
package/docs/helpers/REST.md
CHANGED
|
@@ -202,7 +202,7 @@ I.setRequestTimeout(10000); // In milliseconds
|
|
|
202
202
|
|
|
203
203
|
- `newTimeout` **[number][5]** timeout in milliseconds
|
|
204
204
|
|
|
205
|
-
: https://github.com/axios/axios
|
|
205
|
+
[1]: https://github.com/axios/axios
|
|
206
206
|
|
|
207
207
|
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
|
|
208
208
|
|
|
@@ -32,7 +32,7 @@ Type: [object][16]
|
|
|
32
32
|
- `host` **[string][17]?** WebDriver host to connect.
|
|
33
33
|
- `port` **[number][20]?** WebDriver port to connect.
|
|
34
34
|
- `protocol` **[string][17]?** protocol for WebDriver server.
|
|
35
|
-
- `path` **[string][17]?** path to WebDriver server
|
|
35
|
+
- `path` **[string][17]?** path to WebDriver server.
|
|
36
36
|
- `restart` **[boolean][29]?** restart browser between tests.
|
|
37
37
|
- `smartWait` **([boolean][29] | [number][20])?** **enables [SmartWait][33]**; wait for additional milliseconds for element to appear. Enable for 5 secs: "smartWait": 5000.
|
|
38
38
|
- `disableScreenshots` **[boolean][29]?** don't save screenshots on failure.
|
|
@@ -2250,7 +2250,7 @@ I.waitUrlEquals('http://127.0.0.1:8000/info');
|
|
|
2250
2250
|
- `sec` **[number][20]** (optional, `1` by default) time in seconds to wait
|
|
2251
2251
|
⚠️ returns a _promise_ which is synchronized internally by recorder
|
|
2252
2252
|
|
|
2253
|
-
: http://webdriver.io/
|
|
2253
|
+
[1]: http://webdriver.io/
|
|
2254
2254
|
|
|
2255
2255
|
[2]: https://codecept.io/webdriver/#testing-with-webdriver
|
|
2256
2256
|
|
package/docs/playwright.md
CHANGED
|
@@ -580,6 +580,20 @@ async setPermissions() {
|
|
|
580
580
|
|
|
581
581
|
> [▶ Learn more about Helpers](https://codecept.io/helpers/)
|
|
582
582
|
|
|
583
|
+
## Timezone change
|
|
584
|
+
|
|
585
|
+
Sometimes it's useful to test browser in different timezones. You can change timezone this way:
|
|
586
|
+
|
|
587
|
+
```js
|
|
588
|
+
Scenario("Test in a different timezone", ({ I }) => {
|
|
589
|
+
I.restartBrowser({ timezoneId: 'America/Phoenix' });
|
|
590
|
+
I.amOnPage("/");
|
|
591
|
+
// ...
|
|
592
|
+
// Reset timezone to default one (taken from OS)
|
|
593
|
+
I.restartBrowser();
|
|
594
|
+
});
|
|
595
|
+
```
|
|
596
|
+
Other context options: https://playwright.dev/docs/api/class-browser#browser-new-context
|
|
583
597
|
|
|
584
598
|
## Configuring CI
|
|
585
599
|
|
package/docs/quickstart.md
CHANGED
|
@@ -62,26 +62,53 @@ After CodeceptJS is installed, try running **demo tests** using this commands:
|
|
|
62
62
|
|
|
63
63
|
---
|
|
64
64
|
|
|
65
|
+
### Init
|
|
66
|
+
|
|
65
67
|
To start a new project initialize CodeceptJS to create main config file: `codecept.conf.js`.
|
|
66
68
|
|
|
67
69
|
```
|
|
68
70
|
npx codeceptjs init
|
|
69
71
|
```
|
|
70
72
|
|
|
71
|
-
Answer questions, agree on defaults
|
|
73
|
+
Answer questions, agree on defaults:
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
| Question | Default Answer | Alternative
|
|
77
|
+
|---|---|---|
|
|
78
|
+
| Do you plan to write tests in TypeScript? | **n** (No) | or [learn how to use TypeScript](/typescript)
|
|
79
|
+
| Where are your tests located? | `**./*_test.js` | or any glob pattern like `**.spec.js`
|
|
80
|
+
| What helpers do you want to use? | **Playwright** | Which helper to use for: [web testing](https://codecept.io/basics/#architecture), [mobile testing](https://codecept.io/mobile/), [API testing](https://codecept.io/api/)
|
|
81
|
+
| Where should logs, screenshots, and reports to be stored? | `./output` | path to store artifacts and temporary files
|
|
82
|
+
| Do you want to enable localization for tests? | **n** English (no localization) | or write [localized tests](https://codecept.io/translation/) in your language
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
Sample output:
|
|
72
86
|
|
|
87
|
+
```js
|
|
88
|
+
? Do you plan to write tests in TypeScript? 'No'
|
|
89
|
+
? Where are your tests located? '**./*_test.js'
|
|
90
|
+
? What helpers do you want to use? 'Playwright'
|
|
91
|
+
? Where should logs, screenshots, and reports to be stored? '**./output**'
|
|
92
|
+
? Do you want to enable localization for tests? 'English (no localization)'
|
|
73
93
|
```
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
94
|
+
|
|
95
|
+
For Playwright helper provide a website to be tested and browser to be used:
|
|
96
|
+
|
|
97
|
+
| Question | Default Answer | Alternative
|
|
98
|
+
|---|---|---|
|
|
99
|
+
| Base url of site to be tested | http://localhost | Base URL of website you plan to test. Use http://github.com or [sample checkout page](https://getbootstrap.com/docs/5.2/examples/checkout/) if you just want to play around
|
|
100
|
+
| Show browser window | **y** Yes | or run browser in **headless mode**
|
|
101
|
+
| Browser in which testing will be performed | **chromium** | or run tests in firefox, webkit (which is opensource version of Safari) or launch electron app
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
? [Playwright] Base url of site to be tested 'http://mysite.com'
|
|
105
|
+
? [Playwright] Show browser window 'Yes'
|
|
106
|
+
? [Playwright] Browser in which testing will be performed. Possible options: chromium, firefox, webkit or electron 'chromium'
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Create first feature and test when asked
|
|
111
|
+
|
|
85
112
|
Open a newly created file in your favorite JavaScript editor.
|
|
86
113
|
The file should look like this:
|
|
87
114
|
|
|
@@ -106,7 +133,7 @@ Scenario('test something', ({ I }) => {
|
|
|
106
133
|
Run a test:
|
|
107
134
|
|
|
108
135
|
```
|
|
109
|
-
|
|
136
|
+
npx codeceptjs run
|
|
110
137
|
```
|
|
111
138
|
|
|
112
139
|
The output should be similar to this:
|
package/docs/translation.md
CHANGED
|
@@ -3,55 +3,58 @@ permalink: /translation
|
|
|
3
3
|
title: Translation
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
# Translation
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
*Unique feature of CodeceptJS: write tests in your language!*
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
This way scenarios can be written in almost native language using UTF support of JavaScript.
|
|
12
|
-
If you have non-English team and you work on non-English project consider enabling translation
|
|
13
|
-
by setting translation to [one of available languages](https://github.com/codeceptjs/CodeceptJS/blob/master/translations).
|
|
10
|
+
🇩🇪🇯🇵🇫🇷🇹🇼🇨🇳🇵🇱🇧🇷🇮🇹
|
|
14
11
|
|
|
15
|
-
|
|
12
|
+
Test output and the way tests are written can be localized. This way scenarios can be written in almost native language using UTF support of JavaScript.
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
If you have non-English team and you work on non-English project consider enabling translation
|
|
15
|
+
by setting translation to [one of available languages](https://github.com/codeceptjs/CodeceptJS/blob/3.x/translations) or writing vocabulary for your language.
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
npx codeceptjs def
|
|
21
|
-
```
|
|
17
|
+
## How it works
|
|
22
18
|
|
|
23
|
-
|
|
19
|
+
CodceptJS provides a high-level domain specific language (DSL) for writing end-to-end tests.
|
|
20
|
+
As CodeceptJS API is designed to provide a minimal set of methods to write test cases of any kind of complexity.
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
It is possible to add aliases for all CodeceptJS keywords and methods. So if all keywords and methods are translated to a specific language it is possible to write tests in that language. Sure, this is not perfect, as CSS/XPath locators as well as REST API speific words are used as is. However, writing tests in your native language may improve the team's understanding of the test behavior.
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
"translation": "ru-RU"
|
|
29
|
-
```
|
|
24
|
+
You can enable translation if your team is not from English-speaking country developing non-English product.
|
|
30
25
|
|
|
31
|
-
|
|
26
|
+
> ⚠️ It's important to note that default translations are far from being complete. So there are still lots of methods and keywords not translated to your language yet. We recommend to [extend a vocabulary](#extending-vocabulary) to add aliases for non-translated methods and submit a pull request with improvements to a [corresponding language file](https://github.com/codeceptjs/CodeceptJS/blob/3.x/translations).
|
|
32
27
|
|
|
33
|
-
|
|
28
|
+
To enable translition create a new project with
|
|
34
29
|
|
|
35
|
-
|
|
30
|
+
```
|
|
31
|
+
npx codeceptjs init
|
|
32
|
+
```
|
|
36
33
|
|
|
37
|
-
|
|
34
|
+
And select a language of your choice from a list:
|
|
38
35
|
|
|
39
|
-
```js
|
|
40
|
-
Сценарий('пробую написать реферат', (Я) => {
|
|
41
|
-
Я.на_странице('https://yandex.ru/referats');
|
|
42
|
-
Я.вижу("Написать реферат по");
|
|
43
|
-
Я.выбираю_опцию('Психологии');
|
|
44
|
-
Я.кликаю("Написать реферат");
|
|
45
|
-
Я.вижу("Реферат по психологии");
|
|
46
|
-
});
|
|
47
36
|
```
|
|
37
|
+
? Do you want localization for tests? (See https://codecept.io/translation/)
|
|
38
|
+
❯ English (no localization)
|
|
39
|
+
de-DE
|
|
40
|
+
it-IT
|
|
41
|
+
fr-FR
|
|
42
|
+
ja-JP
|
|
43
|
+
pl-PL
|
|
44
|
+
pt-BR
|
|
45
|
+
(Move up and down to reveal more choices)
|
|
46
|
+
```
|
|
47
|
+
> 💡 If you don't see your language in the list but still want to use localized tests, select 'English (no localization)' and create [custom translation](#custom-translation).
|
|
48
|
+
|
|
48
49
|
|
|
49
|
-
##
|
|
50
|
+
## Languages
|
|
51
|
+
|
|
52
|
+
### Portuguese 🇧🇷
|
|
50
53
|
|
|
51
54
|
To write your tests in portuguese you can enable the portuguese translation in config file like:
|
|
52
55
|
|
|
53
|
-
```
|
|
54
|
-
|
|
56
|
+
```js
|
|
57
|
+
translation: "pt-BR"
|
|
55
58
|
```
|
|
56
59
|
|
|
57
60
|
Now you can write test like this:
|
|
@@ -66,12 +69,12 @@ Cenário('Efetuar login', ({ Eu }) => {
|
|
|
66
69
|
});
|
|
67
70
|
```
|
|
68
71
|
|
|
69
|
-
|
|
72
|
+
### French 🇫🇷
|
|
70
73
|
|
|
71
74
|
To write your tests in French you can enable the French translation by adding to config:
|
|
72
75
|
|
|
73
|
-
```
|
|
74
|
-
|
|
76
|
+
```js
|
|
77
|
+
translation: "fr-FR"
|
|
75
78
|
```
|
|
76
79
|
|
|
77
80
|
Now you can write tests like this:
|
|
@@ -86,12 +89,12 @@ Scenario('Se connecter sur GitHub', (Je) => {
|
|
|
86
89
|
});
|
|
87
90
|
```
|
|
88
91
|
|
|
89
|
-
|
|
92
|
+
### Italian 🇮🇹
|
|
90
93
|
|
|
91
|
-
Add to config
|
|
94
|
+
Add to `codeceptjs.conf.js` or `codeceptjs.conf.ts` config file:
|
|
92
95
|
|
|
93
|
-
```
|
|
94
|
-
|
|
96
|
+
```js
|
|
97
|
+
translation: "it-IT"
|
|
95
98
|
```
|
|
96
99
|
|
|
97
100
|
Now you can write test like this:
|
|
@@ -106,12 +109,12 @@ Caratteristica('Effettuare il Login su GitHub', (io) => {
|
|
|
106
109
|
});
|
|
107
110
|
```
|
|
108
111
|
|
|
109
|
-
|
|
112
|
+
### Polish 🇵🇱
|
|
110
113
|
|
|
111
|
-
Add to config
|
|
114
|
+
Add to `codeceptjs.conf.js` or `codeceptjs.conf.ts` config file:
|
|
112
115
|
|
|
113
|
-
```
|
|
114
|
-
|
|
116
|
+
```js
|
|
117
|
+
translation: "pl-PL"
|
|
115
118
|
```
|
|
116
119
|
|
|
117
120
|
Now you can write test like this:
|
|
@@ -127,16 +130,16 @@ Scenario('Zakładanie konta free trial na stronie głównej GetResponse', ({ Ja
|
|
|
127
130
|
});
|
|
128
131
|
```
|
|
129
132
|
|
|
130
|
-
|
|
133
|
+
### Chinese 🇹🇼🇨🇳
|
|
131
134
|
|
|
132
|
-
Add to config:
|
|
135
|
+
Add to `codeceptjs.conf.js` or `codeceptjs.conf.ts` config: file:
|
|
133
136
|
|
|
134
|
-
```
|
|
135
|
-
|
|
137
|
+
```JS
|
|
138
|
+
translation: "zh-CN"
|
|
136
139
|
```
|
|
137
140
|
or
|
|
138
|
-
```
|
|
139
|
-
|
|
141
|
+
```JS
|
|
142
|
+
translation: "zh-TW"
|
|
140
143
|
```
|
|
141
144
|
|
|
142
145
|
This way tests can be written in Chinese language while it is still JavaScript:
|
|
@@ -156,6 +159,7 @@ Scenario('成功提交表单', ({ 我 }) => {
|
|
|
156
159
|
});
|
|
157
160
|
```
|
|
158
161
|
or
|
|
162
|
+
|
|
159
163
|
```JavaScript
|
|
160
164
|
Feature('CodeceptJS 演示');
|
|
161
165
|
|
|
@@ -171,12 +175,12 @@ Scenario('成功提交表單', ({ 我 }) => {
|
|
|
171
175
|
});
|
|
172
176
|
```
|
|
173
177
|
|
|
174
|
-
|
|
178
|
+
### Japanese 🇯🇵
|
|
175
179
|
|
|
176
|
-
Add to config
|
|
180
|
+
Add to `codeceptjs.conf.js` or `codeceptjs.conf.ts` config file:
|
|
177
181
|
|
|
178
|
-
```
|
|
179
|
-
|
|
182
|
+
```js
|
|
183
|
+
translation: "ja-JP"
|
|
180
184
|
```
|
|
181
185
|
|
|
182
186
|
Now you can write test like this:
|
|
@@ -192,13 +196,35 @@ Scenario('ログインできる', ({ 私は }) => {
|
|
|
192
196
|
});
|
|
193
197
|
```
|
|
194
198
|
|
|
195
|
-
##
|
|
199
|
+
## Extending Vocabulary
|
|
200
|
+
|
|
201
|
+
To add localized aliases to more actions create a new JSON or JavaScript file returning an object with following fields:
|
|
202
|
+
|
|
203
|
+
```js
|
|
204
|
+
module.exports = {
|
|
205
|
+
actions: {
|
|
206
|
+
// add action aliases, translating method name to your language
|
|
207
|
+
rightClick: 'Rechtsklick'
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Then enable this vocabulary file in codecept conf:
|
|
213
|
+
|
|
214
|
+
```js
|
|
215
|
+
// inside codecept.conf.js or codecept.conf.ts
|
|
216
|
+
// ...
|
|
217
|
+
translation: 'de_DE',
|
|
218
|
+
vocabularies: ['my_translation_file.js'],
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Custom Translation
|
|
196
222
|
|
|
197
223
|
Create translation file like this:
|
|
198
224
|
|
|
199
225
|
```js
|
|
200
226
|
module.exports = {
|
|
201
|
-
I: '',
|
|
227
|
+
I: 'Ya',
|
|
202
228
|
contexts: {
|
|
203
229
|
Feature: 'Feature',
|
|
204
230
|
Scenario: 'Szenario',
|
|
@@ -215,6 +241,7 @@ module.exports = {
|
|
|
215
241
|
|
|
216
242
|
And add the file path to your config
|
|
217
243
|
|
|
218
|
-
```
|
|
219
|
-
|
|
244
|
+
```js
|
|
245
|
+
translation: "MyLang",
|
|
246
|
+
vocabularies: ["./relative/path/to/your/translation.js"]
|
|
220
247
|
```
|
package/docs/typescript.md
CHANGED
|
@@ -41,8 +41,55 @@ Then select TypeScript as the first question:
|
|
|
41
41
|
|
|
42
42
|
Then a config file and new tests will be created in TypeScript format.
|
|
43
43
|
|
|
44
|
-
If a config file is set in
|
|
44
|
+
If a config file is set in TypeScript format (`codecept.conf.ts`) package `node-ts` will be used to run tests.
|
|
45
45
|
|
|
46
|
+
## Promise-Based Typings
|
|
47
|
+
|
|
48
|
+
If you plan to write tests in TypeScript you will probably want to enable "promise-based typings" as you will be asked in `init` command about it:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
? Would you prefer to use promise-based typings and explicitly use `await` for all I.* commands?
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
By default, CodeceptJS tests are written in synchronous mode. This is a regular CodeceptJS test:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
I.amOnPage('/')
|
|
58
|
+
I.click('Login')
|
|
59
|
+
I.see('Hello!')
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Even thought we don't see any `await`, those commands are executed synchronously, one by one.
|
|
63
|
+
All methods of `I` object actually return promise and TypeScript linter requires to use `await` operator for those promises.
|
|
64
|
+
To trick TypeScript and allow writing tests in CodeceptJS manner we create typings where `void` is returned instead of promises. This way linter won't complain on async code without await, as no promise is returned.
|
|
65
|
+
|
|
66
|
+
Our philosophy here is: use `await` only when it is actually needed, don't add visual mess to your code prefixing each line with `await`. However, you might want to get a better control of your tests and follow TypeScript conventions.
|
|
67
|
+
This is why you might want to **enable promise-based typings**.
|
|
68
|
+
|
|
69
|
+
A previous test should be rewritten with `await`s:
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
await I.amOnPage('/')
|
|
73
|
+
await I.click('Login')
|
|
74
|
+
await I.see('Hello!')
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Using `await` explicitly provides a beter control of execution flow. Some CodeceptJS users report that they increased stability of tests by adopting `await` for all CodeceptJS commands in their codebase.
|
|
78
|
+
|
|
79
|
+
If you select to use promise-based typings, type definitions will be generated so all actions to return a promise.
|
|
80
|
+
Otherwise they will still return promises but it won't be relfected in type definitions.
|
|
81
|
+
|
|
82
|
+
To introduce promise-based typings into a current project edit `codecept.conf.ts`:
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
fullPromiseBased: true;
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
and rebuild type definitions with
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
npx codeceptjs def
|
|
92
|
+
```
|
|
46
93
|
|
|
47
94
|
## Types for custom helper or page object
|
|
48
95
|
|
|
@@ -51,13 +98,12 @@ If you want to get types for your [custom helper](https://codecept.io/helpers/#c
|
|
|
51
98
|
For example, if you add the new step `printMessage` for your custom helper like this:
|
|
52
99
|
```js
|
|
53
100
|
// customHelper.ts
|
|
54
|
-
class CustomHelper extends Helper {
|
|
101
|
+
export class CustomHelper extends Helper {
|
|
55
102
|
printMessage(msg: string) {
|
|
56
103
|
console.log(msg)
|
|
57
104
|
}
|
|
58
105
|
}
|
|
59
106
|
|
|
60
|
-
export = CustomHelper
|
|
61
107
|
```
|
|
62
108
|
|
|
63
109
|
Then you need to add this helper to your `codecept.conf.js` like in this [docs](https://codecept.io/helpers/#configuration).
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/docs/wiki/Examples.md
CHANGED
|
File without changes
|
|
File without changes
|
package/docs/wiki/Home.md
CHANGED
|
File without changes
|
|
File without changes
|
package/docs/wiki/Roadmap.md
CHANGED
|
File without changes
|
package/docs/wiki/Tests.md
CHANGED
|
File without changes
|
|
File without changes
|
package/docs/wiki/Videos.md
CHANGED
|
File without changes
|
package/lib/codecept.js
CHANGED
|
@@ -85,6 +85,7 @@ class Codecept {
|
|
|
85
85
|
global.Given = stepDefinitions.Given;
|
|
86
86
|
global.When = stepDefinitions.When;
|
|
87
87
|
global.Then = stepDefinitions.Then;
|
|
88
|
+
global.DefineParameterType = stepDefinitions.defineParameterType;
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
91
|
|
|
@@ -94,12 +95,13 @@ class Codecept {
|
|
|
94
95
|
runHooks() {
|
|
95
96
|
// default hooks
|
|
96
97
|
runHook(require('./listener/steps'));
|
|
98
|
+
runHook(require('./listener/artifacts'));
|
|
97
99
|
runHook(require('./listener/config'));
|
|
98
100
|
runHook(require('./listener/helpers'));
|
|
99
101
|
runHook(require('./listener/timeout'));
|
|
100
102
|
runHook(require('./listener/exit'));
|
|
101
103
|
|
|
102
|
-
// custom hooks
|
|
104
|
+
// custom hooks (previous iteration of plugins)
|
|
103
105
|
this.config.hooks.forEach(hook => runHook(hook));
|
|
104
106
|
}
|
|
105
107
|
|
|
@@ -138,7 +138,8 @@ module.exports = function (genPath, options) {
|
|
|
138
138
|
helperPaths[name] = require;
|
|
139
139
|
helperNames.push(name);
|
|
140
140
|
} else {
|
|
141
|
-
|
|
141
|
+
const fullBasedPromised = codecept.config.fullPromiseBased;
|
|
142
|
+
helperNames.push(fullBasedPromised === true ? `${name}Ts` : name);
|
|
142
143
|
}
|
|
143
144
|
|
|
144
145
|
if (!actingHelpers.includes(name)) {
|
|
@@ -155,6 +156,10 @@ module.exports = function (genPath, options) {
|
|
|
155
156
|
supportObject.set('I', 'I');
|
|
156
157
|
supportObject.set('current', 'any');
|
|
157
158
|
|
|
159
|
+
if (translations.loaded) {
|
|
160
|
+
supportObject.set(translations.I, translations.I);
|
|
161
|
+
}
|
|
162
|
+
|
|
158
163
|
if (autoLogin) {
|
|
159
164
|
supportObject.set(autoLogin, 'any');
|
|
160
165
|
}
|
|
@@ -174,7 +179,7 @@ module.exports = function (genPath, options) {
|
|
|
174
179
|
supportObject.set(name, name);
|
|
175
180
|
}
|
|
176
181
|
|
|
177
|
-
|
|
182
|
+
let definitionsFileContent = getDefinitionsFileContent({
|
|
178
183
|
helperNames,
|
|
179
184
|
supportObject,
|
|
180
185
|
importPaths: getImportString(testsPath, targetFolderPath, supportPaths, helperPaths),
|
|
@@ -184,6 +189,25 @@ module.exports = function (genPath, options) {
|
|
|
184
189
|
customHelpers,
|
|
185
190
|
});
|
|
186
191
|
|
|
192
|
+
// add aliases for translations
|
|
193
|
+
if (translations.loaded) {
|
|
194
|
+
const namespaceTranslationAliases = [];
|
|
195
|
+
namespaceTranslationAliases.push(`interface ${translations.vocabulary.I} extends WithTranslation<Methods> {}`);
|
|
196
|
+
|
|
197
|
+
namespaceTranslationAliases.push(' namespace Translation {');
|
|
198
|
+
definitionsFileContent = definitionsFileContent.replace('namespace Translation {', namespaceTranslationAliases.join('\n'));
|
|
199
|
+
|
|
200
|
+
const translationAliases = [];
|
|
201
|
+
|
|
202
|
+
if (translations.vocabulary.contexts) {
|
|
203
|
+
Object.keys(translations.vocabulary.contexts).forEach(k => {
|
|
204
|
+
translationAliases.push(`declare const ${translations.vocabulary.contexts[k]}: typeof ${k};`);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
definitionsFileContent += `\n${translationAliases.join('\n')}`;
|
|
209
|
+
}
|
|
210
|
+
|
|
187
211
|
fs.writeFileSync(path.join(targetFolderPath, 'steps.d.ts'), definitionsFileContent);
|
|
188
212
|
output.print('TypeScript Definitions provide autocompletion in Visual Studio Code and other IDEs');
|
|
189
213
|
output.print('Definitions were generated in steps.d.ts');
|
package/lib/command/generate.js
CHANGED
|
@@ -7,6 +7,7 @@ const {
|
|
|
7
7
|
fileExists, ucfirst, lcfirst, beautify,
|
|
8
8
|
} = require('../utils');
|
|
9
9
|
const output = require('../output');
|
|
10
|
+
const generateDefinitions = require('./definitions');
|
|
10
11
|
const {
|
|
11
12
|
getConfig, getTestRoot, safeFileWrite, readConfig,
|
|
12
13
|
} = require('./utils');
|
|
@@ -15,7 +16,7 @@ let extension = 'js';
|
|
|
15
16
|
|
|
16
17
|
const testTemplate = `Feature('{{feature}}');
|
|
17
18
|
|
|
18
|
-
Scenario('test something', ({ {{actor}} }) => {
|
|
19
|
+
Scenario('test something', async ({ {{actor}} }) => {
|
|
19
20
|
|
|
20
21
|
});
|
|
21
22
|
`;
|
|
@@ -55,13 +56,19 @@ module.exports.test = function (genPath) {
|
|
|
55
56
|
if (!fileExists(dir)) mkdirp.sync(dir);
|
|
56
57
|
let testContent = testTemplate.replace('{{feature}}', result.feature);
|
|
57
58
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
const container = require('../container');
|
|
60
|
+
container.create(config, {});
|
|
61
|
+
// translate scenario test
|
|
62
|
+
if (container.translation().loaded) {
|
|
63
|
+
const vocabulary = container.translation().vocabulary;
|
|
64
|
+
testContent = testContent.replace('{{actor}}', container.translation().I);
|
|
65
|
+
if (vocabulary.contexts.Feature) testContent = testContent.replace('Feature', vocabulary.contexts.Feature);
|
|
66
|
+
if (vocabulary.contexts.Scenario) testContent = testContent.replace('Scenario', vocabulary.contexts.Scenario);
|
|
67
|
+
output.print(`Test was created in ${colors.bold(config.translation)} localization. See: https://codecept.io/translation/`);
|
|
68
|
+
} else {
|
|
69
|
+
testContent = testContent.replace('{{actor}}', 'I');
|
|
70
|
+
}
|
|
71
|
+
if (!config.fullPromiseBased) testContent = testContent.replace('async', '');
|
|
65
72
|
|
|
66
73
|
if (!safeFileWrite(testFile, testContent)) return;
|
|
67
74
|
output.success(`\nTest for ${result.filename} was created in ${testFile}`);
|
|
@@ -133,7 +140,14 @@ module.exports.pageObject = function (genPath, opts) {
|
|
|
133
140
|
${name}: '${result.filename}',
|
|
134
141
|
},`);
|
|
135
142
|
|
|
136
|
-
output.print(`Use ${output.colors.bold(colors.cyan(name))} as parameter in test scenarios to access this object
|
|
143
|
+
output.print(`Use ${output.colors.bold(colors.cyan(name))} as parameter in test scenarios to access this object:`);
|
|
144
|
+
output.print(`\nScenario('my new test', ({ I, ${name} })) { /** ... */ }\n`);
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
generateDefinitions(testsPath, {});
|
|
148
|
+
} catch (_err) {
|
|
149
|
+
output.print(`Run ${colors.green('npx codeceptjs def')} to update your types to get auto-completion for object.`);
|
|
150
|
+
}
|
|
137
151
|
});
|
|
138
152
|
};
|
|
139
153
|
|