codeceptjs 3.5.0 → 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.
Files changed (273) hide show
  1. package/README.md +24 -25
  2. package/lib/actor.js +6 -3
  3. package/lib/ai.js +12 -3
  4. package/lib/cli.js +12 -2
  5. package/lib/codecept.js +4 -0
  6. package/lib/colorUtils.js +10 -0
  7. package/lib/command/definitions.js +2 -7
  8. package/lib/command/dryRun.js +2 -1
  9. package/lib/command/info.js +24 -0
  10. package/lib/command/init.js +51 -5
  11. package/lib/command/run-multiple/collection.js +17 -5
  12. package/lib/command/run-multiple.js +4 -2
  13. package/lib/command/run-workers.js +66 -4
  14. package/lib/command/run.js +7 -0
  15. package/lib/command/workers/runTests.js +39 -0
  16. package/lib/data/context.js +14 -6
  17. package/lib/event.js +4 -0
  18. package/lib/helper/ApiDataFactory.js +2 -1
  19. package/lib/helper/Appium.js +73 -24
  20. package/lib/helper/Expect.js +422 -0
  21. package/lib/helper/FileSystem.js +1 -1
  22. package/lib/helper/GraphQL.js +25 -0
  23. package/lib/helper/Nightmare.js +9 -4
  24. package/lib/helper/OpenAI.js +14 -10
  25. package/lib/helper/Playwright.js +1205 -288
  26. package/lib/helper/Protractor.js +11 -6
  27. package/lib/helper/Puppeteer.js +173 -61
  28. package/lib/helper/TestCafe.js +44 -9
  29. package/lib/helper/WebDriver.js +231 -82
  30. package/lib/helper/errors/ElementNotFound.js +2 -1
  31. package/lib/helper/extras/PlaywrightReactVueLocator.js +38 -0
  32. package/lib/helper/scripts/blurElement.js +17 -0
  33. package/lib/helper/scripts/focusElement.js +17 -0
  34. package/lib/helper/scripts/highlightElement.js +2 -2
  35. package/lib/html.js +3 -3
  36. package/lib/interfaces/bdd.js +1 -1
  37. package/lib/interfaces/gherkin.js +37 -3
  38. package/lib/interfaces/scenarioConfig.js +1 -0
  39. package/lib/locator.js +17 -4
  40. package/lib/mochaFactory.js +2 -1
  41. package/lib/output.js +1 -1
  42. package/lib/pause.js +12 -9
  43. package/lib/plugin/autoLogin.js +45 -10
  44. package/lib/plugin/heal.js +47 -17
  45. package/lib/plugin/retryFailedStep.js +10 -1
  46. package/lib/plugin/retryTo.js +2 -4
  47. package/lib/plugin/selenoid.js +6 -1
  48. package/lib/plugin/standardActingHelpers.js +0 -2
  49. package/lib/plugin/stepByStepReport.js +2 -2
  50. package/lib/plugin/tryTo.js +5 -7
  51. package/lib/plugin/wdio.js +0 -1
  52. package/lib/recorder.js +20 -9
  53. package/lib/session.js +1 -1
  54. package/lib/step.js +30 -11
  55. package/lib/ui.js +1 -0
  56. package/lib/utils.js +18 -1
  57. package/lib/workers.js +28 -3
  58. package/package.json +108 -98
  59. package/translations/de-DE.js +5 -0
  60. package/translations/fr-FR.js +14 -1
  61. package/translations/it-IT.js +1 -0
  62. package/translations/ja-JP.js +5 -0
  63. package/translations/pl-PL.js +5 -0
  64. package/translations/pt-BR.js +1 -0
  65. package/translations/ru-RU.js +1 -0
  66. package/translations/zh-CN.js +5 -0
  67. package/translations/zh-TW.js +5 -0
  68. package/typings/index.d.ts +8 -6
  69. package/typings/promiseBasedTypes.d.ts +784 -822
  70. package/typings/types.d.ts +1214 -727
  71. package/CHANGELOG.md +0 -2492
  72. package/docs/advanced.md +0 -351
  73. package/docs/ai.md +0 -246
  74. package/docs/api.md +0 -323
  75. package/docs/basics.md +0 -980
  76. package/docs/bdd.md +0 -535
  77. package/docs/best.md +0 -237
  78. package/docs/books.md +0 -37
  79. package/docs/bootstrap.md +0 -135
  80. package/docs/build/ApiDataFactory.js +0 -409
  81. package/docs/build/Appium.js +0 -1978
  82. package/docs/build/FileSystem.js +0 -228
  83. package/docs/build/GraphQL.js +0 -204
  84. package/docs/build/GraphQLDataFactory.js +0 -309
  85. package/docs/build/JSONResponse.js +0 -338
  86. package/docs/build/Mochawesome.js +0 -71
  87. package/docs/build/Nightmare.js +0 -2147
  88. package/docs/build/OpenAI.js +0 -122
  89. package/docs/build/Playwright.js +0 -4134
  90. package/docs/build/Polly.js +0 -42
  91. package/docs/build/Protractor.js +0 -2701
  92. package/docs/build/Puppeteer.js +0 -3743
  93. package/docs/build/REST.js +0 -344
  94. package/docs/build/SeleniumWebdriver.js +0 -76
  95. package/docs/build/TestCafe.js +0 -2059
  96. package/docs/build/WebDriver.js +0 -4042
  97. package/docs/changelog.md +0 -2501
  98. package/docs/commands.md +0 -254
  99. package/docs/community-helpers.md +0 -58
  100. package/docs/configuration.md +0 -157
  101. package/docs/continuous-integration.md +0 -22
  102. package/docs/custom-helpers.md +0 -306
  103. package/docs/data.md +0 -375
  104. package/docs/detox.md +0 -235
  105. package/docs/docker.md +0 -137
  106. package/docs/email.md +0 -183
  107. package/docs/examples.md +0 -149
  108. package/docs/helpers/ApiDataFactory.md +0 -266
  109. package/docs/helpers/Appium.md +0 -1317
  110. package/docs/helpers/Detox.md +0 -586
  111. package/docs/helpers/FileSystem.md +0 -152
  112. package/docs/helpers/GraphQL.md +0 -130
  113. package/docs/helpers/GraphQLDataFactory.md +0 -226
  114. package/docs/helpers/JSONResponse.md +0 -254
  115. package/docs/helpers/Mochawesome.md +0 -8
  116. package/docs/helpers/MockRequest.md +0 -377
  117. package/docs/helpers/Nightmare.md +0 -1258
  118. package/docs/helpers/OpenAI.md +0 -70
  119. package/docs/helpers/Playwright.md +0 -2250
  120. package/docs/helpers/Polly.md +0 -44
  121. package/docs/helpers/Puppeteer-firefox.md +0 -86
  122. package/docs/helpers/Puppeteer.md +0 -2147
  123. package/docs/helpers/REST.md +0 -218
  124. package/docs/helpers/TestCafe.md +0 -1224
  125. package/docs/helpers/WebDriver.md +0 -2325
  126. package/docs/hooks.md +0 -340
  127. package/docs/index.md +0 -111
  128. package/docs/installation.md +0 -75
  129. package/docs/internal-api.md +0 -265
  130. package/docs/locators.md +0 -331
  131. package/docs/mobile-react-native-locators.md +0 -67
  132. package/docs/mobile.md +0 -344
  133. package/docs/nightmare.md +0 -223
  134. package/docs/pageobjects.md +0 -291
  135. package/docs/parallel.md +0 -288
  136. package/docs/playwright.md +0 -609
  137. package/docs/plugins.md +0 -1225
  138. package/docs/puppeteer.md +0 -316
  139. package/docs/quickstart.md +0 -163
  140. package/docs/react.md +0 -69
  141. package/docs/reports.md +0 -392
  142. package/docs/secrets.md +0 -36
  143. package/docs/shadow.md +0 -68
  144. package/docs/shared/keys.mustache +0 -31
  145. package/docs/shared/react.mustache +0 -1
  146. package/docs/testcafe.md +0 -174
  147. package/docs/translation.md +0 -247
  148. package/docs/tutorial.md +0 -271
  149. package/docs/typescript.md +0 -180
  150. package/docs/ui.md +0 -59
  151. package/docs/videos.md +0 -28
  152. package/docs/visual.md +0 -202
  153. package/docs/vue.md +0 -121
  154. package/docs/webapi/amOnPage.mustache +0 -11
  155. package/docs/webapi/appendField.mustache +0 -11
  156. package/docs/webapi/attachFile.mustache +0 -12
  157. package/docs/webapi/checkOption.mustache +0 -13
  158. package/docs/webapi/clearCookie.mustache +0 -10
  159. package/docs/webapi/clearField.mustache +0 -9
  160. package/docs/webapi/click.mustache +0 -25
  161. package/docs/webapi/clickLink.mustache +0 -8
  162. package/docs/webapi/closeCurrentTab.mustache +0 -7
  163. package/docs/webapi/closeOtherTabs.mustache +0 -8
  164. package/docs/webapi/dontSee.mustache +0 -11
  165. package/docs/webapi/dontSeeCheckboxIsChecked.mustache +0 -10
  166. package/docs/webapi/dontSeeCookie.mustache +0 -8
  167. package/docs/webapi/dontSeeCurrentUrlEquals.mustache +0 -10
  168. package/docs/webapi/dontSeeElement.mustache +0 -8
  169. package/docs/webapi/dontSeeElementInDOM.mustache +0 -8
  170. package/docs/webapi/dontSeeInCurrentUrl.mustache +0 -4
  171. package/docs/webapi/dontSeeInField.mustache +0 -11
  172. package/docs/webapi/dontSeeInSource.mustache +0 -8
  173. package/docs/webapi/dontSeeInTitle.mustache +0 -8
  174. package/docs/webapi/doubleClick.mustache +0 -13
  175. package/docs/webapi/downloadFile.mustache +0 -12
  176. package/docs/webapi/dragAndDrop.mustache +0 -9
  177. package/docs/webapi/dragSlider.mustache +0 -11
  178. package/docs/webapi/executeAsyncScript.mustache +0 -24
  179. package/docs/webapi/executeScript.mustache +0 -26
  180. package/docs/webapi/fillField.mustache +0 -16
  181. package/docs/webapi/forceClick.mustache +0 -28
  182. package/docs/webapi/forceRightClick.mustache +0 -18
  183. package/docs/webapi/grabAllWindowHandles.mustache +0 -7
  184. package/docs/webapi/grabAttributeFrom.mustache +0 -10
  185. package/docs/webapi/grabAttributeFromAll.mustache +0 -9
  186. package/docs/webapi/grabBrowserLogs.mustache +0 -9
  187. package/docs/webapi/grabCookie.mustache +0 -11
  188. package/docs/webapi/grabCssPropertyFrom.mustache +0 -11
  189. package/docs/webapi/grabCssPropertyFromAll.mustache +0 -10
  190. package/docs/webapi/grabCurrentUrl.mustache +0 -9
  191. package/docs/webapi/grabCurrentWindowHandle.mustache +0 -6
  192. package/docs/webapi/grabDataFromPerformanceTiming.mustache +0 -20
  193. package/docs/webapi/grabElementBoundingRect.mustache +0 -20
  194. package/docs/webapi/grabGeoLocation.mustache +0 -8
  195. package/docs/webapi/grabHTMLFrom.mustache +0 -10
  196. package/docs/webapi/grabHTMLFromAll.mustache +0 -9
  197. package/docs/webapi/grabNumberOfOpenTabs.mustache +0 -8
  198. package/docs/webapi/grabNumberOfVisibleElements.mustache +0 -9
  199. package/docs/webapi/grabPageScrollPosition.mustache +0 -8
  200. package/docs/webapi/grabPopupText.mustache +0 -5
  201. package/docs/webapi/grabSource.mustache +0 -8
  202. package/docs/webapi/grabTextFrom.mustache +0 -10
  203. package/docs/webapi/grabTextFromAll.mustache +0 -9
  204. package/docs/webapi/grabTitle.mustache +0 -8
  205. package/docs/webapi/grabValueFrom.mustache +0 -9
  206. package/docs/webapi/grabValueFromAll.mustache +0 -8
  207. package/docs/webapi/moveCursorTo.mustache +0 -12
  208. package/docs/webapi/openNewTab.mustache +0 -7
  209. package/docs/webapi/pressKey.mustache +0 -12
  210. package/docs/webapi/pressKeyDown.mustache +0 -12
  211. package/docs/webapi/pressKeyUp.mustache +0 -12
  212. package/docs/webapi/pressKeyWithKeyNormalization.mustache +0 -60
  213. package/docs/webapi/refreshPage.mustache +0 -6
  214. package/docs/webapi/resizeWindow.mustache +0 -6
  215. package/docs/webapi/rightClick.mustache +0 -14
  216. package/docs/webapi/saveElementScreenshot.mustache +0 -10
  217. package/docs/webapi/saveScreenshot.mustache +0 -12
  218. package/docs/webapi/say.mustache +0 -10
  219. package/docs/webapi/scrollIntoView.mustache +0 -11
  220. package/docs/webapi/scrollPageToBottom.mustache +0 -6
  221. package/docs/webapi/scrollPageToTop.mustache +0 -6
  222. package/docs/webapi/scrollTo.mustache +0 -12
  223. package/docs/webapi/see.mustache +0 -11
  224. package/docs/webapi/seeAttributesOnElements.mustache +0 -9
  225. package/docs/webapi/seeCheckboxIsChecked.mustache +0 -10
  226. package/docs/webapi/seeCookie.mustache +0 -8
  227. package/docs/webapi/seeCssPropertiesOnElements.mustache +0 -9
  228. package/docs/webapi/seeCurrentUrlEquals.mustache +0 -11
  229. package/docs/webapi/seeElement.mustache +0 -8
  230. package/docs/webapi/seeElementInDOM.mustache +0 -8
  231. package/docs/webapi/seeInCurrentUrl.mustache +0 -8
  232. package/docs/webapi/seeInField.mustache +0 -12
  233. package/docs/webapi/seeInPopup.mustache +0 -8
  234. package/docs/webapi/seeInSource.mustache +0 -7
  235. package/docs/webapi/seeInTitle.mustache +0 -8
  236. package/docs/webapi/seeNumberOfElements.mustache +0 -11
  237. package/docs/webapi/seeNumberOfVisibleElements.mustache +0 -10
  238. package/docs/webapi/seeTextEquals.mustache +0 -9
  239. package/docs/webapi/seeTitleEquals.mustache +0 -8
  240. package/docs/webapi/selectOption.mustache +0 -21
  241. package/docs/webapi/setCookie.mustache +0 -16
  242. package/docs/webapi/setGeoLocation.mustache +0 -12
  243. package/docs/webapi/switchTo.mustache +0 -9
  244. package/docs/webapi/switchToNextTab.mustache +0 -10
  245. package/docs/webapi/switchToPreviousTab.mustache +0 -10
  246. package/docs/webapi/type.mustache +0 -21
  247. package/docs/webapi/uncheckOption.mustache +0 -13
  248. package/docs/webapi/wait.mustache +0 -8
  249. package/docs/webapi/waitForClickable.mustache +0 -11
  250. package/docs/webapi/waitForDetached.mustache +0 -10
  251. package/docs/webapi/waitForElement.mustache +0 -11
  252. package/docs/webapi/waitForEnabled.mustache +0 -6
  253. package/docs/webapi/waitForFunction.mustache +0 -17
  254. package/docs/webapi/waitForInvisible.mustache +0 -10
  255. package/docs/webapi/waitForText.mustache +0 -13
  256. package/docs/webapi/waitForValue.mustache +0 -10
  257. package/docs/webapi/waitForVisible.mustache +0 -10
  258. package/docs/webapi/waitInUrl.mustache +0 -9
  259. package/docs/webapi/waitNumberOfVisibleElements.mustache +0 -10
  260. package/docs/webapi/waitToHide.mustache +0 -10
  261. package/docs/webapi/waitUrlEquals.mustache +0 -10
  262. package/docs/webdriver.md +0 -657
  263. package/docs/wiki/Books-&-Posts.md +0 -27
  264. package/docs/wiki/Community-Helpers-&-Plugins.md +0 -49
  265. package/docs/wiki/Converting-Playwright-to-Istanbul-Coverage.md +0 -29
  266. package/docs/wiki/Examples.md +0 -139
  267. package/docs/wiki/Google-Summer-of-Code-(GSoC)-2020.md +0 -68
  268. package/docs/wiki/Home.md +0 -16
  269. package/docs/wiki/Release-Process.md +0 -24
  270. package/docs/wiki/Roadmap.md +0 -23
  271. package/docs/wiki/Tests.md +0 -1393
  272. package/docs/wiki/Upgrading-to-CodeceptJS-3.md +0 -153
  273. package/docs/wiki/Videos.md +0 -19
