codeceptjs 3.4.1 → 3.5.1-2.beta.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/README.md +31 -30
- package/bin/codecept.js +1 -1
- package/lib/actor.js +6 -3
- package/lib/ai.js +180 -0
- package/lib/cli.js +13 -3
- package/lib/codecept.js +8 -0
- package/lib/colorUtils.js +10 -0
- package/lib/command/definitions.js +2 -7
- package/lib/command/dryRun.js +11 -2
- package/lib/command/generate.js +46 -3
- package/lib/command/info.js +24 -0
- package/lib/command/init.js +64 -6
- package/lib/command/interactive.js +15 -1
- package/lib/command/run-multiple/collection.js +17 -5
- package/lib/command/run-multiple.js +4 -2
- package/lib/command/run-workers.js +68 -5
- package/lib/command/run.js +7 -0
- package/lib/command/workers/runTests.js +39 -0
- package/lib/container.js +13 -3
- package/lib/data/context.js +14 -6
- package/lib/event.js +4 -0
- package/lib/helper/ApiDataFactory.js +2 -1
- package/lib/helper/Appium.js +116 -29
- package/lib/helper/Expect.js +422 -0
- package/lib/helper/FileSystem.js +1 -1
- package/lib/helper/GraphQL.js +25 -0
- package/lib/helper/JSONResponse.js +4 -4
- package/lib/helper/Nightmare.js +10 -5
- package/lib/helper/OpenAI.js +126 -0
- package/lib/helper/Playwright.js +1298 -229
- package/lib/helper/Protractor.js +12 -7
- package/lib/helper/Puppeteer.js +204 -64
- package/lib/helper/REST.js +15 -5
- package/lib/helper/TestCafe.js +45 -10
- package/lib/helper/WebDriver.js +252 -83
- package/lib/helper/errors/ElementNotFound.js +2 -1
- package/lib/helper/extras/PlaywrightReactVueLocator.js +38 -0
- package/lib/helper/scripts/blurElement.js +17 -0
- package/lib/helper/scripts/focusElement.js +17 -0
- package/lib/helper/scripts/highlightElement.js +20 -0
- package/lib/html.js +258 -0
- package/lib/interfaces/bdd.js +1 -1
- package/lib/interfaces/gherkin.js +37 -3
- package/lib/interfaces/scenarioConfig.js +1 -0
- package/lib/listener/retry.js +2 -1
- package/lib/locator.js +17 -4
- package/lib/mochaFactory.js +2 -1
- package/lib/output.js +1 -1
- package/lib/pause.js +78 -19
- package/lib/plugin/autoLogin.js +45 -10
- package/lib/plugin/debugErrors.js +67 -0
- package/lib/plugin/fakerTransform.js +4 -6
- package/lib/plugin/heal.js +209 -0
- package/lib/plugin/retryFailedStep.js +10 -1
- package/lib/plugin/retryTo.js +2 -4
- package/lib/plugin/screenshotOnFail.js +11 -2
- package/lib/plugin/selenoid.js +6 -1
- package/lib/plugin/standardActingHelpers.js +0 -2
- package/lib/plugin/stepByStepReport.js +2 -2
- package/lib/plugin/tryTo.js +5 -7
- package/lib/plugin/wdio.js +0 -1
- package/lib/recorder.js +22 -11
- package/lib/secret.js +5 -4
- package/lib/session.js +1 -1
- package/lib/step.js +36 -12
- package/lib/ui.js +5 -3
- package/lib/utils.js +22 -1
- package/lib/workers.js +83 -10
- package/package.json +117 -95
- package/translations/de-DE.js +5 -0
- package/translations/fr-FR.js +14 -1
- package/translations/it-IT.js +1 -0
- package/translations/ja-JP.js +14 -9
- package/translations/pl-PL.js +5 -0
- package/translations/pt-BR.js +1 -0
- package/translations/ru-RU.js +1 -0
- package/translations/zh-CN.js +5 -0
- package/translations/zh-TW.js +5 -0
- package/typings/index.d.ts +51 -15
- package/typings/promiseBasedTypes.d.ts +864 -802
- package/typings/types.d.ts +1339 -744
- package/CHANGELOG.md +0 -2427
- package/docs/advanced.md +0 -351
- package/docs/api.md +0 -323
- package/docs/basics.md +0 -980
- package/docs/bdd.md +0 -535
- package/docs/best.md +0 -237
- package/docs/books.md +0 -37
- package/docs/bootstrap.md +0 -135
- package/docs/build/ApiDataFactory.js +0 -409
- package/docs/build/Appium.js +0 -1938
- package/docs/build/FileSystem.js +0 -228
- package/docs/build/GraphQL.js +0 -204
- package/docs/build/GraphQLDataFactory.js +0 -309
- package/docs/build/JSONResponse.js +0 -338
- package/docs/build/Mochawesome.js +0 -71
- package/docs/build/Nightmare.js +0 -2145
- package/docs/build/Playwright.js +0 -3986
- package/docs/build/Polly.js +0 -42
- package/docs/build/Protractor.js +0 -2699
- package/docs/build/Puppeteer.js +0 -3710
- package/docs/build/REST.js +0 -334
- package/docs/build/SeleniumWebdriver.js +0 -76
- package/docs/build/TestCafe.js +0 -2057
- package/docs/build/WebDriver.js +0 -4017
- package/docs/changelog.md +0 -2436
- package/docs/commands.md +0 -254
- package/docs/community-helpers.md +0 -58
- package/docs/configuration.md +0 -157
- package/docs/continuous-integration.md +0 -22
- package/docs/custom-helpers.md +0 -306
- package/docs/data.md +0 -375
- package/docs/detox.md +0 -235
- package/docs/docker.md +0 -137
- package/docs/email.md +0 -183
- package/docs/examples.md +0 -149
- package/docs/helpers/ApiDataFactory.md +0 -266
- package/docs/helpers/Appium.md +0 -1312
- package/docs/helpers/Detox.md +0 -586
- package/docs/helpers/FileSystem.md +0 -152
- package/docs/helpers/GraphQL.md +0 -130
- package/docs/helpers/GraphQLDataFactory.md +0 -226
- package/docs/helpers/JSONResponse.md +0 -254
- package/docs/helpers/Mochawesome.md +0 -8
- package/docs/helpers/MockRequest.md +0 -377
- package/docs/helpers/Nightmare.md +0 -1256
- package/docs/helpers/Playwright.md +0 -2208
- package/docs/helpers/Polly.md +0 -44
- package/docs/helpers/Puppeteer-firefox.md +0 -86
- package/docs/helpers/Puppeteer.md +0 -2141
- package/docs/helpers/REST.md +0 -217
- package/docs/helpers/TestCafe.md +0 -1222
- package/docs/helpers/WebDriver.md +0 -2319
- package/docs/hooks.md +0 -340
- package/docs/index.md +0 -111
- package/docs/installation.md +0 -75
- package/docs/internal-api.md +0 -265
- package/docs/locators.md +0 -331
- package/docs/mobile-react-native-locators.md +0 -67
- package/docs/mobile.md +0 -297
- package/docs/nightmare.md +0 -223
- package/docs/pageobjects.md +0 -291
- package/docs/parallel.md +0 -232
- package/docs/playwright.md +0 -609
- package/docs/plugins.md +0 -1171
- package/docs/puppeteer.md +0 -316
- package/docs/quickstart.md +0 -163
- package/docs/react.md +0 -69
- package/docs/reports.md +0 -392
- package/docs/secrets.md +0 -30
- package/docs/shadow.md +0 -68
- package/docs/shared/keys.mustache +0 -31
- package/docs/shared/react.mustache +0 -1
- package/docs/testcafe.md +0 -174
- package/docs/translation.md +0 -247
- package/docs/tutorial.md +0 -271
- package/docs/typescript.md +0 -180
- package/docs/ui.md +0 -59
- package/docs/videos.md +0 -28
- package/docs/visual.md +0 -202
- package/docs/vue.md +0 -121
- package/docs/webapi/amOnPage.mustache +0 -11
- package/docs/webapi/appendField.mustache +0 -9
- package/docs/webapi/attachFile.mustache +0 -12
- package/docs/webapi/checkOption.mustache +0 -13
- package/docs/webapi/clearCookie.mustache +0 -10
- package/docs/webapi/clearField.mustache +0 -9
- package/docs/webapi/click.mustache +0 -25
- package/docs/webapi/clickLink.mustache +0 -8
- package/docs/webapi/closeCurrentTab.mustache +0 -7
- package/docs/webapi/closeOtherTabs.mustache +0 -8
- package/docs/webapi/dontSee.mustache +0 -11
- package/docs/webapi/dontSeeCheckboxIsChecked.mustache +0 -10
- package/docs/webapi/dontSeeCookie.mustache +0 -8
- package/docs/webapi/dontSeeCurrentUrlEquals.mustache +0 -10
- package/docs/webapi/dontSeeElement.mustache +0 -8
- package/docs/webapi/dontSeeElementInDOM.mustache +0 -8
- package/docs/webapi/dontSeeInCurrentUrl.mustache +0 -4
- package/docs/webapi/dontSeeInField.mustache +0 -11
- package/docs/webapi/dontSeeInSource.mustache +0 -8
- package/docs/webapi/dontSeeInTitle.mustache +0 -8
- package/docs/webapi/doubleClick.mustache +0 -13
- package/docs/webapi/downloadFile.mustache +0 -12
- package/docs/webapi/dragAndDrop.mustache +0 -9
- package/docs/webapi/dragSlider.mustache +0 -11
- package/docs/webapi/executeAsyncScript.mustache +0 -24
- package/docs/webapi/executeScript.mustache +0 -26
- package/docs/webapi/fillField.mustache +0 -16
- package/docs/webapi/forceClick.mustache +0 -28
- package/docs/webapi/forceRightClick.mustache +0 -18
- package/docs/webapi/grabAllWindowHandles.mustache +0 -7
- package/docs/webapi/grabAttributeFrom.mustache +0 -10
- package/docs/webapi/grabAttributeFromAll.mustache +0 -9
- package/docs/webapi/grabBrowserLogs.mustache +0 -9
- package/docs/webapi/grabCookie.mustache +0 -11
- package/docs/webapi/grabCssPropertyFrom.mustache +0 -11
- package/docs/webapi/grabCssPropertyFromAll.mustache +0 -10
- package/docs/webapi/grabCurrentUrl.mustache +0 -9
- package/docs/webapi/grabCurrentWindowHandle.mustache +0 -6
- package/docs/webapi/grabDataFromPerformanceTiming.mustache +0 -20
- package/docs/webapi/grabElementBoundingRect.mustache +0 -20
- package/docs/webapi/grabGeoLocation.mustache +0 -8
- package/docs/webapi/grabHTMLFrom.mustache +0 -10
- package/docs/webapi/grabHTMLFromAll.mustache +0 -9
- package/docs/webapi/grabNumberOfOpenTabs.mustache +0 -8
- package/docs/webapi/grabNumberOfVisibleElements.mustache +0 -9
- package/docs/webapi/grabPageScrollPosition.mustache +0 -8
- package/docs/webapi/grabPopupText.mustache +0 -5
- package/docs/webapi/grabSource.mustache +0 -8
- package/docs/webapi/grabTextFrom.mustache +0 -10
- package/docs/webapi/grabTextFromAll.mustache +0 -9
- package/docs/webapi/grabTitle.mustache +0 -8
- package/docs/webapi/grabValueFrom.mustache +0 -9
- package/docs/webapi/grabValueFromAll.mustache +0 -8
- package/docs/webapi/moveCursorTo.mustache +0 -12
- package/docs/webapi/openNewTab.mustache +0 -7
- package/docs/webapi/pressKey.mustache +0 -12
- package/docs/webapi/pressKeyDown.mustache +0 -12
- package/docs/webapi/pressKeyUp.mustache +0 -12
- package/docs/webapi/pressKeyWithKeyNormalization.mustache +0 -60
- package/docs/webapi/refreshPage.mustache +0 -6
- package/docs/webapi/resizeWindow.mustache +0 -6
- package/docs/webapi/rightClick.mustache +0 -14
- package/docs/webapi/saveElementScreenshot.mustache +0 -10
- package/docs/webapi/saveScreenshot.mustache +0 -12
- package/docs/webapi/say.mustache +0 -10
- package/docs/webapi/scrollIntoView.mustache +0 -11
- package/docs/webapi/scrollPageToBottom.mustache +0 -6
- package/docs/webapi/scrollPageToTop.mustache +0 -6
- package/docs/webapi/scrollTo.mustache +0 -12
- package/docs/webapi/see.mustache +0 -11
- package/docs/webapi/seeAttributesOnElements.mustache +0 -9
- package/docs/webapi/seeCheckboxIsChecked.mustache +0 -10
- package/docs/webapi/seeCookie.mustache +0 -8
- package/docs/webapi/seeCssPropertiesOnElements.mustache +0 -9
- package/docs/webapi/seeCurrentUrlEquals.mustache +0 -11
- package/docs/webapi/seeElement.mustache +0 -8
- package/docs/webapi/seeElementInDOM.mustache +0 -8
- package/docs/webapi/seeInCurrentUrl.mustache +0 -8
- package/docs/webapi/seeInField.mustache +0 -12
- package/docs/webapi/seeInPopup.mustache +0 -8
- package/docs/webapi/seeInSource.mustache +0 -7
- package/docs/webapi/seeInTitle.mustache +0 -8
- package/docs/webapi/seeNumberOfElements.mustache +0 -11
- package/docs/webapi/seeNumberOfVisibleElements.mustache +0 -10
- package/docs/webapi/seeTextEquals.mustache +0 -9
- package/docs/webapi/seeTitleEquals.mustache +0 -8
- package/docs/webapi/selectOption.mustache +0 -21
- package/docs/webapi/setCookie.mustache +0 -16
- package/docs/webapi/setGeoLocation.mustache +0 -12
- package/docs/webapi/switchTo.mustache +0 -9
- package/docs/webapi/switchToNextTab.mustache +0 -10
- package/docs/webapi/switchToPreviousTab.mustache +0 -10
- package/docs/webapi/type.mustache +0 -18
- package/docs/webapi/uncheckOption.mustache +0 -13
- package/docs/webapi/wait.mustache +0 -8
- package/docs/webapi/waitForClickable.mustache +0 -11
- package/docs/webapi/waitForDetached.mustache +0 -10
- package/docs/webapi/waitForElement.mustache +0 -11
- package/docs/webapi/waitForEnabled.mustache +0 -6
- package/docs/webapi/waitForFunction.mustache +0 -17
- package/docs/webapi/waitForInvisible.mustache +0 -10
- package/docs/webapi/waitForText.mustache +0 -13
- package/docs/webapi/waitForValue.mustache +0 -10
- package/docs/webapi/waitForVisible.mustache +0 -10
- package/docs/webapi/waitInUrl.mustache +0 -9
- package/docs/webapi/waitNumberOfVisibleElements.mustache +0 -10
- package/docs/webapi/waitToHide.mustache +0 -10
- package/docs/webapi/waitUrlEquals.mustache +0 -10
- package/docs/webdriver.md +0 -657
- package/docs/wiki/Books-&-Posts.md +0 -27
- package/docs/wiki/Community-Helpers-&-Plugins.md +0 -49
- package/docs/wiki/Converting-Playwright-to-Istanbul-Coverage.md +0 -29
- package/docs/wiki/Examples.md +0 -139
- package/docs/wiki/Google-Summer-of-Code-(GSoC)-2020.md +0 -68
- package/docs/wiki/Home.md +0 -16
- package/docs/wiki/Release-Process.md +0 -24
- package/docs/wiki/Roadmap.md +0 -23
- package/docs/wiki/Tests.md +0 -1393
- package/docs/wiki/Upgrading-to-CodeceptJS-3.md +0 -153
- package/docs/wiki/Videos.md +0 -19
package/docs/translation.md
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
permalink: /translation
|
|
3
|
-
title: Translation
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Translation
|
|
7
|
-
|
|
8
|
-
*Unique feature of CodeceptJS: write tests in your language!*
|
|
9
|
-
|
|
10
|
-
🇩🇪🇯🇵🇫🇷🇹🇼🇨🇳🇵🇱🇧🇷🇮🇹
|
|
11
|
-
|
|
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.
|
|
13
|
-
|
|
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.
|
|
16
|
-
|
|
17
|
-
## How it works
|
|
18
|
-
|
|
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.
|
|
21
|
-
|
|
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.
|
|
23
|
-
|
|
24
|
-
You can enable translation if your team is not from English-speaking country developing non-English product.
|
|
25
|
-
|
|
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).
|
|
27
|
-
|
|
28
|
-
To enable translition create a new project with
|
|
29
|
-
|
|
30
|
-
```
|
|
31
|
-
npx codeceptjs init
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
And select a language of your choice from a list:
|
|
35
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
## Languages
|
|
51
|
-
|
|
52
|
-
### Portuguese 🇧🇷
|
|
53
|
-
|
|
54
|
-
To write your tests in portuguese you can enable the portuguese translation in config file like:
|
|
55
|
-
|
|
56
|
-
```js
|
|
57
|
-
translation: "pt-BR"
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
Now you can write test like this:
|
|
61
|
-
|
|
62
|
-
```js
|
|
63
|
-
Cenário('Efetuar login', ({ Eu }) => {
|
|
64
|
-
Eu.estouNaPagina('http://minhaAplicacao.com.br');
|
|
65
|
-
Eu.preenchoOCampo("login", "usuario@minhaAplicacao.com.br");
|
|
66
|
-
Eu.preenchoOCampo("senha", "123456");
|
|
67
|
-
Eu.clico("Entrar");
|
|
68
|
-
Eu.vejo("Seja bem vindo usuário!");
|
|
69
|
-
});
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### French 🇫🇷
|
|
73
|
-
|
|
74
|
-
To write your tests in French you can enable the French translation by adding to config:
|
|
75
|
-
|
|
76
|
-
```js
|
|
77
|
-
translation: "fr-FR"
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
Now you can write tests like this:
|
|
81
|
-
|
|
82
|
-
```js
|
|
83
|
-
Scenario('Se connecter sur GitHub', (Je) => {
|
|
84
|
-
Je.suisSurLaPage('https://github.com/login');
|
|
85
|
-
Je.remplisLeChamp("Username or email address", "jean-dupond");
|
|
86
|
-
Je.remplisLeChamp("Password", "*********");
|
|
87
|
-
Je.cliqueSur("Sign in");
|
|
88
|
-
Je.vois("Learn Git and GitHub without any code!");
|
|
89
|
-
});
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### Italian 🇮🇹
|
|
93
|
-
|
|
94
|
-
Add to `codeceptjs.conf.js` or `codeceptjs.conf.ts` config file:
|
|
95
|
-
|
|
96
|
-
```js
|
|
97
|
-
translation: "it-IT"
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Now you can write test like this:
|
|
101
|
-
|
|
102
|
-
```js
|
|
103
|
-
Caratteristica('Effettuare il Login su GitHub', (io) => {
|
|
104
|
-
io.sono_sulla_pagina('https://github.com/login');
|
|
105
|
-
io.compilo_il_campo("Username or email address", "giuseppe-santoro");
|
|
106
|
-
io.compilo_il_campo("Password", "*********");
|
|
107
|
-
io.faccio_click_su("Sign in");
|
|
108
|
-
io.vedo("Learn Git and GitHub without any code!");
|
|
109
|
-
});
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
### Polish 🇵🇱
|
|
113
|
-
|
|
114
|
-
Add to `codeceptjs.conf.js` or `codeceptjs.conf.ts` config file:
|
|
115
|
-
|
|
116
|
-
```js
|
|
117
|
-
translation: "pl-PL"
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
Now you can write test like this:
|
|
121
|
-
|
|
122
|
-
```js
|
|
123
|
-
Scenario('Zakładanie konta free trial na stronie głównej GetResponse', ({ Ja }) => {
|
|
124
|
-
Ja.jestem_na_stronie('https://getresponse.com');
|
|
125
|
-
Ja.wypełniam_pole("Email address", "sjakubowski@getresponse.com");
|
|
126
|
-
Ja.wypełniam_pole("Password", "digital-marketing-systems");
|
|
127
|
-
Ja.klikam('Sign up');
|
|
128
|
-
Ja.czekam(1);
|
|
129
|
-
Ja.widzę_w_adresie_url('/account_free_created.html');
|
|
130
|
-
});
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### Chinese 🇹🇼🇨🇳
|
|
134
|
-
|
|
135
|
-
Add to `codeceptjs.conf.js` or `codeceptjs.conf.ts` config: file:
|
|
136
|
-
|
|
137
|
-
```JS
|
|
138
|
-
translation: "zh-CN"
|
|
139
|
-
```
|
|
140
|
-
or
|
|
141
|
-
```JS
|
|
142
|
-
translation: "zh-TW"
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
This way tests can be written in Chinese language while it is still JavaScript:
|
|
146
|
-
|
|
147
|
-
```JavaScript
|
|
148
|
-
Feature('CodeceptJS 演示');
|
|
149
|
-
|
|
150
|
-
Scenario('成功提交表单', ({ 我 }) => {
|
|
151
|
-
我.在页面('/documentation')
|
|
152
|
-
我.填写字段('电邮', 'hello@world.com')
|
|
153
|
-
我.填写字段('密码', '123456')
|
|
154
|
-
我.勾选选项('激活')
|
|
155
|
-
我.勾选选项('男');
|
|
156
|
-
我.单击('创建用户')
|
|
157
|
-
我.看到('用户名可用')
|
|
158
|
-
我.在当前网址中看不到('/documentation')
|
|
159
|
-
});
|
|
160
|
-
```
|
|
161
|
-
or
|
|
162
|
-
|
|
163
|
-
```JavaScript
|
|
164
|
-
Feature('CodeceptJS 演示');
|
|
165
|
-
|
|
166
|
-
Scenario('成功提交表單', ({ 我 }) => {
|
|
167
|
-
我.在頁面('/documentation')
|
|
168
|
-
我.填寫欄位('電郵', 'hello@world.com')
|
|
169
|
-
我.填寫欄位('密碼', '123456')
|
|
170
|
-
我.勾選選項('活化')
|
|
171
|
-
我.勾選選項('男');
|
|
172
|
-
我.單擊('建立用戶')
|
|
173
|
-
我.看到('用戶名可用')
|
|
174
|
-
我.在當前網址中看不到('/documentation')
|
|
175
|
-
});
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
### Japanese 🇯🇵
|
|
179
|
-
|
|
180
|
-
Add to `codeceptjs.conf.js` or `codeceptjs.conf.ts` config file:
|
|
181
|
-
|
|
182
|
-
```js
|
|
183
|
-
translation: "ja-JP"
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
Now you can write test like this:
|
|
187
|
-
|
|
188
|
-
```js
|
|
189
|
-
Scenario('ログインできる', ({ 私は }) => {
|
|
190
|
-
私は.ページを移動する('/login');
|
|
191
|
-
私は.フィールドに入力する("Eメール", "foo@example.com");
|
|
192
|
-
私は.フィールドに入力する("パスワード", "p@ssword");
|
|
193
|
-
私は.クリックする('ログイン');
|
|
194
|
-
私は.待つ(1);
|
|
195
|
-
私は.URLに含まれるか確認する('/home');
|
|
196
|
-
});
|
|
197
|
-
```
|
|
198
|
-
|
|
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
|
|
222
|
-
|
|
223
|
-
Create translation file like this:
|
|
224
|
-
|
|
225
|
-
```js
|
|
226
|
-
module.exports = {
|
|
227
|
-
I: 'Ya',
|
|
228
|
-
contexts: {
|
|
229
|
-
Feature: 'Feature',
|
|
230
|
-
Scenario: 'Szenario',
|
|
231
|
-
Before: 'Vor',
|
|
232
|
-
After: 'Nach',
|
|
233
|
-
BeforeSuite: 'vor_der_suite',
|
|
234
|
-
AfterSuite: 'nach_der_suite',
|
|
235
|
-
},
|
|
236
|
-
actions: {
|
|
237
|
-
click: 'Klicken',
|
|
238
|
-
wait: 'Wartenn',
|
|
239
|
-
}
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
And add the file path to your config
|
|
243
|
-
|
|
244
|
-
```js
|
|
245
|
-
translation: "MyLang",
|
|
246
|
-
vocabularies: ["./relative/path/to/your/translation.js"]
|
|
247
|
-
```
|
package/docs/tutorial.md
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
permalink: /tutorial
|
|
3
|
-
title: CoeceptJS Complete Tutorial
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Tutorial: Writing Tests for Checkout Page
|
|
7
|
-
|
|
8
|
-
**[CodeceptJS](https://codecept.io) is a popular open-source testing framework** for JavaScript. It is designed to simplify writing and maintain end-to-end tests for web applications, using a readable and intuitive syntax. To run tests in browser it uses **[Playwright](https://playwright.dev)** by default but ca execute tests via WebDriver, Puppeteer or Appium.
|
|
9
|
-
|
|
10
|
-
## Let's get CodeceptJS installed!
|
|
11
|
-
|
|
12
|
-
To install CodeceptJS, you will need to have Node.js and npm (the Node.js package manager) installed on your system. You can check if you already have these tools installed by running the following commands in a terminal:
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
node --version
|
|
16
|
-
npm --version
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
If either of these commands return an error, you will need to install Node.js and npm before you can install CodeceptJS. You can download and install the latest version of Node.js from the official website, which includes npm.
|
|
20
|
-
|
|
21
|
-
To install CodeceptJS create a new folder and run command form terminal:
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
npx create-codeceptjs .
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
If you run the npx create-codeceptjs . command, it will install CodeceptJS with Playwright in the current directory.
|
|
28
|
-
|
|
29
|
-
> The `npx` command is a tool that comes with npm (the Node.js package manager) and it allows you to run npm packages without having to install them globally on your system.
|
|
30
|
-
|
|
31
|
-
It may take some time as it downloads browsers: Chrome, Firefox and Safari and creates a demo project.
|
|
32
|
-
|
|
33
|
-
But we are here to write a checkout test, right?
|
|
34
|
-
|
|
35
|
-
Let's initialize a new project for that!
|
|
36
|
-
|
|
37
|
-
Run
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
npx codeceptjs init
|
|
41
|
-
```
|
|
42
|
-
Agree on defaults (press Enter for every question asked). When asked for base site URL, provide a URL of a ecommerce website you are testing. For instance, it could be: `https://myshop.com` if you test already published website or `http://localhost` if you run the website locally.
|
|
43
|
-
|
|
44
|
-
When asked for a test name and suite name write "Checkout". It will create the following dirctory structure:
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
.
|
|
48
|
-
├── codecept.conf.js
|
|
49
|
-
├── package.json
|
|
50
|
-
└── Checkout_test.js
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
The `codecept.conf.js` file in the root of the project directory contains the global configuration settings for CodeceptJS.
|
|
54
|
-
|
|
55
|
-
Now open a test:
|
|
56
|
-
|
|
57
|
-
```js
|
|
58
|
-
Feature('Checkout');
|
|
59
|
-
|
|
60
|
-
Scenario('test something', ({ I }) => {
|
|
61
|
-
});
|
|
62
|
-
```
|
|
63
|
-
Inside the Scenario block you write a test.
|
|
64
|
-
|
|
65
|
-
Add `I.amOnPage('/')` into it. It will open the browser on a URL you specified as a base.
|
|
66
|
-
|
|
67
|
-
```js
|
|
68
|
-
Feature('Checkout');
|
|
69
|
-
|
|
70
|
-
Scenario('test something', ({ I }) => {
|
|
71
|
-
I.amOnPage('/')
|
|
72
|
-
});
|
|
73
|
-
```
|
|
74
|
-
But you may want to ask...
|
|
75
|
-
|
|
76
|
-
## What is I?
|
|
77
|
-
|
|
78
|
-
Glad you asked!
|
|
79
|
-
|
|
80
|
-
In CodeceptJS, the `I` object is used to represent the user performing actions in a test scenario. It provides a number of methods (also known as actions) that can be used to simulate user interactions with the application under test.
|
|
81
|
-
|
|
82
|
-
Some of the most popular actions of the I object are:
|
|
83
|
-
|
|
84
|
-
* `I.amOnPage(url)`: This action navigates the user to the specified URL.
|
|
85
|
-
* `I.click(locator)`: This action simulates a click on the element identified by the given locator.
|
|
86
|
-
* `I.fillField(field, value)`: This action fills the specified field with the given value.
|
|
87
|
-
* `I.see(text, context)`: This action checks that the given text is visible on the page (or in the specified context).
|
|
88
|
-
* `I.selectOption(select, option)`: This action selects the specified option from the given select dropdown.
|
|
89
|
-
* `I.waitForElement(locator, timeout)`: This action waits for the specified element to appear on the page, up to the given timeout.
|
|
90
|
-
* `I.waitForText(text, timeout, context)`: This action waits for the given text to appear on the page (or in the specified context), up to the given timeout.
|
|
91
|
-
|
|
92
|
-
We will need to use them to navigate into Checkout process. How do we navigate web? Sure by clicking on links!
|
|
93
|
-
|
|
94
|
-
Let's use `I.click()` for that.
|
|
95
|
-
|
|
96
|
-
But how we can access elements on a webpage?
|
|
97
|
-
|
|
98
|
-
CodeceptJS is smart enough to locate clickable elements by their visible text. For instance, if on your ecommerce website you have a product 'Coffee Cup' with that exact name you can use
|
|
99
|
-
|
|
100
|
-
```js
|
|
101
|
-
I.click('Coffee Cup');
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
But sometimes elements are not as easy to locate, so you can use CSS or XPath locators to locate them.
|
|
105
|
-
|
|
106
|
-
For instance, locating Coffee Cup via CSS can take into accont HTML structure of a page and element attributes. For instance, it can be like this:
|
|
107
|
-
|
|
108
|
-
```js
|
|
109
|
-
I.click('div.products a.product-name[title="Coffee Cup"]');
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
In this example, the `div.products` part of the selector specifies a div element with the `products` class, and the `a.product-name[title="Coffee Cup"]` part specifies an a element with `the product-name` class and the `title` attribute set to Coffee Cup.
|
|
113
|
-
|
|
114
|
-
You can read more about HTML and CSS locators, and basically that's all what you need to know to start writing a checkout test!
|
|
115
|
-
|
|
116
|
-
## Get back to Checkout
|
|
117
|
-
|
|
118
|
-
Let's see how a regular checkout script may look in CodeceptJS:
|
|
119
|
-
|
|
120
|
-
```js
|
|
121
|
-
Scenario('test the checkout form', async ({ I }) => {
|
|
122
|
-
// we select one product and switched to checkout project
|
|
123
|
-
I.amOnPage('/');
|
|
124
|
-
I.click('Coffee Cup');
|
|
125
|
-
I.click('Purchase');
|
|
126
|
-
I.click('Checkout');
|
|
127
|
-
|
|
128
|
-
// fill in the shipping address
|
|
129
|
-
I.fillField('First Name', 'John');
|
|
130
|
-
I.fillField('Last Name', 'Doe');
|
|
131
|
-
I.fillField('Address', '123 Main St.');
|
|
132
|
-
I.fillField('City', 'New York');
|
|
133
|
-
I.selectOption('State', 'New York');
|
|
134
|
-
I.fillField('Zip Code', '10001');
|
|
135
|
-
|
|
136
|
-
// select a payment method
|
|
137
|
-
I.click('#credit-card-option');
|
|
138
|
-
I.fillField('Card Number', '1234-5678-9012-3456');
|
|
139
|
-
I.fillField('Expiration Date', '12/22');
|
|
140
|
-
I.fillField('Security Code', '123');
|
|
141
|
-
|
|
142
|
-
// click the checkout button
|
|
143
|
-
I.click('Checkout');
|
|
144
|
-
|
|
145
|
-
// verify that the checkout was successful
|
|
146
|
-
I.see('Your order has been placed successfully!');
|
|
147
|
-
});
|
|
148
|
-
```
|
|
149
|
-
Sure, in relaity your script might be more complicated. As you have noticed, we used CSS locator `'#credit-card-option'` to get select a payment option. However, the test is simple and you can follow user steps through it.
|
|
150
|
-
|
|
151
|
-
Please note, that you shouldn't use a real credit card number here. Good news, you don't need to. Payment providers like Strip provide dummy card numbers for testing purposes.
|
|
152
|
-
|
|
153
|
-
Run the test with next command:
|
|
154
|
-
|
|
155
|
-
```
|
|
156
|
-
npx codeceptjs run --debug -p pauseOnFail
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
What are special options here?
|
|
160
|
-
|
|
161
|
-
* `--debug` flag is used to output additional information to the console, such as the details of each step in the test, the values of variables, and the results of test assertions. This can help you to identify and fix any issues in your tests.
|
|
162
|
-
* `-p pauseOnFail` option is also used to keep the browser opened even if a test fails. It will help us to identify to which point test was executed and what can be improved.
|
|
163
|
-
|
|
164
|
-
Add more test steps if needed, update locators, and notify business owners that all that purchases are made by you so your collegues won't call you in the night asking when you want to get a coffee cup 😀 Also the good idea is to run tests on staging website, to not interfere with business process.
|
|
165
|
-
|
|
166
|
-
What a test is complete you can run it with:
|
|
167
|
-
|
|
168
|
-
```
|
|
169
|
-
npx codeceptjs run
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
If you are annoyed to see a browser window you can use `HEADLESS` environment variable:
|
|
173
|
-
|
|
174
|
-
```
|
|
175
|
-
HEADLESS=true codeceptjs run
|
|
176
|
-
```
|
|
177
|
-
for Windows users HEADLESS should be set in a different manner:
|
|
178
|
-
|
|
179
|
-
```
|
|
180
|
-
set HEADLESS=true&& codeceptjs run
|
|
181
|
-
```
|
|
182
|
-
The tests will pass but no browser is shown, so you can watch YouTube videos while it goes!
|
|
183
|
-
|
|
184
|
-
## Refactoring
|
|
185
|
-
|
|
186
|
-
What if you need to check more purchases? Should you copy paste your code for that?
|
|
187
|
-
|
|
188
|
-
No! You can use Page Object pattern to put repeating interactions into the reusable functions.
|
|
189
|
-
|
|
190
|
-
You can create a page object via next command:
|
|
191
|
-
|
|
192
|
-
```
|
|
193
|
-
npx codeceptjs gpo
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
Sure, we will call it `Checkout`. It will be created in `./pages/Checkout.js` file. You should enable it in `codecept.conf.js` inside `include` section:
|
|
197
|
-
|
|
198
|
-
```js
|
|
199
|
-
include: {
|
|
200
|
-
...
|
|
201
|
-
checkoutPage: './pages/Checkout.js',
|
|
202
|
-
},
|
|
203
|
-
|
|
204
|
-
```
|
|
205
|
-
Now open this file:
|
|
206
|
-
|
|
207
|
-
```js
|
|
208
|
-
const { I } = inject();
|
|
209
|
-
|
|
210
|
-
module.exports = {
|
|
211
|
-
|
|
212
|
-
// insert your locators and methods here
|
|
213
|
-
}
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
Feels really empty. What should we do about it? Should we write more code? No, we already have it. Let's copy code blocks from a test we have it and place them under a corredponnding function names:
|
|
217
|
-
|
|
218
|
-
```js
|
|
219
|
-
connst { I } = inject();
|
|
220
|
-
|
|
221
|
-
module.exports = {
|
|
222
|
-
|
|
223
|
-
fillShippingAddress(name, address, city, state, zip) {
|
|
224
|
-
I.fillField('Name', name);
|
|
225
|
-
I.fillField('Address', address);
|
|
226
|
-
I.fillField('City', city);
|
|
227
|
-
I.fillField('State', state);
|
|
228
|
-
I.fillField('Zip', zip);
|
|
229
|
-
},
|
|
230
|
-
|
|
231
|
-
fillValidCreditCard() {
|
|
232
|
-
I.click('#credit-card-option');
|
|
233
|
-
I.fillField('Card Number', '1234-5678-9012-3456');
|
|
234
|
-
I.fillField('Expiration Date', '12/22');
|
|
235
|
-
I.fillField('Security Code', '123');
|
|
236
|
-
},
|
|
237
|
-
|
|
238
|
-
checkout() {
|
|
239
|
-
I.click('Checkout');
|
|
240
|
-
},
|
|
241
|
-
}
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
After that we can update our test to use the created page object. Note, that we import Checkout PageObject by its name `checkoutPage` we previously defined in a config.
|
|
245
|
-
|
|
246
|
-
```js
|
|
247
|
-
Scenario('test the checkout form', async ({I, checkoutPage}) => {
|
|
248
|
-
I.amOnPage('/');
|
|
249
|
-
I.click('Coffee Cup');
|
|
250
|
-
I.click('Purchase');
|
|
251
|
-
I.click('Checkout');
|
|
252
|
-
|
|
253
|
-
// fill in the shipping address using the page object
|
|
254
|
-
checkoutPage.fillShippingAddress('John', 'Doe', '123 Main St.', 'New York', 'New York', '10001');
|
|
255
|
-
checkoutPage.fillValidCreditCard();
|
|
256
|
-
checkoutPage.checkout();
|
|
257
|
-
|
|
258
|
-
// verify that the checkout was successful
|
|
259
|
-
I.see('Your order has been placed successfully!');
|
|
260
|
-
});
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
As you see the code of a test was reduced. And we can write the similar tests on the same manner.
|
|
264
|
-
|
|
265
|
-
By applying more and more cases you can test a website to all behaviors.
|
|
266
|
-
|
|
267
|
-
## Summary
|
|
268
|
-
|
|
269
|
-
If you think on just starting test automation, CodeceptJS is the best choice for you as it uses native language to pass commands to browser.
|
|
270
|
-
|
|
271
|
-
If you already skilled in JavaScript, with CodeceptJS you can focus on business level of your test, instead of writing code for browser. This way you can keep your tests stable and maintainable.
|
package/docs/typescript.md
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
permalink: /typescript
|
|
3
|
-
title: TypeScript
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# TypeScript
|
|
7
|
-
|
|
8
|
-
CodeceptJS supports [type declaration](https://github.com/codeceptjs/CodeceptJS/tree/master/typings) for [TypeScript](https://www.typescriptlang.org/). It means that you can write your tests in TS. Also, all of your custom steps can be written in TS
|
|
9
|
-
|
|
10
|
-
# Why TypeScript?
|
|
11
|
-
|
|
12
|
-
With the TypeScript writing CodeceptJS tests becomes much easier. If you configure TS properly in your project as well as your IDE, you will get the following features:
|
|
13
|
-
- [Autocomplete (with IntelliSense)](https://code.visualstudio.com/docs/editor/intellisense) - a tool that streamlines your work by suggesting when you typing what function or property which exists in a class, what arguments can be passed to that method, what it returns, etc.
|
|
14
|
-
Example:
|
|
15
|
-
|
|
16
|
-

|
|
17
|
-
|
|
18
|
-
- To show additional information for a step in a test. Example:
|
|
19
|
-
|
|
20
|
-

|
|
21
|
-
|
|
22
|
-
- Checks types - thanks to TypeScript support in CodeceptJS now allow to tests your tests. TypeScript can prevent some errors:
|
|
23
|
-
- invalid type of variables passed to function;
|
|
24
|
-
- calls no-exist method from PageObject or `I` object;
|
|
25
|
-
- incorrectly used CodeceptJS features;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
## Getting Started <Badge text="Since 3.3.5" type="warning"/>
|
|
29
|
-
|
|
30
|
-
CodeceptJS can initialize tests as a TypeScript project.
|
|
31
|
-
When starting a new project with a standard installation via
|
|
32
|
-
|
|
33
|
-
```
|
|
34
|
-
npx codeceptjs init
|
|
35
|
-
```
|
|
36
|
-
Then select TypeScript as the first question:
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
? Do you plan to write tests in TypeScript? Yes
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Then a config file and new tests will be created in TypeScript format.
|
|
43
|
-
|
|
44
|
-
If a config file is set in TypeScript format (`codecept.conf.ts`) package `ts-node` will be used to run tests.
|
|
45
|
-
|
|
46
|
-
## Promise-Based Typings
|
|
47
|
-
|
|
48
|
-
By default, CodeceptJS tests are written in synchronous mode. This is a regular CodeceptJS test:
|
|
49
|
-
|
|
50
|
-
```js
|
|
51
|
-
I.amOnPage('/')
|
|
52
|
-
I.click('Login')
|
|
53
|
-
I.see('Hello!')
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
Even thought we don't see any `await`, those commands are executed synchronously, one by one.
|
|
57
|
-
All methods of `I` object actually return promise and TypeScript linter requires to use `await` operator for those promises.
|
|
58
|
-
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.
|
|
59
|
-
|
|
60
|
-
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.
|
|
61
|
-
This is why you might want to **enable promise-based typings**.
|
|
62
|
-
|
|
63
|
-
A previous test should be rewritten with `await`s:
|
|
64
|
-
|
|
65
|
-
```js
|
|
66
|
-
await I.amOnPage('/')
|
|
67
|
-
await I.click('Login')
|
|
68
|
-
await I.see('Hello!')
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
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.
|
|
72
|
-
|
|
73
|
-
If you select to use promise-based typings, type definitions will be generated so all actions to return a promise.
|
|
74
|
-
Otherwise they will still return promises but it won't be relfected in type definitions.
|
|
75
|
-
|
|
76
|
-
To introduce promise-based typings into a current project edit `codecept.conf.ts`:
|
|
77
|
-
|
|
78
|
-
```ts
|
|
79
|
-
fullPromiseBased: true;
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
and rebuild type definitions with
|
|
83
|
-
|
|
84
|
-
```
|
|
85
|
-
npx codeceptjs def
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
## Types for custom helper or page object
|
|
89
|
-
|
|
90
|
-
If you want to get types for your [custom helper](https://codecept.io/helpers/#configuration), you can add their automatically with CodeceptJS command `npx codeceptjs def`.
|
|
91
|
-
|
|
92
|
-
For example, if you add the new step `printMessage` for your custom helper like this:
|
|
93
|
-
```js
|
|
94
|
-
// customHelper.ts
|
|
95
|
-
export class CustomHelper extends Helper {
|
|
96
|
-
printMessage(msg: string) {
|
|
97
|
-
console.log(msg)
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
Then you need to add this helper to your `codecept.conf.js` like in this [docs](https://codecept.io/helpers/#configuration).
|
|
104
|
-
And then run the command `npx codeceptjs def`.
|
|
105
|
-
|
|
106
|
-
As result our `steps.d.ts` file will be updated like this:
|
|
107
|
-
```ts
|
|
108
|
-
/// <reference types='codeceptjs' />
|
|
109
|
-
type CustomHelper = import('./CustomHelper');
|
|
110
|
-
|
|
111
|
-
declare namespace CodeceptJS {
|
|
112
|
-
interface SupportObject { I: I }
|
|
113
|
-
interface Methods extends Puppeteer, CustomHelper {}
|
|
114
|
-
interface I extends WithTranslation<Methods> {}
|
|
115
|
-
namespace Translation {
|
|
116
|
-
interface Actions {}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
And now you can use autocomplete on your test.
|
|
122
|
-
|
|
123
|
-
Generation types for PageObject looks like for a custom helper, but `steps.d.ts` will look like:
|
|
124
|
-
```ts
|
|
125
|
-
/// <reference types='codeceptjs' />
|
|
126
|
-
type loginPage = typeof import('./loginPage');
|
|
127
|
-
type homePage = typeof import('./homePage');
|
|
128
|
-
type CustomHelper = import('./CustomHelper');
|
|
129
|
-
|
|
130
|
-
declare namespace CodeceptJS {
|
|
131
|
-
interface SupportObject { I: I, loginPage: loginPage, homePage: homePage }
|
|
132
|
-
interface Methods extends Puppeteer, CustomHelper {}
|
|
133
|
-
interface I extends WithTranslation<Methods> {}
|
|
134
|
-
namespace Translation {
|
|
135
|
-
interface Actions {}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
## Types for custom strict locators
|
|
141
|
-
|
|
142
|
-
You can define [custom strict locators](https://codecept.io/locators/#custom-strict-locators) that can be used in all methods taking a locator (parameter type `LocatorOrString`).
|
|
143
|
-
|
|
144
|
-
Example: A custom strict locator with a `data` property, which can be used like this:
|
|
145
|
-
|
|
146
|
-
```ts
|
|
147
|
-
I.click({ data: 'user-login' });
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
In order to use the custom locator in TypeScript code, its type shape needs to be registered in the interface `CustomLocators` in your `steps.d.ts` file:
|
|
151
|
-
|
|
152
|
-
```ts
|
|
153
|
-
/// <reference types='codeceptjs' />
|
|
154
|
-
...
|
|
155
|
-
|
|
156
|
-
declare namespace CodeceptJS {
|
|
157
|
-
...
|
|
158
|
-
|
|
159
|
-
interface CustomLocators {
|
|
160
|
-
data: { data: string };
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
The property keys used in the `CustomLocators` interface do not matter (only the *types* of the interface properties are used). For simplicity it is recommended to use the name that is also used in your custom locator itself.
|
|
166
|
-
|
|
167
|
-
You can also define more complicated custom locators with multiple (also optional) properties:
|
|
168
|
-
|
|
169
|
-
```ts
|
|
170
|
-
/// <reference types='codeceptjs' />
|
|
171
|
-
...
|
|
172
|
-
|
|
173
|
-
declare namespace CodeceptJS {
|
|
174
|
-
...
|
|
175
|
-
|
|
176
|
-
interface CustomLocators {
|
|
177
|
-
data: { data: string, value?: number, flag?: boolean };
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
```
|