codeceptjs 2.3.4 → 2.4.1
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/CHANGELOG.md +52 -0
- package/README.md +28 -6
- package/bin/codecept.js +42 -0
- package/docs/advanced.md +45 -1
- package/docs/angular.md +3 -3
- package/docs/basics.md +162 -118
- package/docs/bdd.md +30 -5
- package/docs/best.md +8 -6
- package/docs/books.md +6 -1
- package/docs/build/Appium.js +95 -85
- package/docs/build/FileSystem.js +48 -3
- package/docs/build/GraphQL.js +3 -2
- package/docs/build/GraphQLDataFactory.js +1 -0
- package/docs/build/Mochawesome.js +3 -2
- package/docs/build/MockRequest.js +23 -5
- package/docs/build/Nightmare.js +87 -128
- package/docs/build/Protractor.js +107 -155
- package/docs/build/Puppeteer.js +190 -174
- package/docs/build/REST.js +13 -9
- package/docs/build/SeleniumWebdriver.js +0 -17
- package/docs/build/TestCafe.js +164 -158
- package/docs/build/WebDriver.js +236 -211
- package/docs/build/WebDriverIO.js +218 -187
- package/docs/changelog.md +57 -1
- package/docs/commands.md +41 -2
- package/docs/community-helpers.md +12 -1
- package/docs/configuration.md +5 -2
- package/docs/continuous-integration.md +22 -0
- package/docs/{helpers.md → custom-helpers.md} +16 -10
- package/docs/data.md +7 -6
- package/docs/detox.md +6 -6
- package/docs/email.md +4 -2
- package/docs/examples.md +22 -3
- package/docs/helpers/ApiDataFactory.md +15 -13
- package/docs/helpers/Appium.md +1011 -468
- package/docs/helpers/Detox.md +33 -26
- package/docs/helpers/FileSystem.md +43 -13
- package/docs/helpers/GraphQL.md +17 -15
- package/docs/helpers/GraphQLDataFactory.md +15 -13
- package/docs/helpers/Mochawesome.md +3 -1
- package/docs/helpers/MockRequest.md +37 -19
- package/docs/helpers/Nightmare.md +129 -240
- package/docs/helpers/Polly.md +1 -1
- package/docs/helpers/Protractor.md +157 -298
- package/docs/helpers/Puppeteer.md +216 -335
- package/docs/helpers/REST.md +29 -24
- package/docs/helpers/TestCafe.md +137 -235
- package/docs/helpers/WebDriver.md +250 -347
- package/docs/hooks.md +14 -10
- package/docs/index.md +112 -0
- package/docs/installation.md +3 -1
- package/docs/locators.md +19 -8
- package/docs/mobile-react-native-locators.md +2 -2
- package/docs/mobile.md +5 -3
- package/docs/nightmare.md +2 -1
- package/docs/pageobjects.md +4 -2
- package/docs/parallel.md +4 -2
- package/docs/plugins.md +41 -15
- package/docs/puppeteer.md +8 -6
- package/docs/quickstart.md +130 -0
- package/docs/react.md +4 -2
- package/docs/reports.md +6 -4
- package/docs/testcafe.md +10 -8
- package/docs/translation.md +4 -2
- package/docs/ui.md +56 -0
- package/docs/videos.md +11 -2
- package/docs/visual.md +7 -5
- package/docs/vue.md +121 -0
- package/docs/webapi/appendField.mustache +1 -1
- package/docs/webapi/attachFile.mustache +1 -1
- package/docs/webapi/checkOption.mustache +2 -2
- package/docs/webapi/clearCookie.mustache +1 -1
- package/docs/webapi/click.mustache +2 -2
- package/docs/webapi/clickLink.mustache +2 -2
- package/docs/webapi/dontSee.mustache +1 -2
- package/docs/webapi/dontSeeCheckboxIsChecked.mustache +1 -1
- package/docs/webapi/dontSeeElement.mustache +1 -1
- package/docs/webapi/dontSeeElementInDOM.mustache +1 -1
- package/docs/webapi/dontSeeInField.mustache +1 -1
- package/docs/webapi/doubleClick.mustache +2 -2
- package/docs/webapi/downloadFile.mustache +1 -1
- package/docs/webapi/dragSlider.mustache +1 -1
- package/docs/webapi/executeAsyncScript.mustache +2 -1
- package/docs/webapi/executeScript.mustache +2 -1
- package/docs/webapi/fillField.mustache +1 -1
- package/docs/webapi/grabAttributeFrom.mustache +1 -1
- package/docs/webapi/grabBrowserLogs.mustache +1 -1
- package/docs/webapi/grabCookie.mustache +2 -2
- package/docs/webapi/grabCssPropertyFrom.mustache +1 -1
- package/docs/webapi/grabHTMLFrom.mustache +1 -1
- package/docs/webapi/grabNumberOfVisibleElements.mustache +1 -1
- package/docs/webapi/grabPageScrollPosition.mustache +1 -1
- package/docs/webapi/grabTextFrom.mustache +2 -2
- package/docs/webapi/grabValueFrom.mustache +1 -1
- package/docs/webapi/moveCursorTo.mustache +3 -3
- package/docs/webapi/pressKey.mustache +1 -1
- package/docs/webapi/pressKeyWithKeyNormalization.mustache +1 -1
- package/docs/webapi/rightClick.mustache +2 -2
- package/docs/webapi/saveScreenshot.mustache +1 -1
- package/docs/webapi/scrollIntoView.mustache +10 -0
- package/docs/webapi/scrollTo.mustache +3 -3
- package/docs/webapi/see.mustache +1 -1
- package/docs/webapi/seeAttributesOnElements.mustache +1 -1
- package/docs/webapi/seeCheckboxIsChecked.mustache +1 -1
- package/docs/webapi/seeCssPropertiesOnElements.mustache +1 -1
- package/docs/webapi/seeElement.mustache +1 -1
- package/docs/webapi/seeElementInDOM.mustache +1 -1
- package/docs/webapi/seeInField.mustache +1 -1
- package/docs/webapi/seeNumberOfElements.mustache +1 -1
- package/docs/webapi/seeNumberOfVisibleElements.mustache +1 -1
- package/docs/webapi/seeTextEquals.mustache +8 -0
- package/docs/webapi/selectOption.mustache +2 -2
- package/docs/webapi/switchTo.mustache +1 -1
- package/docs/webapi/uncheckOption.mustache +2 -2
- package/docs/webapi/waitForClickable.mustache +10 -0
- package/docs/webapi/waitForDetached.mustache +2 -2
- package/docs/webapi/waitForElement.mustache +2 -2
- package/docs/webapi/waitForEnabled.mustache +2 -2
- package/docs/webapi/waitForFunction.mustache +2 -2
- package/docs/webapi/waitForInvisible.mustache +2 -2
- package/docs/webapi/waitForText.mustache +2 -2
- package/docs/webapi/waitForValue.mustache +1 -1
- package/docs/webapi/waitForVisible.mustache +2 -2
- package/docs/webapi/waitInUrl.mustache +1 -1
- package/docs/webapi/waitNumberOfVisibleElements.mustache +2 -2
- package/docs/webapi/waitToHide.mustache +2 -2
- package/docs/webapi/waitUntil.mustache +3 -2
- package/docs/webapi/waitUrlEquals.mustache +1 -1
- package/docs/webdriver.md +20 -18
- package/docs/wiki/.git/FETCH_HEAD +1 -0
- package/docs/wiki/.git/HEAD +1 -0
- package/docs/wiki/.git/ORIG_HEAD +1 -0
- package/docs/wiki/.git/config +11 -0
- package/docs/wiki/.git/description +1 -0
- package/docs/wiki/.git/hooks/applypatch-msg.sample +15 -0
- package/docs/wiki/.git/hooks/commit-msg.sample +24 -0
- package/docs/wiki/.git/hooks/fsmonitor-watchman.sample +114 -0
- package/docs/wiki/.git/hooks/post-update.sample +8 -0
- package/docs/wiki/.git/hooks/pre-applypatch.sample +14 -0
- package/docs/wiki/.git/hooks/pre-commit.sample +49 -0
- package/docs/wiki/.git/hooks/pre-push.sample +53 -0
- package/docs/wiki/.git/hooks/pre-rebase.sample +169 -0
- package/docs/wiki/.git/hooks/pre-receive.sample +24 -0
- package/docs/wiki/.git/hooks/prepare-commit-msg.sample +42 -0
- package/docs/wiki/.git/hooks/update.sample +128 -0
- package/docs/wiki/.git/index +0 -0
- package/docs/wiki/.git/info/exclude +6 -0
- package/docs/wiki/.git/logs/HEAD +4 -0
- package/docs/wiki/.git/logs/refs/heads/master +4 -0
- package/docs/wiki/.git/logs/refs/remotes/origin/HEAD +1 -0
- package/docs/wiki/.git/logs/refs/remotes/origin/master +3 -0
- package/docs/wiki/.git/objects/00/d216b0774d15db2d0a2a0d4ce249b5251acc55 +3 -0
- package/docs/wiki/.git/objects/09/01d87c5241905fdfe3493cfe8f04df4a2685ea +0 -0
- package/docs/wiki/.git/objects/0d/bdd0c20c4deb6a8cc81dbbf32ecf8c09238983 +2 -0
- package/docs/wiki/.git/objects/1a/c29e4fa82422c52392f22f0f2b8d1a759535bf +0 -0
- package/docs/wiki/.git/objects/27/12f92898d3e8f68e229b6cda76570d6c66d781 +0 -0
- package/docs/wiki/.git/objects/2d/dbe22c257166b648928eeb9460ecfb71ba702d +0 -0
- package/docs/wiki/.git/objects/2f/c942ec3773efd2678d9ff98035c61fcded81a1 +0 -0
- package/docs/wiki/.git/objects/40/a2856342c67796b48911a256b764fb06888b94 +5 -0
- package/docs/wiki/.git/objects/47/53181844fc4dc563cf3aa5e80462243cb58d38 +0 -0
- package/docs/wiki/.git/objects/4e/24a95fb2e4f8ffef51f19b694451a205c06f10 +3 -0
- package/docs/wiki/.git/objects/73/31ebd96f3c7e08a9f63f05a25f939afa0d4de1 +0 -0
- package/docs/wiki/.git/objects/86/19cbb2289caa502e33fccf0ed14eecf6ba2ba0 +0 -0
- package/docs/wiki/.git/objects/a4/72f797d9d74b87c9f71a2b1539d75bb07d1e35 +0 -0
- package/docs/wiki/.git/objects/c9/9f3e4bd227d6b050b2e416f9876df49583dbf6 +0 -0
- package/docs/wiki/.git/objects/ca/e609b4ef3e0ef85fcbe0d68d1a58246584b915 +0 -0
- package/docs/wiki/.git/objects/d5/8386ca72f6d550548f3d71d74e3ac73d5ad488 +0 -0
- package/docs/wiki/.git/objects/d9/c6874a6de524bdafeb563a20d847f4fdd59a86 +0 -0
- package/docs/wiki/.git/objects/f1/c944675bb38b40ae553b0be36c14674c79af54 +0 -0
- package/docs/wiki/.git/objects/pack/pack-28da0fc7e6c08d4c5350717bfbb7b1c53e8198ad.idx +0 -0
- package/docs/wiki/.git/objects/pack/pack-28da0fc7e6c08d4c5350717bfbb7b1c53e8198ad.pack +0 -0
- package/docs/wiki/.git/packed-refs +2 -0
- package/docs/wiki/.git/refs/heads/master +1 -0
- package/docs/wiki/.git/refs/remotes/origin/HEAD +1 -0
- package/docs/wiki/.git/refs/remotes/origin/master +1 -0
- package/docs/wiki/Books-&-Posts.md +27 -0
- package/docs/wiki/Community-Helpers.md +41 -0
- package/docs/wiki/Examples.md +138 -0
- package/docs/wiki/Home.md +11 -0
- package/docs/wiki/Release-process.md +25 -0
- package/docs/wiki/Roadmap.md +23 -0
- package/docs/wiki/Videos.md +19 -0
- package/lib/actor.js +18 -1
- package/lib/assert/error.js +3 -3
- package/lib/codecept.js +9 -6
- package/lib/command/configMigrate.js +7 -6
- package/lib/command/definitions.js +98 -350
- package/lib/command/generate.js +22 -17
- package/lib/command/gherkin/init.js +2 -1
- package/lib/command/gherkin/snippets.js +6 -6
- package/lib/command/gherkin/steps.js +0 -1
- package/lib/command/info.js +40 -0
- package/lib/command/init.js +54 -41
- package/lib/command/run-multiple.js +5 -4
- package/lib/command/run-rerun.js +39 -0
- package/lib/command/run-workers.js +4 -6
- package/lib/command/run.js +8 -18
- package/lib/command/utils.js +23 -2
- package/lib/command/workers/runTests.js +1 -2
- package/lib/config.js +10 -4
- package/lib/container.js +31 -6
- package/lib/data/dataTableArgument.js +31 -0
- package/lib/data/table.js +4 -0
- package/lib/event.js +65 -1
- package/lib/helper/Appium.js +52 -38
- package/lib/helper/FileSystem.js +48 -3
- package/lib/helper/GraphQL.js +3 -2
- package/lib/helper/GraphQLDataFactory.js +1 -0
- package/lib/helper/Mochawesome.js +3 -2
- package/lib/helper/MockRequest.js +23 -5
- package/lib/helper/Nightmare.js +5 -6
- package/lib/helper/Protractor.js +7 -8
- package/lib/helper/Puppeteer.js +76 -20
- package/lib/helper/REST.js +13 -9
- package/lib/helper/SeleniumWebdriver.js +0 -17
- package/lib/helper/TestCafe.js +84 -36
- package/lib/helper/WebDriver.js +113 -59
- package/lib/helper/WebDriverIO.js +43 -59
- package/lib/helper/clientscripts/nightmare.js +66 -4
- package/lib/helper/scripts/isElementClickable.js +24 -0
- package/lib/helper.js +34 -10
- package/lib/history.js +1 -1
- package/lib/hooks.js +2 -1
- package/lib/index.js +19 -0
- package/lib/interfaces/bdd.js +4 -0
- package/lib/interfaces/featureConfig.js +10 -3
- package/lib/interfaces/gherkin.js +6 -2
- package/lib/interfaces/scenarioConfig.js +17 -6
- package/lib/listener/config.js +1 -1
- package/lib/listener/exit.js +6 -0
- package/lib/listener/steps.js +0 -1
- package/lib/listener/trace.js +0 -1
- package/lib/locator.js +67 -2
- package/lib/output.js +53 -0
- package/lib/parser.js +2 -71
- package/lib/pause.js +3 -2
- package/lib/plugin/allure.js +41 -22
- package/lib/plugin/autoLogin.js +4 -1
- package/lib/plugin/pauseOnFail.js +38 -0
- package/lib/plugin/puppeteerCoverage.js +8 -7
- package/lib/plugin/screenshotOnFail.js +13 -8
- package/lib/plugin/stepByStepReport.js +7 -6
- package/lib/plugin/wdio.js +2 -1
- package/lib/recorder.js +85 -7
- package/lib/rerun.js +81 -0
- package/lib/secret.js +6 -0
- package/lib/session.js +9 -2
- package/lib/step.js +37 -2
- package/lib/store.js +5 -1
- package/lib/ui.js +34 -8
- package/lib/utils.js +6 -13
- package/lib/within.js +5 -0
- package/package.json +49 -29
- package/typings/Mocha.d.ts +21 -0
- package/typings/Protractor.d.ts +16 -0
- package/typings/index.d.ts +169 -0
- package/typings/jsdoc.conf.js +34 -0
- package/typings/jsdoc.namespace.js +29 -0
- package/typings/types.d.ts +9827 -0
- package/typings/utils.d.ts +7 -0
- package/docs/acceptance.md +0 -409
- package/docs/api/codecept.md +0 -75
- package/docs/api/config.md +0 -49
- package/docs/api/container.md +0 -66
- package/docs/api/helper.md +0 -116
- package/docs/api/output.md +0 -67
- package/docs/api/recorder.md +0 -63
- package/docs/helpers/SeleniumWebdriver.md +0 -92
- package/docs/helpers/WebDriverIO.md +0 -1671
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type ValueOf<T> = T[keyof T]
|
|
2
|
+
type KeyValueTupleToObject<T extends [keyof any, any]> = {
|
|
3
|
+
[K in T[0]]: Extract<T, [K, any]>[1]
|
|
4
|
+
}
|
|
5
|
+
export type Translate<T, M extends Record<string, string>> = KeyValueTupleToObject<ValueOf<{
|
|
6
|
+
[K in keyof T]: [K extends keyof M ? M[K] : K, T[K]]
|
|
7
|
+
}>>
|
package/docs/acceptance.md
DELETED
|
@@ -1,409 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
id: acceptance
|
|
3
|
-
title: Acceptance Testing
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
How does your client, manager, or tester, or any other non-technical person, know your web application is working? By opening the browser, accessing a site, clicking on links, filling in the forms, and actually seeing the content on a web page.
|
|
7
|
-
|
|
8
|
-
Acceptance (also called End to End) tests can cover standard but complex scenarios from a user's perspective. With acceptance tests you can be confident that users, following all defined scenarios, won't get errors. We check **not just functionality of application but a user interface** (UI) as well.
|
|
9
|
-
|
|
10
|
-
By default CodeceptJS uses [WebDriver](/helpers/WebDriver/) helper and **Selenium** to automate browser. Within web page you can locate elements, interact with them, and check that expected elements are present on a page.
|
|
11
|
-
However, you can also choose [Puppeteer](/helpers/Puppeteer), [Nightmare](/helpers/Nightmare) or [Protractor](/helpers/Protractor) helpers, driven by corresponding libraries.
|
|
12
|
-
No matter of helper and library you use for acceptance testing, CodeceptJS should execute same actions in similar manner.
|
|
13
|
-
|
|
14
|
-
In case of CodeceptJS you can be sure that in code it will be as easy as it sounds. You just describe a test scenario with JavaScript DSL and allow the framework to handle the rest.
|
|
15
|
-
|
|
16
|
-
Within web page you can locate elements, interact with them, and check that expected elements are present on a page. That is what a test look like.
|
|
17
|
-
That is what a test look like.
|
|
18
|
-
|
|
19
|
-
```js
|
|
20
|
-
I.amOnPage('/login');
|
|
21
|
-
I.fillField('Username', 'john');
|
|
22
|
-
I.fillField('Password', '123456');
|
|
23
|
-
I.click('Login');
|
|
24
|
-
I.see('Welcome, John');
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
This is how we can check that login form of a simple web application works. At first we opened `/login` page, then filled forms and in the end we saw the greetings text.
|
|
28
|
-
|
|
29
|
-
## Locating Element
|
|
30
|
-
|
|
31
|
-
Element can be found by CSS or XPath locators. Practically every steps
|
|
32
|
-
in WebDriver helper accept them both.
|
|
33
|
-
|
|
34
|
-
```js
|
|
35
|
-
I.seeElement('.user'); // element with CSS class user
|
|
36
|
-
I.seeElement('//button[contains(., "press me")]'); // button
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
By default CodeceptJS tries to guess the locator type.
|
|
40
|
-
In order to specify exact locator type you can pass a hash called **strict locator**.
|
|
41
|
-
|
|
42
|
-
```js
|
|
43
|
-
I.seeElement({css: 'div.user'});
|
|
44
|
-
I.seeElement({xpath: '//div[@class=user]'});
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
Strict locators allow to specify additional locator types:
|
|
48
|
-
|
|
49
|
-
```js
|
|
50
|
-
// locate form element by name
|
|
51
|
-
I.seeElement({name: 'password'});
|
|
52
|
-
// locate element by id
|
|
53
|
-
I.seeElement({id: 'users'});
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
In [mobile testing](http://codecept.io/mobile/#locating-elements) you can use `~` to specify accessibility id to locate an element. In web application you can locate element by their `aria-label` value.
|
|
57
|
-
|
|
58
|
-
```js
|
|
59
|
-
// locate element by [aria-label] attribute in web
|
|
60
|
-
// or by accessibility id in mobile
|
|
61
|
-
I.seeElement('~username');
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## Clicking
|
|
65
|
-
|
|
66
|
-
CodeceptJS provides a flexible syntax to specify an element to click.
|
|
67
|
-
|
|
68
|
-
By default CodeceptJS tries to find button or link with exact text on it
|
|
69
|
-
|
|
70
|
-
```js
|
|
71
|
-
// search for link or button
|
|
72
|
-
I.click('Login');
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
If none found, CodeceptJS tries to find link or button containing that text. In case an image is clickable its `alt` attribute will be checked for text inclusion. Form buttons will also be searched by name.
|
|
76
|
-
|
|
77
|
-
To narrow down the results you can specify a context in second parameter.
|
|
78
|
-
|
|
79
|
-
```js
|
|
80
|
-
I.click('Login', '.nav'); // search only in .nav
|
|
81
|
-
I.click('Login', {css: 'footer'}); // search only in footer
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
To skip the global search pass exact strict locator (or start locator with `//` or `.` or `#`).
|
|
85
|
-
In this case you are not limited to buttons and links. Any element found by that locator is clicked.
|
|
86
|
-
|
|
87
|
-
```js
|
|
88
|
-
// click element by CSS
|
|
89
|
-
I.click('#signup');
|
|
90
|
-
// click element located by name inside a form
|
|
91
|
-
I.click({name: 'submit'}, '#user>form');
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
## Filling Fields
|
|
95
|
-
|
|
96
|
-
Clicking the links is not what takes the most time during testing a web site. If your site consists only of links you can skip test automation. The most routine waste of time goes into the testing of forms. CodeceptJS provides several ways of doing that.
|
|
97
|
-
|
|
98
|
-
Let's submit this sample form for a test:
|
|
99
|
-
|
|
100
|
-
```html
|
|
101
|
-
<form method="post" action="/update" id="update_form">
|
|
102
|
-
<label for="user_name">Name</label>
|
|
103
|
-
<input type="text" name="user[name]" id="user_name" />
|
|
104
|
-
<label for="user_email">Email</label>
|
|
105
|
-
<input type="text" name="user[email]" id="user_email" />
|
|
106
|
-
<label for="user_gender">Gender</label>
|
|
107
|
-
<select id="user_gender" name="user[gender]">
|
|
108
|
-
<option value="m">Male</option>
|
|
109
|
-
<option value="f">Female</option>
|
|
110
|
-
</select>
|
|
111
|
-
<input type="submit" name="submitButton" value="Update" />
|
|
112
|
-
</form>
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
We need to fill in all those fields and click "Update" button. CodeceptJS matches form elements by their label, name, or by CSS or XPath locators.
|
|
116
|
-
|
|
117
|
-
```js
|
|
118
|
-
// we are using label to match user_name field
|
|
119
|
-
I.fillField('Name', 'Miles');
|
|
120
|
-
// we can use input name
|
|
121
|
-
I.fillField('user[email]','miles@davis.com');
|
|
122
|
-
// select element by label, choose option by text
|
|
123
|
-
I.selectOption('Gender','Male');
|
|
124
|
-
// click 'Update' button, found by text
|
|
125
|
-
I.click('Update');
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
Alternative scenario:
|
|
129
|
-
|
|
130
|
-
```js
|
|
131
|
-
// we are using CSS
|
|
132
|
-
I.fillField('#user_name', 'Miles');
|
|
133
|
-
I.fillField('#user_email','miles@davis.com');
|
|
134
|
-
// select element by label, option by value
|
|
135
|
-
I.selectOption('#user_gender','m');
|
|
136
|
-
// click 'Update' button, found by name
|
|
137
|
-
I.click('submitButton', '#update_form');
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
To fill in sensitive data use `secret` function:
|
|
141
|
-
|
|
142
|
-
```js
|
|
143
|
-
I.fillField('password', secret('123456'));
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
## Assertions
|
|
147
|
-
|
|
148
|
-
In order to verify the expected behavior of a web application, web page connects should be checked.
|
|
149
|
-
CodeceptJS provides built-in assertions for that. They start with `see` (or `dontSee`) prefix, as they describe user's current vision.
|
|
150
|
-
|
|
151
|
-
The most general and common assertion is `see`:
|
|
152
|
-
|
|
153
|
-
```js
|
|
154
|
-
// Just a visible text on a page
|
|
155
|
-
I.see('Hello');
|
|
156
|
-
// text inside .msg element
|
|
157
|
-
I.see('Hello', '.msg');
|
|
158
|
-
// opposite
|
|
159
|
-
I.dontSee('Bye');
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
You should provide a text as first argument, and optionally a locator to narrow the search context.
|
|
163
|
-
|
|
164
|
-
You can check that specific element exists (or not) on a page, as it was described in [Locating Element](#locating-element) section.
|
|
165
|
-
|
|
166
|
-
```js
|
|
167
|
-
I.seeElement('.notice');
|
|
168
|
-
I.dontSeeElement('.error');
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
Additional assertions:
|
|
172
|
-
|
|
173
|
-
```js
|
|
174
|
-
I.seeInCurrentUrl('/user/miles');
|
|
175
|
-
I.seeInField('user[name]', 'Miles');
|
|
176
|
-
I.seeInTitle('My Website');
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
To see all possible assertions see the helper's reference.
|
|
180
|
-
|
|
181
|
-
## Grabbing
|
|
182
|
-
|
|
183
|
-
Sometimes you need to retrieve a data from a page to use it in next steps of a scenario.
|
|
184
|
-
Imagine, application generates a password and you want to ensure that user can login using this password.
|
|
185
|
-
|
|
186
|
-
```js
|
|
187
|
-
Scenario('login with generated password', async (I) => {
|
|
188
|
-
I.fillField('email', 'miles@davis.com');
|
|
189
|
-
I.click('Generate Password');
|
|
190
|
-
const password = await I.grabTextFrom('#password');
|
|
191
|
-
I.click('Login');
|
|
192
|
-
I.fillField('email', 'miles@davis.com');
|
|
193
|
-
I.fillField('password', password);
|
|
194
|
-
I.click('Log in!');
|
|
195
|
-
I.see('Hello, Miles');
|
|
196
|
-
});
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
`grabTextFrom` action is used here to retrieve text from an element. All actions starting with `grab` prefix are expected to return data. In order to synchronize this step with a scenario you should pause test execution with `await` keyword of ES6. To make it work your test should be written inside a async function (notice `async` in its definition).
|
|
200
|
-
|
|
201
|
-
```js
|
|
202
|
-
Scenario('use page title', async (I) => {
|
|
203
|
-
// ...
|
|
204
|
-
const password = await I.grabTextFrom('#password');
|
|
205
|
-
I.fillField('password', password);
|
|
206
|
-
});
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
## Waiting
|
|
210
|
-
|
|
211
|
-
In modern web applications rendering is happen on client side.
|
|
212
|
-
Sometimes that may cause delays. A test may fail while trying to click an element which has not appeared on a page yet.
|
|
213
|
-
To handle this cases `wait*` methods introduced.
|
|
214
|
-
|
|
215
|
-
```js
|
|
216
|
-
I.waitForElement('#agree_button', 30); // secs
|
|
217
|
-
// clicks a button only when it is visible
|
|
218
|
-
I.click('#agree_button');
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
More wait actions can be found in helper's reference.
|
|
222
|
-
|
|
223
|
-
## SmartWait
|
|
224
|
-
|
|
225
|
-
It is possible to wait for elements pragmatically. If a test uses element which is not on a page yet, CodeceptJS will wait for few extra seconds before failing. This feature is based on [Implicit Wait](http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp#implicit-waits) of Selenium. CodeceptJS enables implicit wait only when searching for a specific element and disables in all other cases. Thus, the performance of a test is not affected.
|
|
226
|
-
|
|
227
|
-
SmartWait can be enabled by setting wait option in WebDriver config.
|
|
228
|
-
Add `"smartWait": 5000` to wait for additional 5s.
|
|
229
|
-
|
|
230
|
-
SmartWait works with a CSS/XPath locators in `click`, `seeElement` and other methods. See where it is enabled and where is not:
|
|
231
|
-
|
|
232
|
-
```js
|
|
233
|
-
I.click('Login'); // DISABLED, not a locator
|
|
234
|
-
I.fillField('user', 'davert'); // DISABLED, not a specific locator
|
|
235
|
-
I.fillField({name: 'password'}, '123456'); // ENABLED, strict locator
|
|
236
|
-
I.click('#login'); // ENABLED, locator is CSS ID
|
|
237
|
-
I.see('Hello, Davert'); // DISABLED, Not a locator
|
|
238
|
-
I.seeElement('#userbar'); // ENABLED
|
|
239
|
-
I.dontSeeElement('#login'); // DISABLED, can't wait for element to hide
|
|
240
|
-
I.seeNumberOfElements('button.link', 5); // DISABLED, can wait only for one element
|
|
241
|
-
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
SmartWait doesn't check element for visibility, so tests may fail even element is on a page.
|
|
245
|
-
|
|
246
|
-
Usage example:
|
|
247
|
-
|
|
248
|
-
```js
|
|
249
|
-
// we use smartWait: 5000 instead of
|
|
250
|
-
// I.waitForElement('#click-me', 5);
|
|
251
|
-
// to wait for element on page
|
|
252
|
-
I.click('#click-me');
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
If it's hard to define what to wait, it is recommended to use [retries](https://codecept.io/basics/#retries) to rerun flaky steps.
|
|
256
|
-
|
|
257
|
-
## IFrames
|
|
258
|
-
|
|
259
|
-
[within](/basics/#within) operator can be used to work inside IFrames. Special `frame` locator is required to locate the iframe and get into its context.
|
|
260
|
-
|
|
261
|
-
See example:
|
|
262
|
-
|
|
263
|
-
```js
|
|
264
|
-
within({frame: "#editor"}, () => {
|
|
265
|
-
I.see('Page');
|
|
266
|
-
});
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
Nested IFrames can be set by passing array *(WebDriver, Nightmare & Puppeteer only)*:
|
|
270
|
-
|
|
271
|
-
```js
|
|
272
|
-
within({frame: [".content", "#editor"]}, () => {
|
|
273
|
-
I.see('Page');
|
|
274
|
-
});
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
## Auto Login
|
|
279
|
-
|
|
280
|
-
To share the same user session across different tests CodeceptJS provides [autoLogin plugin](https://codecept.io/plugins#autologin). It simplifies login management and reduces time consuming login operations. Instead of filling in login form before each test it saves the cookies of a valid user session and reuses it for next tests. If a session expires or doesn't exist, logs in a user again.
|
|
281
|
-
|
|
282
|
-
This plugin requires some configuration but is very simple in use:
|
|
283
|
-
|
|
284
|
-
```js
|
|
285
|
-
Scenario('do something with logged in user', (I, login)) => {
|
|
286
|
-
login('user');
|
|
287
|
-
I.see('Dashboard','h1');
|
|
288
|
-
});
|
|
289
|
-
```
|
|
290
|
-
|
|
291
|
-
With `autoLogin` plugin you can save cookies into a file and reuse same session on different runs.
|
|
292
|
-
|
|
293
|
-
> Read more about setting up [autoLogin](https://codecept.io/plugins#autologin)
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
## Multiple Sessions
|
|
297
|
-
|
|
298
|
-
CodeceptJS allows to run several browser sessions inside a test. This can be useful for testing communication between users inside a system, for instance in chats. To open another browser use `session()` function as shown in example:
|
|
299
|
-
|
|
300
|
-
```js
|
|
301
|
-
Scenario('test app', (I) => {
|
|
302
|
-
I.amOnPage('/chat');
|
|
303
|
-
I.fillField('name', 'davert');
|
|
304
|
-
I.click('Sign In');
|
|
305
|
-
I.see('Hello, davert');
|
|
306
|
-
session('john', () => {
|
|
307
|
-
// another session started
|
|
308
|
-
I.amOnPage('/chat');
|
|
309
|
-
I.fillField('name', 'john');
|
|
310
|
-
I.click('Sign In');
|
|
311
|
-
I.see('Hello, john');
|
|
312
|
-
});
|
|
313
|
-
// switching back to default session
|
|
314
|
-
I.fillField('message', 'Hi, john');
|
|
315
|
-
// there is a message from current user
|
|
316
|
-
I.see('me: Hi, john', '.messages');
|
|
317
|
-
session('john', () => {
|
|
318
|
-
// let's check if john received it
|
|
319
|
-
I.see('davert: Hi, john', '.messages');
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
`session` function expects a first parameter to be a name of a session. You can switch back to session by using the same name.
|
|
325
|
-
|
|
326
|
-
You can override config for session by passing second parameter:
|
|
327
|
-
|
|
328
|
-
```js
|
|
329
|
-
session('john', { browser: 'firefox' } , () => {
|
|
330
|
-
// run this steps in firefox
|
|
331
|
-
I.amOnPage('/');
|
|
332
|
-
});
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
or just start session without switching to it. Call `session` passing only its name:
|
|
336
|
-
|
|
337
|
-
```js
|
|
338
|
-
Scenario('test', (I) => {
|
|
339
|
-
// opens 3 additional browsers
|
|
340
|
-
session('john');
|
|
341
|
-
session('mary');
|
|
342
|
-
session('jane');
|
|
343
|
-
|
|
344
|
-
I.amOnPage('/');
|
|
345
|
-
|
|
346
|
-
// switch to session by its name
|
|
347
|
-
session('mary', () => {
|
|
348
|
-
I.amOnPage('/login');
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
```
|
|
352
|
-
`session` can return value which can be used in scenario:
|
|
353
|
-
|
|
354
|
-
```js
|
|
355
|
-
// inside async function
|
|
356
|
-
const val = await session('john', () => {
|
|
357
|
-
I.amOnPage('/info');
|
|
358
|
-
return I.grabTextFrom({ css: 'h1' });
|
|
359
|
-
});
|
|
360
|
-
I.fillField('Description', val);
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
Function passed into session can use `I`, page objects, and any objects declared for the scenario.
|
|
364
|
-
This function can also be declared as async (but doesn't work as generator).
|
|
365
|
-
|
|
366
|
-
Also, you can use `within` inside a session but you can't call session from inside `within`.
|
|
367
|
-
|
|
368
|
-
## Multiple Windows
|
|
369
|
-
|
|
370
|
-
CodeceptJS allows to use several browser windows inside a test. Sometimes we are testing the functionality of websites that we cannot control, such as a closed-source managed package, and there are popups that either remain open for configuring data on the screen, or close as a result of clicking a window. We can use these functions in order to gain more control over which page is being tested with Codecept at any given time. For example:
|
|
371
|
-
|
|
372
|
-
```js
|
|
373
|
-
const assert = require('assert');
|
|
374
|
-
|
|
375
|
-
Scenario('should open main page of configured site, open a popup, switch to main page, then switch to popup, close popup, and go back to main page', async (I) => {
|
|
376
|
-
I.amOnPage('/');
|
|
377
|
-
const handleBeforePopup = await I.grabCurrentWindowHandle();
|
|
378
|
-
const urlBeforePopup = await I.grabCurrentUrl();
|
|
379
|
-
const allHandlesBeforePopup = await I.grabAllWindowHandles();
|
|
380
|
-
assert.equal(allHandlesBeforePopup.length, 1, 'Single Window');
|
|
381
|
-
|
|
382
|
-
await I.executeScript(() => {
|
|
383
|
-
window.open('https://www.w3schools.com/', 'new window', 'toolbar=yes,scrollbars=yes,resizable=yes,width=400,height=400');
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
const allHandlesAfterPopup = await I.grabAllWindowHandles();
|
|
387
|
-
assert.equal(allHandlesAfterPopup.length, 2, 'Two Windows');
|
|
388
|
-
|
|
389
|
-
await I.switchToWindow(allHandlesAfterPopup[1]);
|
|
390
|
-
const urlAfterPopup = await I.grabCurrentUrl();
|
|
391
|
-
assert.equal(urlAfterPopup, 'https://www.w3schools.com/', 'Expected URL: Popup');
|
|
392
|
-
|
|
393
|
-
assert.equal(handleBeforePopup, allHandlesAfterPopup[0], 'Expected Window: Main Window');
|
|
394
|
-
await I.switchToWindow(handleBeforePopup);
|
|
395
|
-
const currentURL = await I.grabCurrentUrl();
|
|
396
|
-
assert.equal(currentURL, urlBeforePopup, 'Expected URL: Main URL');
|
|
397
|
-
|
|
398
|
-
await I.switchToWindow(allHandlesAfterPopup[1]);
|
|
399
|
-
const urlAfterSwitchBack = await I.grabCurrentUrl();
|
|
400
|
-
assert.equal(urlAfterSwitchBack, 'https://www.w3schools.com/', 'Expected URL: Popup');
|
|
401
|
-
await I.closeCurrentTab();
|
|
402
|
-
|
|
403
|
-
const allHandlesAfterPopupClosed = await I.grabAllWindowHandles();
|
|
404
|
-
assert.equal(allHandlesAfterPopupClosed.length, 1, 'Single Window');
|
|
405
|
-
const currentWindowHandle = await I.grabCurrentWindowHandle();
|
|
406
|
-
assert.equal(currentWindowHandle, allHandlesAfterPopup[0], 'Expected Window: Main Window');
|
|
407
|
-
|
|
408
|
-
}).tag('@ProofOfConcept').tag('@grabAllWindowHandles').tag('@grabCurrentWindowHandle').tag('@switchToWindow');
|
|
409
|
-
```
|
package/docs/api/codecept.md
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
2
|
-
|
|
3
|
-
## Codecept
|
|
4
|
-
|
|
5
|
-
CodeceptJS runner
|
|
6
|
-
|
|
7
|
-
### Parameters
|
|
8
|
-
|
|
9
|
-
- `config` **any**
|
|
10
|
-
- `opts` **any**
|
|
11
|
-
|
|
12
|
-
### init
|
|
13
|
-
|
|
14
|
-
Initialize CodeceptJS at specific directory.
|
|
15
|
-
If async initialization is required, pass callback as second parameter.
|
|
16
|
-
|
|
17
|
-
#### Parameters
|
|
18
|
-
|
|
19
|
-
- `dir` **[string][1]**
|
|
20
|
-
|
|
21
|
-
### initGlobals
|
|
22
|
-
|
|
23
|
-
Creates global variables
|
|
24
|
-
|
|
25
|
-
#### Parameters
|
|
26
|
-
|
|
27
|
-
- `dir` **[string][1]**
|
|
28
|
-
|
|
29
|
-
### loadTests
|
|
30
|
-
|
|
31
|
-
Loads tests by pattern or by config.tests
|
|
32
|
-
|
|
33
|
-
#### Parameters
|
|
34
|
-
|
|
35
|
-
- `pattern` **[string][1]?**
|
|
36
|
-
|
|
37
|
-
### requireModules
|
|
38
|
-
|
|
39
|
-
Require modules before codeceptjs running
|
|
40
|
-
|
|
41
|
-
#### Parameters
|
|
42
|
-
|
|
43
|
-
- `requiringModules` **\[[string][1]]**
|
|
44
|
-
|
|
45
|
-
### run
|
|
46
|
-
|
|
47
|
-
Run a specific test or all loaded tests.
|
|
48
|
-
|
|
49
|
-
#### Parameters
|
|
50
|
-
|
|
51
|
-
- `test` **[string][1]?**
|
|
52
|
-
|
|
53
|
-
### runBootstrap
|
|
54
|
-
|
|
55
|
-
Executes bootstrap.
|
|
56
|
-
If bootstrap is async, second parameter is required.
|
|
57
|
-
|
|
58
|
-
#### Parameters
|
|
59
|
-
|
|
60
|
-
- `done`
|
|
61
|
-
|
|
62
|
-
### runHooks
|
|
63
|
-
|
|
64
|
-
Executes hooks.
|
|
65
|
-
|
|
66
|
-
### teardown
|
|
67
|
-
|
|
68
|
-
Executes teardown.
|
|
69
|
-
If teardown is async a parameter is provided.
|
|
70
|
-
|
|
71
|
-
#### Parameters
|
|
72
|
-
|
|
73
|
-
- `done` **any** (optional, default `undefined`)
|
|
74
|
-
|
|
75
|
-
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|
package/docs/api/config.md
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
2
|
-
|
|
3
|
-
## Config
|
|
4
|
-
|
|
5
|
-
Current configuration
|
|
6
|
-
|
|
7
|
-
### append
|
|
8
|
-
|
|
9
|
-
Appends values to current config
|
|
10
|
-
|
|
11
|
-
#### Parameters
|
|
12
|
-
|
|
13
|
-
- `additionalConfig` **any**
|
|
14
|
-
|
|
15
|
-
### create
|
|
16
|
-
|
|
17
|
-
Create a config with default options
|
|
18
|
-
|
|
19
|
-
#### Parameters
|
|
20
|
-
|
|
21
|
-
- `newConfig` **any**
|
|
22
|
-
|
|
23
|
-
### get
|
|
24
|
-
|
|
25
|
-
Get current config.
|
|
26
|
-
|
|
27
|
-
#### Parameters
|
|
28
|
-
|
|
29
|
-
- `key`
|
|
30
|
-
- `val`
|
|
31
|
-
|
|
32
|
-
### load
|
|
33
|
-
|
|
34
|
-
Load config from a file.
|
|
35
|
-
If js file provided: require it and get .config key
|
|
36
|
-
If json file provided: load and parse JSON
|
|
37
|
-
If directory provided:
|
|
38
|
-
|
|
39
|
-
- try to load `codecept.conf.js` from it
|
|
40
|
-
- try to load `codecept.json` from it
|
|
41
|
-
If none of above: fail.
|
|
42
|
-
|
|
43
|
-
#### Parameters
|
|
44
|
-
|
|
45
|
-
- `configFile` **any**
|
|
46
|
-
|
|
47
|
-
### reset
|
|
48
|
-
|
|
49
|
-
Resets config to default
|
package/docs/api/container.md
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
|
|
2
|
-
|
|
3
|
-
## Container
|
|
4
|
-
|
|
5
|
-
Dependency Injection Container
|
|
6
|
-
|
|
7
|
-
### append
|
|
8
|
-
|
|
9
|
-
Append new services to container
|
|
10
|
-
|
|
11
|
-
#### Parameters
|
|
12
|
-
|
|
13
|
-
- `newContainer`
|
|
14
|
-
|
|
15
|
-
### clear
|
|
16
|
-
|
|
17
|
-
Clear container
|
|
18
|
-
|
|
19
|
-
#### Parameters
|
|
20
|
-
|
|
21
|
-
- `newHelpers` **any**
|
|
22
|
-
- `newSupport` **any**
|
|
23
|
-
- `newPlugins`
|
|
24
|
-
|
|
25
|
-
### create
|
|
26
|
-
|
|
27
|
-
Create container with all required helpers and support objects
|
|
28
|
-
|
|
29
|
-
#### Parameters
|
|
30
|
-
|
|
31
|
-
- `config` **any**
|
|
32
|
-
- `opts` **any**
|
|
33
|
-
|
|
34
|
-
### helpers
|
|
35
|
-
|
|
36
|
-
Get all helpers or get a helper by name
|
|
37
|
-
|
|
38
|
-
#### Parameters
|
|
39
|
-
|
|
40
|
-
- `name` **[string][1]?**
|
|
41
|
-
|
|
42
|
-
### mocha
|
|
43
|
-
|
|
44
|
-
Get Mocha instance
|
|
45
|
-
|
|
46
|
-
### plugins
|
|
47
|
-
|
|
48
|
-
Get all plugins
|
|
49
|
-
|
|
50
|
-
#### Parameters
|
|
51
|
-
|
|
52
|
-
- `name` **[string][1]?**
|
|
53
|
-
|
|
54
|
-
### support
|
|
55
|
-
|
|
56
|
-
Get all support objects or get support object by name
|
|
57
|
-
|
|
58
|
-
#### Parameters
|
|
59
|
-
|
|
60
|
-
- `name` **[string][1]?**
|
|
61
|
-
|
|
62
|
-
### translation
|
|
63
|
-
|
|
64
|
-
Get translation
|
|
65
|
-
|
|
66
|
-
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
|