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.
Files changed (269) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +28 -6
  3. package/bin/codecept.js +42 -0
  4. package/docs/advanced.md +45 -1
  5. package/docs/angular.md +3 -3
  6. package/docs/basics.md +162 -118
  7. package/docs/bdd.md +30 -5
  8. package/docs/best.md +8 -6
  9. package/docs/books.md +6 -1
  10. package/docs/build/Appium.js +95 -85
  11. package/docs/build/FileSystem.js +48 -3
  12. package/docs/build/GraphQL.js +3 -2
  13. package/docs/build/GraphQLDataFactory.js +1 -0
  14. package/docs/build/Mochawesome.js +3 -2
  15. package/docs/build/MockRequest.js +23 -5
  16. package/docs/build/Nightmare.js +87 -128
  17. package/docs/build/Protractor.js +107 -155
  18. package/docs/build/Puppeteer.js +190 -174
  19. package/docs/build/REST.js +13 -9
  20. package/docs/build/SeleniumWebdriver.js +0 -17
  21. package/docs/build/TestCafe.js +164 -158
  22. package/docs/build/WebDriver.js +236 -211
  23. package/docs/build/WebDriverIO.js +218 -187
  24. package/docs/changelog.md +57 -1
  25. package/docs/commands.md +41 -2
  26. package/docs/community-helpers.md +12 -1
  27. package/docs/configuration.md +5 -2
  28. package/docs/continuous-integration.md +22 -0
  29. package/docs/{helpers.md → custom-helpers.md} +16 -10
  30. package/docs/data.md +7 -6
  31. package/docs/detox.md +6 -6
  32. package/docs/email.md +4 -2
  33. package/docs/examples.md +22 -3
  34. package/docs/helpers/ApiDataFactory.md +15 -13
  35. package/docs/helpers/Appium.md +1011 -468
  36. package/docs/helpers/Detox.md +33 -26
  37. package/docs/helpers/FileSystem.md +43 -13
  38. package/docs/helpers/GraphQL.md +17 -15
  39. package/docs/helpers/GraphQLDataFactory.md +15 -13
  40. package/docs/helpers/Mochawesome.md +3 -1
  41. package/docs/helpers/MockRequest.md +37 -19
  42. package/docs/helpers/Nightmare.md +129 -240
  43. package/docs/helpers/Polly.md +1 -1
  44. package/docs/helpers/Protractor.md +157 -298
  45. package/docs/helpers/Puppeteer.md +216 -335
  46. package/docs/helpers/REST.md +29 -24
  47. package/docs/helpers/TestCafe.md +137 -235
  48. package/docs/helpers/WebDriver.md +250 -347
  49. package/docs/hooks.md +14 -10
  50. package/docs/index.md +112 -0
  51. package/docs/installation.md +3 -1
  52. package/docs/locators.md +19 -8
  53. package/docs/mobile-react-native-locators.md +2 -2
  54. package/docs/mobile.md +5 -3
  55. package/docs/nightmare.md +2 -1
  56. package/docs/pageobjects.md +4 -2
  57. package/docs/parallel.md +4 -2
  58. package/docs/plugins.md +41 -15
  59. package/docs/puppeteer.md +8 -6
  60. package/docs/quickstart.md +130 -0
  61. package/docs/react.md +4 -2
  62. package/docs/reports.md +6 -4
  63. package/docs/testcafe.md +10 -8
  64. package/docs/translation.md +4 -2
  65. package/docs/ui.md +56 -0
  66. package/docs/videos.md +11 -2
  67. package/docs/visual.md +7 -5
  68. package/docs/vue.md +121 -0
  69. package/docs/webapi/appendField.mustache +1 -1
  70. package/docs/webapi/attachFile.mustache +1 -1
  71. package/docs/webapi/checkOption.mustache +2 -2
  72. package/docs/webapi/clearCookie.mustache +1 -1
  73. package/docs/webapi/click.mustache +2 -2
  74. package/docs/webapi/clickLink.mustache +2 -2
  75. package/docs/webapi/dontSee.mustache +1 -2
  76. package/docs/webapi/dontSeeCheckboxIsChecked.mustache +1 -1
  77. package/docs/webapi/dontSeeElement.mustache +1 -1
  78. package/docs/webapi/dontSeeElementInDOM.mustache +1 -1
  79. package/docs/webapi/dontSeeInField.mustache +1 -1
  80. package/docs/webapi/doubleClick.mustache +2 -2
  81. package/docs/webapi/downloadFile.mustache +1 -1
  82. package/docs/webapi/dragSlider.mustache +1 -1
  83. package/docs/webapi/executeAsyncScript.mustache +2 -1
  84. package/docs/webapi/executeScript.mustache +2 -1
  85. package/docs/webapi/fillField.mustache +1 -1
  86. package/docs/webapi/grabAttributeFrom.mustache +1 -1
  87. package/docs/webapi/grabBrowserLogs.mustache +1 -1
  88. package/docs/webapi/grabCookie.mustache +2 -2
  89. package/docs/webapi/grabCssPropertyFrom.mustache +1 -1
  90. package/docs/webapi/grabHTMLFrom.mustache +1 -1
  91. package/docs/webapi/grabNumberOfVisibleElements.mustache +1 -1
  92. package/docs/webapi/grabPageScrollPosition.mustache +1 -1
  93. package/docs/webapi/grabTextFrom.mustache +2 -2
  94. package/docs/webapi/grabValueFrom.mustache +1 -1
  95. package/docs/webapi/moveCursorTo.mustache +3 -3
  96. package/docs/webapi/pressKey.mustache +1 -1
  97. package/docs/webapi/pressKeyWithKeyNormalization.mustache +1 -1
  98. package/docs/webapi/rightClick.mustache +2 -2
  99. package/docs/webapi/saveScreenshot.mustache +1 -1
  100. package/docs/webapi/scrollIntoView.mustache +10 -0
  101. package/docs/webapi/scrollTo.mustache +3 -3
  102. package/docs/webapi/see.mustache +1 -1
  103. package/docs/webapi/seeAttributesOnElements.mustache +1 -1
  104. package/docs/webapi/seeCheckboxIsChecked.mustache +1 -1
  105. package/docs/webapi/seeCssPropertiesOnElements.mustache +1 -1
  106. package/docs/webapi/seeElement.mustache +1 -1
  107. package/docs/webapi/seeElementInDOM.mustache +1 -1
  108. package/docs/webapi/seeInField.mustache +1 -1
  109. package/docs/webapi/seeNumberOfElements.mustache +1 -1
  110. package/docs/webapi/seeNumberOfVisibleElements.mustache +1 -1
  111. package/docs/webapi/seeTextEquals.mustache +8 -0
  112. package/docs/webapi/selectOption.mustache +2 -2
  113. package/docs/webapi/switchTo.mustache +1 -1
  114. package/docs/webapi/uncheckOption.mustache +2 -2
  115. package/docs/webapi/waitForClickable.mustache +10 -0
  116. package/docs/webapi/waitForDetached.mustache +2 -2
  117. package/docs/webapi/waitForElement.mustache +2 -2
  118. package/docs/webapi/waitForEnabled.mustache +2 -2
  119. package/docs/webapi/waitForFunction.mustache +2 -2
  120. package/docs/webapi/waitForInvisible.mustache +2 -2
  121. package/docs/webapi/waitForText.mustache +2 -2
  122. package/docs/webapi/waitForValue.mustache +1 -1
  123. package/docs/webapi/waitForVisible.mustache +2 -2
  124. package/docs/webapi/waitInUrl.mustache +1 -1
  125. package/docs/webapi/waitNumberOfVisibleElements.mustache +2 -2
  126. package/docs/webapi/waitToHide.mustache +2 -2
  127. package/docs/webapi/waitUntil.mustache +3 -2
  128. package/docs/webapi/waitUrlEquals.mustache +1 -1
  129. package/docs/webdriver.md +20 -18
  130. package/docs/wiki/.git/FETCH_HEAD +1 -0
  131. package/docs/wiki/.git/HEAD +1 -0
  132. package/docs/wiki/.git/ORIG_HEAD +1 -0
  133. package/docs/wiki/.git/config +11 -0
  134. package/docs/wiki/.git/description +1 -0
  135. package/docs/wiki/.git/hooks/applypatch-msg.sample +15 -0
  136. package/docs/wiki/.git/hooks/commit-msg.sample +24 -0
  137. package/docs/wiki/.git/hooks/fsmonitor-watchman.sample +114 -0
  138. package/docs/wiki/.git/hooks/post-update.sample +8 -0
  139. package/docs/wiki/.git/hooks/pre-applypatch.sample +14 -0
  140. package/docs/wiki/.git/hooks/pre-commit.sample +49 -0
  141. package/docs/wiki/.git/hooks/pre-push.sample +53 -0
  142. package/docs/wiki/.git/hooks/pre-rebase.sample +169 -0
  143. package/docs/wiki/.git/hooks/pre-receive.sample +24 -0
  144. package/docs/wiki/.git/hooks/prepare-commit-msg.sample +42 -0
  145. package/docs/wiki/.git/hooks/update.sample +128 -0
  146. package/docs/wiki/.git/index +0 -0
  147. package/docs/wiki/.git/info/exclude +6 -0
  148. package/docs/wiki/.git/logs/HEAD +4 -0
  149. package/docs/wiki/.git/logs/refs/heads/master +4 -0
  150. package/docs/wiki/.git/logs/refs/remotes/origin/HEAD +1 -0
  151. package/docs/wiki/.git/logs/refs/remotes/origin/master +3 -0
  152. package/docs/wiki/.git/objects/00/d216b0774d15db2d0a2a0d4ce249b5251acc55 +3 -0
  153. package/docs/wiki/.git/objects/09/01d87c5241905fdfe3493cfe8f04df4a2685ea +0 -0
  154. package/docs/wiki/.git/objects/0d/bdd0c20c4deb6a8cc81dbbf32ecf8c09238983 +2 -0
  155. package/docs/wiki/.git/objects/1a/c29e4fa82422c52392f22f0f2b8d1a759535bf +0 -0
  156. package/docs/wiki/.git/objects/27/12f92898d3e8f68e229b6cda76570d6c66d781 +0 -0
  157. package/docs/wiki/.git/objects/2d/dbe22c257166b648928eeb9460ecfb71ba702d +0 -0
  158. package/docs/wiki/.git/objects/2f/c942ec3773efd2678d9ff98035c61fcded81a1 +0 -0
  159. package/docs/wiki/.git/objects/40/a2856342c67796b48911a256b764fb06888b94 +5 -0
  160. package/docs/wiki/.git/objects/47/53181844fc4dc563cf3aa5e80462243cb58d38 +0 -0
  161. package/docs/wiki/.git/objects/4e/24a95fb2e4f8ffef51f19b694451a205c06f10 +3 -0
  162. package/docs/wiki/.git/objects/73/31ebd96f3c7e08a9f63f05a25f939afa0d4de1 +0 -0
  163. package/docs/wiki/.git/objects/86/19cbb2289caa502e33fccf0ed14eecf6ba2ba0 +0 -0
  164. package/docs/wiki/.git/objects/a4/72f797d9d74b87c9f71a2b1539d75bb07d1e35 +0 -0
  165. package/docs/wiki/.git/objects/c9/9f3e4bd227d6b050b2e416f9876df49583dbf6 +0 -0
  166. package/docs/wiki/.git/objects/ca/e609b4ef3e0ef85fcbe0d68d1a58246584b915 +0 -0
  167. package/docs/wiki/.git/objects/d5/8386ca72f6d550548f3d71d74e3ac73d5ad488 +0 -0
  168. package/docs/wiki/.git/objects/d9/c6874a6de524bdafeb563a20d847f4fdd59a86 +0 -0
  169. package/docs/wiki/.git/objects/f1/c944675bb38b40ae553b0be36c14674c79af54 +0 -0
  170. package/docs/wiki/.git/objects/pack/pack-28da0fc7e6c08d4c5350717bfbb7b1c53e8198ad.idx +0 -0
  171. package/docs/wiki/.git/objects/pack/pack-28da0fc7e6c08d4c5350717bfbb7b1c53e8198ad.pack +0 -0
  172. package/docs/wiki/.git/packed-refs +2 -0
  173. package/docs/wiki/.git/refs/heads/master +1 -0
  174. package/docs/wiki/.git/refs/remotes/origin/HEAD +1 -0
  175. package/docs/wiki/.git/refs/remotes/origin/master +1 -0
  176. package/docs/wiki/Books-&-Posts.md +27 -0
  177. package/docs/wiki/Community-Helpers.md +41 -0
  178. package/docs/wiki/Examples.md +138 -0
  179. package/docs/wiki/Home.md +11 -0
  180. package/docs/wiki/Release-process.md +25 -0
  181. package/docs/wiki/Roadmap.md +23 -0
  182. package/docs/wiki/Videos.md +19 -0
  183. package/lib/actor.js +18 -1
  184. package/lib/assert/error.js +3 -3
  185. package/lib/codecept.js +9 -6
  186. package/lib/command/configMigrate.js +7 -6
  187. package/lib/command/definitions.js +98 -350
  188. package/lib/command/generate.js +22 -17
  189. package/lib/command/gherkin/init.js +2 -1
  190. package/lib/command/gherkin/snippets.js +6 -6
  191. package/lib/command/gherkin/steps.js +0 -1
  192. package/lib/command/info.js +40 -0
  193. package/lib/command/init.js +54 -41
  194. package/lib/command/run-multiple.js +5 -4
  195. package/lib/command/run-rerun.js +39 -0
  196. package/lib/command/run-workers.js +4 -6
  197. package/lib/command/run.js +8 -18
  198. package/lib/command/utils.js +23 -2
  199. package/lib/command/workers/runTests.js +1 -2
  200. package/lib/config.js +10 -4
  201. package/lib/container.js +31 -6
  202. package/lib/data/dataTableArgument.js +31 -0
  203. package/lib/data/table.js +4 -0
  204. package/lib/event.js +65 -1
  205. package/lib/helper/Appium.js +52 -38
  206. package/lib/helper/FileSystem.js +48 -3
  207. package/lib/helper/GraphQL.js +3 -2
  208. package/lib/helper/GraphQLDataFactory.js +1 -0
  209. package/lib/helper/Mochawesome.js +3 -2
  210. package/lib/helper/MockRequest.js +23 -5
  211. package/lib/helper/Nightmare.js +5 -6
  212. package/lib/helper/Protractor.js +7 -8
  213. package/lib/helper/Puppeteer.js +76 -20
  214. package/lib/helper/REST.js +13 -9
  215. package/lib/helper/SeleniumWebdriver.js +0 -17
  216. package/lib/helper/TestCafe.js +84 -36
  217. package/lib/helper/WebDriver.js +113 -59
  218. package/lib/helper/WebDriverIO.js +43 -59
  219. package/lib/helper/clientscripts/nightmare.js +66 -4
  220. package/lib/helper/scripts/isElementClickable.js +24 -0
  221. package/lib/helper.js +34 -10
  222. package/lib/history.js +1 -1
  223. package/lib/hooks.js +2 -1
  224. package/lib/index.js +19 -0
  225. package/lib/interfaces/bdd.js +4 -0
  226. package/lib/interfaces/featureConfig.js +10 -3
  227. package/lib/interfaces/gherkin.js +6 -2
  228. package/lib/interfaces/scenarioConfig.js +17 -6
  229. package/lib/listener/config.js +1 -1
  230. package/lib/listener/exit.js +6 -0
  231. package/lib/listener/steps.js +0 -1
  232. package/lib/listener/trace.js +0 -1
  233. package/lib/locator.js +67 -2
  234. package/lib/output.js +53 -0
  235. package/lib/parser.js +2 -71
  236. package/lib/pause.js +3 -2
  237. package/lib/plugin/allure.js +41 -22
  238. package/lib/plugin/autoLogin.js +4 -1
  239. package/lib/plugin/pauseOnFail.js +38 -0
  240. package/lib/plugin/puppeteerCoverage.js +8 -7
  241. package/lib/plugin/screenshotOnFail.js +13 -8
  242. package/lib/plugin/stepByStepReport.js +7 -6
  243. package/lib/plugin/wdio.js +2 -1
  244. package/lib/recorder.js +85 -7
  245. package/lib/rerun.js +81 -0
  246. package/lib/secret.js +6 -0
  247. package/lib/session.js +9 -2
  248. package/lib/step.js +37 -2
  249. package/lib/store.js +5 -1
  250. package/lib/ui.js +34 -8
  251. package/lib/utils.js +6 -13
  252. package/lib/within.js +5 -0
  253. package/package.json +49 -29
  254. package/typings/Mocha.d.ts +21 -0
  255. package/typings/Protractor.d.ts +16 -0
  256. package/typings/index.d.ts +169 -0
  257. package/typings/jsdoc.conf.js +34 -0
  258. package/typings/jsdoc.namespace.js +29 -0
  259. package/typings/types.d.ts +9827 -0
  260. package/typings/utils.d.ts +7 -0
  261. package/docs/acceptance.md +0 -409
  262. package/docs/api/codecept.md +0 -75
  263. package/docs/api/config.md +0 -49
  264. package/docs/api/container.md +0 -66
  265. package/docs/api/helper.md +0 -116
  266. package/docs/api/output.md +0 -67
  267. package/docs/api/recorder.md +0 -63
  268. package/docs/helpers/SeleniumWebdriver.md +0 -92
  269. 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
+ }>>
@@ -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
- ```
@@ -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
@@ -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
@@ -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