@@ -1,265 +0,0 @@
1
- ---
2
- permalink: /internal-api
3
- title: Internal API
4
- ---
5
-
6
- ## Concepts
7
-
8
- In this guide we will overview the internal API of CodeceptJS.
9
- This knowledge is required for customization, writing plugins, etc.
10
-
11
- CodeceptJS provides an API which can be loaded via `require('codeceptjs')` when CodeceptJS is installed locally. Otherwise, you can load codeceptjs API via global `codeceptjs` object:
12
-
13
- ```js
14
- // via module
15
- const { recorder, event, output } = require('codeceptjs');
16
- // or using global object
17
- const { recorder, event, output } = codeceptjs;
18
- ```
19
-
20
- These internal objects are available:
21
-
22
- * [`codecept`](https://github.com/Codeception/CodeceptJS/blob/master/lib/codecept.js): test runner class
23
- * [`config`](https://github.com/Codeception/CodeceptJS/blob/master/lib/config.js): current codecept config
24
- * [`event`](https://github.com/Codeception/CodeceptJS/blob/master/lib/event.js): event listener
25
- * [`recorder`](https://github.com/Codeception/CodeceptJS/blob/master/lib/recorder.js): global promise chain
26
- * [`output`](https://github.com/Codeception/CodeceptJS/blob/master/lib/output.js): internal printer
27
- * [`container`](https://github.com/Codeception/CodeceptJS/blob/master/lib/container.js): dependency injection container for tests, includes current helpers and support objects
28
- * [`helper`](https://github.com/Codeception/CodeceptJS/blob/master/lib/helper.js): basic helper class
29
- * [`actor`](https://github.com/Codeception/CodeceptJS/blob/master/lib/actor.js): basic actor (I) class
30
-
31
- [API reference](https://github.com/Codeception/CodeceptJS/tree/master/docs/api) is available on GitHub.
32
- Also please check the source code of corresponding modules.
33
-
34
- ### Container
35
-
36
- CodeceptJS has a dependency injection container with helpers and support objects.
37
- They can be retrieved from the container:
38
-
39
- ```js
40
- const { container } = require('codeceptjs');
41
-
42
- // get object with all helpers
43
- const helpers = container.helpers();
44
-
45
- // get helper by name
46
- const { WebDriver } = container.helpers();
47
-
48
- // get support objects
49
- const supportObjects = container.support();
50
-
51
- // get support object by name
52
- const { UserPage } = container.support();
53
-
54
- // get all registered plugins
55
- const plugins = container.plugins();
56
- ```
57
-
58
- New objects can also be added to container in runtime:
59
-
60
- ```js
61
- const { container } = require('codeceptjs');
62
-
63
- container.append({
64
- helpers: { // add helper
65
- MyHelper: new MyHelper({ config1: 'val1' });
66
- },
67
- support: { // add page object
68
- UserPage: require('./pages/user');
69
- }
70
- })
71
- ```
72
-
73
- > Use this trick to define custom objects inside `boostrap` script
74
-
75
- The container also contains the current Mocha instance:
76
-
77
- ```js
78
- const mocha = container.mocha();
79
- ```
80
-
81
- ### Event Listeners
82
-
83
- CodeceptJS provides a module with an [event dispatcher and set of predefined events](https://github.com/Codeception/CodeceptJS/blob/master/lib/event.js).
84
-
85
- It can be required from codeceptjs package if it is installed locally.
86
-
87
- ```js
88
- const { event } = require('codeceptjs');
89
-
90
- module.exports = function() {
91
-
92
- event.dispatcher.on(event.test.before, function (test) {
93
-
94
- console.log('--- I am before test --');
95
-
96
- });
97
- }
98
- ```
99
-
100
- Available events:
101
-
102
- * `event.test.before(test)` - *async* when `Before` hooks from helpers and from test is executed
103
- * `event.test.after(test)` - *async* after each test
104
- * `event.test.started(test)` - *sync* at the very beginning of a test.
105
- * `event.test.passed(test)` - *sync* when test passed
106
- * `event.test.failed(test, error)` - *sync* when test failed
107
- * `event.test.finished(test)` - *sync* when test finished
108
- * `event.suite.before(suite)` - *async* before a suite
109
- * `event.suite.after(suite)` - *async* after a suite
110
- * `event.step.before(step)` - *async* when the step is scheduled for execution
111
- * `event.step.after(step)`- *async* after a step
112
- * `event.step.started(step)` - *sync* when step starts.
113
- * `event.step.passed(step)` - *sync* when step passed.
114
- * `event.step.failed(step, err)` - *sync* when step failed.
115
- * `event.step.finished(step)` - *sync* when step finishes.
116
- * `event.step.comment(step)` - *sync* fired for comments like `I.say`.
117
- * `event.all.before` - before running tests
118
- * `event.all.after` - after running tests
119
- * `event.all.result` - when results are printed
120
- * `event.workers.before` - before spawning workers in parallel run
121
- * `event.workers.after` - after workers finished in parallel run
122
-
123
-
124
- > *sync* - means that event is fired in the moment of the action happening.
125
- *async* - means that event is fired when an action is scheduled. Use `recorder` to schedule your actions.
126
-
127
- For further reference look for [currently available listeners](https://github.com/Codeception/CodeceptJS/tree/master/lib/listener) using the event system.
128
-
129
-
130
- ### Recorder
131
-
132
- To inject asynchronous functions in a test or before/after a test you can subscribe to corresponding event and register a function inside a recorder object. [Recorder](https://github.com/Codeception/CodeceptJS/blob/master/lib/recorder.js) represents a global promises chain.
133
-
134
- Provide a function in the first parameter, a function must be async or must return a promise:
135
-
136
- ```js
137
- const { event, recorder } = require('codeceptjs');
138
-
139
- module.exports = function() {
140
-
141
- event.dispatcher.on(event.test.before, function (test) {
142
-
143
- const request = require('request');
144
-
145
- recorder.add('create fixture data via API', function() {
146
- return new Promise((doneFn, errFn) => {
147
- request({
148
- baseUrl: 'http://api.site.com/',
149
- method: 'POST',
150
- url: '/users',
151
- json: { name: 'john', email: 'john@john.com' }
152
- }), (err, httpResponse, body) => {
153
- if (err) return errFn(err);
154
- doneFn();
155
- }
156
- });
157
- }
158
- });
159
- }
160
- ```
161
-
162
- ### Config
163
-
164
- CodeceptJS config can be accessed from `require('codeceptjs').config.get()`:
165
-
166
- ```js
167
- const { config } = require('codeceptjs');
168
-
169
- // config object has access to all values of the current config file
170
-
171
- if (config.get().myKey == 'value') {
172
- // run something
173
- }
174
- ```
175
-
176
-
177
- ### Output
178
-
179
- Output module provides four verbosity levels. Depending on the mode you can have different information printed using corresponding functions.
180
-
181
- * `default`: prints basic information using `output.print`
182
- * `steps`: toggled by `--steps` option, prints step execution
183
- * `debug`: toggled by `--debug` option, prints steps, and debug information with `output.debug`
184
- * `verbose`: toggled by `--verbose` prints debug information and internal logs with `output.log`
185
-
186
- It is recommended to avoid `console.log` and use output.* methods for printing.
187
-
188
- ```js
189
- const output = require('codeceptjs').output;
190
-
191
- output.print('This is basic information');
192
- output.debug('This is debug information');
193
- output.log('This is verbose logging information');
194
- ```
195
-
196
- #### Test Object
197
-
198
- The test events are providing a test object with following properties:
199
-
200
- * `title` title of the test
201
- * `body` test function as a string
202
- * `opts` additional test options like retries, and others
203
- * `pending` true if test is scheduled for execution and false if a test has finished
204
- * `tags` array of tags for this test
205
- * `artifacts` list of files attached to this test. Screenshots, videos and other files can be saved here and shared accross different reporters
206
- * `file` path to a file with a test
207
- * `steps` array of executed steps (available only in `test.passed`, `test.failed`, `test.finished` event)
208
- * `skipInfo` additional test options when test skipped
209
- * * `message` string with reason for skip
210
- * * `description` string with test body
211
- and others
212
-
213
- #### Step Object
214
-
215
- Step events provide step objects with following fields:
216
-
217
- * `name` name of a step, like 'see', 'click', and others
218
- * `actor` current actor, in most cases it is `I`
219
- * `helper` current helper instance used to execute this step
220
- * `helperMethod` corresponding helper method, in most cases is the same as `name`
221
- * `status` status of a step (passed or failed)
222
- * `prefix` if a step is executed inside `within` block contain within text, like: 'Within .js-signup-form'.
223
- * `args` passed arguments
224
-
225
- Whenever you execute tests with `--verbose` option you will see registered events and promises executed by a recorder.
226
-
227
- ## Custom Runner
228
-
229
- You can run CodeceptJS tests from your script.
230
-
231
- ```js
232
- const { codecept: Codecept } = require('codeceptjs');
233
-
234
- // define main config
235
- const config = {
236
- helpers: {
237
- WebDriver: {
238
- browser: 'chrome',
239
- url: 'http://localhost'
240
- }
241
- }
242
- };
243
-
244
- const opts = { steps: true };
245
-
246
- // run CodeceptJS inside async function
247
- (async () => {
248
- const codecept = new Codecept(config, options);
249
- codecept.init(__dirname);
250
-
251
- try {
252
- await codecept.bootstrap();
253
- codecept.loadTests('**_test.js');
254
- // run tests
255
- await codecept.run(test);
256
- } catch (err) {
257
- printError(err);
258
- process.exitCode = 1;
259
- } finally {
260
- await codecept.teardown();
261
- }
262
- })();
263
- ```
264
-
265
- > Also, you can run tests inside workers in a custom scripts. Please refer to the [parallel execution](/parallel) guide for more details.
package/docs/locators.md DELETED
@@ -1,331 +0,0 @@
1
- ---
2
- permalink: /locators
3
- title: Locators
4
- ---
5
-
6
- # Locators
7
-
8
- CodeceptJS provides flexible strategies for locating elements:
9
-
10
- * [CSS and XPath locators](#css-and-xpath)
11
- * [Semantic locators](#semantic-locators): by link text, by button text, by field names, etc.
12
- * [Locator Builder](#locator-builder)
13
- * [ID locators](#id-locators): by CSS id or by accessibility id
14
- * [Custom Locator Strategies](#custom-locators): by data attributes or whatever you prefer.
15
- * [Shadow DOM](/shadow): to access shadow dom elements
16
- * [React](/react): to access React elements by component names and props
17
-
18
- Most methods in CodeceptJS use locators which can be either a string or an object.
19
-
20
- If the locator is an object, it should have a single element, with the key signifying the locator type (`id`, `name`, `css`, `xpath`, `link`, `react`, `class` or `shadow`) and the value being the locator itself. This is called a "strict" locator.
21
-
22
- Examples:
23
-
24
- * {id: 'foo'} matches `<div id="foo">`
25
- * {name: 'foo'} matches `<div name="foo">`
26
- * {css: 'input[type=input][value=foo]'} matches `<input type="input" value="foo">`
27
- * {xpath: "//input[@type='submit'][contains(@value, 'foo')]"} matches `<input type="submit" value="foobar">`
28
- * {class: 'foo'} matches `<div class="foo">`
29
-
30
- Writing good locators can be tricky.
31
- The Mozilla team has written an excellent guide titled [Writing reliable locators for Selenium and WebDriver tests](https://blog.mozilla.org/webqa/2013/09/26/writing-reliable-locators-for-selenium-and-webdriver-tests/).
32
-
33
- If you prefer, you may also pass a string for the locator. This is called a "fuzzy" locator.
34
- In this case, CodeceptJS uses a variety of heuristics (depending on the exact method called) to determine what element you're referring to. If you are locating a clickable element or an input element, CodeceptJS will use [semantic locators](#semantic-locators).
35
-
36
- For example, here's the heuristic used for the `fillField` method:
37
-
38
- 1. Does the locator look like an ID selector (e.g. "#foo")? If so, try to find an input element matching that ID.
39
- 2. If nothing found, check if locator looks like a CSS selector. If so, run it.
40
- 3. If nothing found, check if locator looks like an XPath expression. If so, run it.
41
- 4. If nothing found, check if there is an input element with a corresponding name.
42
- 5. If nothing found, check if there is a label with specified text for input element.
43
- 6. If nothing found, throw an `ElementNotFound` exception.
44
-
45
- > ⚠ Be warned that fuzzy locators can be significantly slower than strict locators. If speed is a concern, it's recommended you stick with explicitly specifying the locator type via object syntax.
46
-
47
- It is recommended to avoid using implicit CSS locators in methods like `fillField` or `click`, where semantic locators are allowed.
48
- Use locator type to speed up search by various locator strategies.
49
-
50
- ```js
51
- // will search for "input[type=password]" text before trying to search by CSS
52
- I.fillField('input[type=password]', '123456');
53
- // replace with strict locator
54
- I.fillField({ css: 'input[type=password]' }, '123456');
55
- ```
56
-
57
- ## CSS and XPath
58
-
59
- Both CSS and XPath is supported. Usually CodeceptJS can guess locator's type:
60
-
61
- ```js
62
- // select by CSS
63
- I.seeElement('.user .profile');
64
- I.seeElement('#user-name');
65
-
66
- // select by XPath
67
- I.seeElement('//table/tr/td[position()=3]');
68
- ```
69
-
70
- To specify exact locator type use **strict locators**:
71
-
72
- ```js
73
- // it's not clear that 'button' is actual CSS locator
74
- I.seeElement({ css: 'button' });
75
-
76
- // it's not clear that 'descendant::table/tr' is actual XPath locator
77
- I.seeElement({ xpath: 'descendant::table/tr' });
78
- ```
79
-
80
- > ℹ Use [Locator Advicer](https://davertmik.github.io/locator/) to check quality of your locators.
81
-
82
- ## Semantic Locators
83
-
84
- CodeceptJS can guess an element's locator from context.
85
- For example, when clicking CodeceptJS will try to find a link or button by their text
86
- When typing into a field this field can be located by its name, placeholder.
87
-
88
- ```js
89
- I.click('Sign In');
90
- I.fillField('Username', 'davert');
91
- ```
92
-
93
- Various strategies are used to locate semantic elements. However, they may run slower than specifying locator by XPath or CSS.
94
-
95
- ## Locator Builder
96
-
97
- CodeceptJS provides a fluent builder to compose custom locators in JavaScript. Use `locate` function to start.
98
-
99
- To locate `a` element inside `label` with text: 'Hello' use:
100
-
101
- ```js
102
- locate('a')
103
- .withAttr({ href: '#' })
104
- .inside(locate('label').withText('Hello'));
105
- ```
106
-
107
- which will produce following XPath:
108
-
109
- ```
110
- .//a[@href = '#'][ancestor::label[contains(., 'Hello')]]
111
- ```
112
-
113
- Locator builder accepts both XPath and CSS as parameters but converts them to XPath as more feature-rich format.
114
- Sometimes provided locators can get very long so it's recommended to simplify the output by providing a brief description for generated XPath:
115
-
116
- ```js
117
- locate('//table')
118
- .find('a')
119
- .withText('Edit')
120
- .as('edit button')
121
- // will be printed as 'edit button'
122
- ```
123
-
124
- `locate` has following methods:
125
-
126
- #### find
127
-
128
- Finds an element inside a located.
129
-
130
- ```js
131
- // find td inside a table
132
- locate('table').find('td');
133
- ```
134
- Switches current element to found one.
135
- Can accept another `locate` call or strict locator.
136
-
137
- #### withAttr
138
-
139
- Find an element with provided attributes
140
-
141
- ```js
142
- // find input with placeholder 'Type in name'
143
- locate('input').withAttr({ placeholder: 'Type in name' });
144
- ```
145
-
146
- #### withChild
147
-
148
- Finds an element which contains a child element provided:
149
-
150
- ```js
151
- // finds form with <select> inside it
152
- locate('form').withChild('select');
153
- ```
154
-
155
- #### withDescendant
156
-
157
- Finds an element which contains a descendant element provided:
158
-
159
- ```js
160
- // finds form with <select> which is the descendant it
161
- locate('form').withDescendant('select');
162
- ```
163
-
164
- #### withText
165
-
166
- Finds element containing a text
167
-
168
- ```js
169
- locate('span').withText('Warning');
170
- ```
171
-
172
- #### first
173
-
174
- Get first element:
175
-
176
- ```js
177
- locate('#table td').first();
178
- ```
179
-
180
- #### last
181
-
182
- Get last element:
183
-
184
- ```js
185
- locate('#table td').last();
186
- ```
187
-
188
- #### at
189
-
190
- Get element at position:
191
-
192
- ```js
193
- // first element
194
- locate('#table td').at(1);
195
- // second element
196
- locate('#table td').at(2);
197
- // second element from end
198
- locate('#table td').at(-2);
199
- ```
200
-
201
- #### inside
202
-
203
- Finds an element which contains an provided ancestor:
204
-
205
- ```js
206
- // finds `select` element inside #user_profile
207
- locate('select').inside('form#user_profile');
208
- ```
209
-
210
- #### before
211
-
212
- Finds element located before the provided one
213
-
214
- ```js
215
- // finds `button` before .btn-cancel
216
- locate('button').before('.btn-cancel');
217
- ```
218
-
219
- #### after
220
-
221
- Finds element located after the provided one
222
-
223
- ```js
224
- // finds `button` after .btn-cancel
225
- locate('button').after('.btn-cancel');
226
- ```
227
-
228
- ## ID Locators
229
-
230
- ID locators are best to select the exact semantic element in web and mobile testing:
231
-
232
- * `#user` or `{ id: 'user' }` finds element with id="user"
233
- * `~user` finds element with accessibility id "user" (in Mobile testing) or with `aria-label=user`.
234
-
235
- ## Custom Locators
236
-
237
- CodeceptJS allows to create custom locator strategies and use them in tests. This way you can define your own handling of elements using specially prepared attributes of elements.
238
-
239
- What if you use special test attributes for locators such as `data-qa`, `data-test`, `test-id`, etc.
240
- We created [customLocator plugin](/plugins#customlocator) to declare rules for locating element.
241
-
242
- Instead of writing a full CSS locator like `[data-qa-id=user_name]` simplify it to `$user_name`.
243
-
244
- ```js
245
- // replace this:
246
- I.click({ css: '[data-test-id=register_button]'});
247
- // with this:
248
- I.click('$register_button');
249
- ```
250
-
251
- This plugin requires two options: locator prefix and actual attribute to match.
252
-
253
- > ℹ See [customLocator Plugin](/plugins#customlocator) reference to learn how to set it up.
254
-
255
- If you need more control over custom locators see how declare them manually without using a customLocator plugin.
256
-
257
- #### Custom Strict Locators
258
-
259
- If use locators of `data-element` attribute you can implement a strategy, which will allow you to use `{ data: 'my-element' }` as a valid locator.
260
-
261
- Custom locators should be implemented in a plugin or a bootstrap script using internal CodeceptJS API:
262
-
263
- ```js
264
- // inside a plugin or a bootstrap script:
265
- codeceptjs.locator.addFilter((providedLocator, locatorObj) => {
266
- // providedLocator - a locator in a format it was provided
267
- // locatorObj - a standrard locator object.
268
- if (providedLocator.data) {
269
- locatorObj.type = 'css';
270
- locatorObj.value = `[data-element=${providedLocator.data}]`
271
- }
272
- });
273
- ```
274
-
275
- That's all. New locator type is ready to use:
276
-
277
- ```js
278
- I.click({ data: 'user-login' });
279
- ```
280
-
281
- #### Custom String Locators
282
-
283
- What if we want to locators prefixed with `=` to match elements with exact text value.
284
- We can do that too:
285
-
286
- ```js
287
- // inside a plugin or a bootstrap script:
288
- codeceptjs.locator.addFilter((providedLocator, locatorObj) => {
289
- if (typeof providedLocator === 'string') {
290
- // this is a string
291
- if (providedLocator[0] === '=') {
292
- locatorObj.value = `.//*[text()="${providedLocator.substring(1)}"]`;
293
- locatorObj.type = 'xpath';
294
- }
295
- }
296
- });
297
- ```
298
- New locator strategy is ready to use:
299
-
300
-
301
- ```js
302
- I.click('=Login');
303
- ```
304
-
305
- #### Custom Strategy Locators
306
-
307
- CodeceptJS provides the option to specify custom locators that uses Custom Locator Strategies defined in the WebDriver configuration. It uses the WebDriverIO's [custom$](https://webdriver.io/docs/api/browser/custom$.html) locators internally to locate the elements on page.
308
- To use the defined Custom Locator Strategy add your custom strategy to your configuration.
309
-
310
- ```js
311
- // in codecept.conf.js
312
-
313
- const myStrat = (selector) => {
314
- return document.querySelectorAll(selector)
315
- }
316
-
317
- // under WebDriver Helpers Configuration
318
- WebDriver: {
319
- ...
320
- customLocatorStrategies: {
321
- custom: myStrat
322
- }
323
- }
324
- ```
325
-
326
- ```js
327
- I.click({custom: 'my-shadow-element-unique-css'})
328
- ```
329
-
330
-
331
- > For more details on locator object see [Locator](https://github.com/codeceptjs/CodeceptJS/blob/master/lib/locator.js) class implementation.
@@ -1,67 +0,0 @@
1
- ## Automating React Native apps
2
-
3
- ### Problem
4
-
5
- > ⚠️ **NOTE**: This problem is not actual starting from `react-native@0.65.x` [CHANGELOG](https://github.com/react-native-community/releases/blob/master/CHANGELOG.md#android-specific-9), [#381fb3](https://github.com/facebook/react-native/commit/381fb395ad9d2d48717a5d082aaedbecdd804554)
6
-
7
- Let's say we have a React Native app with component defined like this
8
- ```html
9
- <Button testID='someButton'>My button</Button>
10
- ```
11
-
12
- If you will try to execute a simple test like
13
- ```js
14
- I.tap('~someButton')
15
- ```
16
- it will work correctly on iOS (with XUITest driver), but on Android's UIAutomator2 it will give you an error
17
- ```
18
- Touch actions like "tap" need at least some kind of position information like "element", "x" or "y" options, you've none given.
19
- ```
20
-
21
- This happens because of the way React Native implements `testID` for Android, it puts provided value into the [View tag](https://developer.android.com/reference/android/view/View#tags),
22
- as could be found in the [source code](https://github.com/facebook/react-native/blob/19a88d7f4addcd9f95fd4908d50db37b3604b5b1/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java#L114).
23
- But UIAutomator doesn't have any means to work with view tags.
24
-
25
- ### Solutions
26
- As many resources suggest (like [here](https://github.com/appium/appium/issues/6025#issuecomment-406141946) or [here](https://github.com/facebook/react-native/issues/7135)),
27
- you could use `testID` for iOS and `accesibilityLabel` for Android, but `accessibilityLabel` is a user-facing text that's intended for ... accesibility,
28
- not for UI tests, and you will need to switch it off for production builds.
29
-
30
- Another way to solve this issue is to use Espresso driver for Android.
31
- At first you need to enable Espresso driver for your Android configuration.
32
- You could do it just by changing `automationName` in the `helpers` section of the config file:
33
- ```js
34
- {
35
- //...
36
- helpers: {
37
- Appium: {
38
- app: '/path/to/apk.apk',
39
- platform: 'Android',
40
- desiredCapabilities: {
41
- automationName: 'Espresso',
42
- platformVersion: '9',
43
- deviceName: 'Android Emulator'
44
- }
45
- }
46
- }
47
- //...
48
- }
49
- ```
50
- Then you could locate components using XPath expression:
51
- ```js
52
- I.tap({android: '//*[@view-tag="someButton"]', ios: '~someButton'})
53
- ```
54
- This way test would work for both platforms without any changes in code.
55
- To simplify things further you could write a helper function:
56
- ```js
57
- function tid(id) {
58
- return {
59
- android: `//*[@view-tag="${id}"]`,
60
- ios: '~' + id
61
- }
62
- }
63
- ```
64
- Now test will look more concise
65
- ```js
66
- I.tap(tid('someButton'));
67
- ```