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
package/docs/mobile.md DELETED
@@ -1,344 +0,0 @@
1
- ---
2
- permalink: /mobile
3
- title: Mobile Testing with Appium
4
- ---
5
-
6
- # Mobile Testing with Appium
7
-
8
- CodeceptJS allows to test mobile and hybrid apps in a similar manner web applications are tested.
9
- Such tests are executed using [Appium](https://appium.io) on emulated or physical devices. Also, Appium allows to test web application on mobile devices.
10
-
11
- What makes CodeceptJS better for mobile testing?
12
- Take a look. Here is the sample test for a native mobile application written in CodeceptJS:
13
-
14
- ```js
15
- I.seeAppIsInstalled("io.super.app");
16
- I.click('~startUserRegistrationCD');
17
- I.fillField('~email of the customer', 'Nothing special');
18
- I.see('davert@codecept.io', '~email of the customer');
19
- I.clearField('~email of the customer');
20
- I.dontSee('Nothing special', '~email of the customer');
21
- I.seeElement({
22
- android: 'android.widget.Button',
23
- ios: '//UIAApplication[1]/UIAWindow[1]/UIAButton[1]'
24
- });
25
- ```
26
-
27
- This test is easy to read and write. Also it will work both on iOS and Android devices.
28
- Doesn't it sound cool?
29
-
30
- ## Setting Up
31
-
32
- Ensure that you have [CodeceptJS installed](https://codecept.io/installation/).
33
- You will also need to install [Appium](https://appium.io/).
34
- We suggest to use [appium-doctor](https://www.npmjs.com/package/appium-doctor) to check if your system is ready for mobile testing.
35
-
36
- ```sh
37
- npm i -g appium-doctor
38
- ```
39
-
40
- If everything is OK, continue with installing Appium. If not, consider using cloud based alternatives like [SauceLabs](https://saucelabs.com) or [BrowserStack](https://browserstack.com). Cloud services provide hosted appium with real and emulated mobile devices.
41
-
42
- To install Appium use npm:
43
-
44
- ```sh
45
- npm i -g appium
46
- ```
47
-
48
- To use Appium 2.x:
49
- ```sh
50
- npm i -g appium@next
51
- ```
52
- Appium 2x (still beta) reenvisions Appium as a platform where “drivers” and “plugins” can be easily created and shared independently.
53
- Install an Appium driver and its dependencies
54
- To install the Appium driver and its dependencies, we'll be using the uiautomator2 (Android), XCUITest (iOS) drivers.
55
-
56
- ```
57
- appium driver install xcuitest
58
- appium driver install uiautomator2
59
- ```
60
- To make sure that all the drivers are installed successfully, run the following command:
61
-
62
- ```
63
- appium driver list
64
-
65
- tth~$appium driver list
66
- ✔ Listing available drivers
67
- - espresso@2.17.0 [installed (NPM)]
68
- - uiautomator2@2.12.6 [installed (NPM)]
69
- - xcuitest@4.19.1 [installed (NPM)]
70
- - mac2 [not installed]
71
- - safari [not installed]
72
- - gecko [not installed]
73
- - chromium [not installed]
74
- ```
75
-
76
- Then you need to prepare application for execution.
77
- It should be packed into apk (for Android) or .ipa (for iOS) or zip.
78
-
79
- Next, is to launch the emulator or connect a physical device.
80
- Once they are prepared, launch Appium:
81
-
82
- ```sh
83
- appium
84
- ```
85
-
86
- To use Appium 2.x:
87
- ```sh
88
- tth~$npx appium --base-path=/wd/hub
89
- [Appium] Welcome to Appium v2.0.0-beta.57 (REV 3e675c32ae71dc0b00749d5d29213e2ea5b53c5b)
90
- [Appium] Non-default server args:
91
- [Appium] {
92
- [Appium] basePath: '/wd/hub'
93
- [Appium] }
94
- [Appium] Attempting to load driver espresso...
95
- [debug] [Appium] Requiring driver at /Users/trung-thanh/Desktop/thanh-nguyen/task2/node_modules/appium-espresso-driver
96
- [Appium] Attempting to load driver uiautomator2...
97
- [debug] [Appium] Requiring driver at /Users/trung-thanh/Desktop/thanh-nguyen/task2/node_modules/appium-uiautomator2-driver
98
- [Appium] Appium REST http interface listener started on 0.0.0.0:4723
99
- [Appium] Available drivers:
100
- [Appium] - espresso@2.17.0 (automationName 'Espresso')
101
- [Appium] - uiautomator2@2.12.6 (automationName 'UiAutomator2')
102
- [Appium] No plugins have been installed. Use the "appium plugin" command to install the one(s) you want to use.
103
- ```
104
-
105
- To run mobile test you need either an device emulator (available with Android SDK or iOS), real device connected for mobile testing. Alternatively, you may execute Appium with device emulator inside Docker container.
106
-
107
- CodeceptJS should be installed with webdriverio support:
108
-
109
- ```bash
110
- npm install codeceptjs webdriverio@8.6.3 --save
111
- ```
112
-
113
- ## Configuring
114
-
115
- Initialize CodeceptJS with `init` command:
116
-
117
- ```sh
118
- npx codeceptjs init
119
- ```
120
-
121
- Select [Appium helper](https://codecept.io/helpers/Appium/) when asked.
122
-
123
- ```sh
124
- ? What helpers do you want to use?
125
- ◯ WebDriver
126
- ◯ Protractor
127
- ◯ Puppeteer
128
- ◯ Nightmare
129
- ❯◉ Appium
130
- ◯ REST
131
- ```
132
-
133
- You will also be asked for the platform and the application package.
134
-
135
- ```sh
136
- ? [Appium] Application package. Path to file or url
137
- ```
138
-
139
- Check the newly created `codecept.conf.js` configuration file.
140
- You may want to set some additional Appium settings via [desiredCapabilities](https://appium.io/docs/en/writing-running-appium/caps/)
141
-
142
- ```js
143
- helpers: {
144
- Appium: {
145
- app: "my_app.apk",
146
- platform: "Android",
147
- desiredCapabilities: {}
148
- }
149
- }
150
- ```
151
-
152
- Once you configured Appium, create the first test by running
153
-
154
- ```sh
155
- npx codeceptjs gt
156
- ```
157
-
158
- ## BrowserStack Configuration
159
-
160
- If you wish to use BrowserStack's [Automated Mobile App Testing](https://www.browserstack.com/app-automate) platform. Configure the Appium helper like this:
161
-
162
- ```js
163
- helpers: {
164
- Appium: {
165
- app: "bs://<hashed app-id>",
166
- host: "hub-cloud.browserstack.com",
167
- port: 4444,
168
- platform: "ios",
169
- user: "BROWSERSTACK_USER",
170
- key: "BROWSERSTACK_KEY",
171
- device: "iPhone 7"
172
- }
173
- }
174
- ```
175
- Here is the full list of [capabilities](https://www.browserstack.com/app-automate/capabilities).
176
-
177
- You need to upload your Android app (.apk) or iOS app (.ipa) to the BrowserStack servers using the REST API before running your tests. The App URL (`bs://hashed appid`) is returned in the response of this call.
178
-
179
- ```sh
180
- curl -u "USERNAME:ACCESS_KEY" \
181
- -X POST "https://api-cloud.browserstack.com/app-automate/upload" \
182
- -F "file=@/path/to/app/file/Application-debug.apk"
183
- ```
184
-
185
- ## Writing a Test
186
-
187
- A test is written in a scenario-driven manner, listing an actions taken by a user.
188
- This is the sample test for a native mobile application:
189
-
190
- ```js
191
- Scenario('test registration', ({ I }) => {
192
- I.click('~startUserRegistrationCD');
193
- I.fillField('~inputUsername', 'davert');
194
- I.fillField('~inputEmail', 'davert@codecept.io');
195
- I.fillField('~inputPassword', '123456');
196
- I.hideDeviceKeyboard();
197
- I.click('~input_preferredProgrammingLanguage');
198
- I.click('Javascript');
199
- I.checkOption('#io.demo.testapp:id/input_adds');
200
- I.click('Register User (verify)');
201
- I.swipeUp("#io.selendroid.testapp:id/LinearLayout1");
202
- I.see('Javascript'); // see on the screen
203
- I.see('davert', '~label_username_data'); // see in element
204
- });
205
- ```
206
-
207
- Mobile test is pretty similar to a web test. And it is much the same, if you test hybrid app with a web view context inside.
208
- However, mobile apps do not have URLs, Cookies, they have other features which may vary on a running platform.
209
-
210
- There are mobile-only methods like:
211
-
212
- * `swipeUp`, `swipeLeft`, ...
213
- * `hideDeviceKeyboard`,
214
- * `seeAppIsInstalled`, `installApp`, `removeApp`, `seeAppIsNotInstalled` - Android only
215
-
216
- and [others](https://codecept.io/helpers/Appium/).
217
-
218
- ## Locating Elements
219
-
220
- To start writing a test it is important to understand how to locate elements for native mobile applications.
221
- In both Android and iPhone elements are defined in XML format and can be searched by XPath locators.
222
-
223
- ```js
224
- I.seeElement('//android.widget.ScrollView/android.widget.LinearLayout')'
225
- ```
226
-
227
- > Despite showing XPath in this guide we **do not recommend using XPath for testing iOS native apps. XPath runs very slow on iOS. Consider using ID or Accessibility ID locators instead.
228
-
229
- CSS locators are not supported in native mobile apps, you need to switch to web context to use them.
230
-
231
- Elements can also be located by their accessability id, available both at Android and iOS.
232
- Accessibility id is recommended to use for locating element, as it rarely changed.
233
-
234
- * iOS uses [UIAccessibilityIdentification](https://developer.apple.com/documentation/uikit/uiaccessibilityidentification)
235
- * Android `accessibility id` matches the content-description
236
- * Web view uses `[aria-label]` attribute as accessibility id
237
- * For [React Native for Android see our special guide](mobile-react-native-locators.md).
238
-
239
- > If you test React Native application, consider using [Detox helper](/detox) for faster tests.
240
-
241
- Add `~` prefix to search for element by its accessibility id:
242
-
243
- ```js
244
- I.seeElement('~startUserRegistrationButton');
245
- ```
246
-
247
- Elements can also have ids, which can be located with `#` prefix.
248
- On Android it it is important to keep full package name in id locator:
249
-
250
- ```js
251
- I.seeElement('#io.selendroid.testapp:id/inputUsername');
252
- ```
253
-
254
- Buttons can be matched by their visible text:
255
-
256
- ```js
257
- I.tap('Click me!');
258
- I.click('Click me!');
259
- ```
260
-
261
- Native iOS/Android locators can be used with `android=` and `ios=` prefixes. [Learn more](https://webdriver.io/guide/usage/selectors.html#Mobile-Selectors).
262
-
263
- But how to get all those locators? We recommend to use [Appium Inspector](https://github.com/appium/appium-desktop).
264
-
265
- For Android you can use **UI Automator Viewer** bundled with Android SDK:
266
-
267
- ![](https://user-images.githubusercontent.com/220264/27566310-1f631604-5aed-11e7-8b92-1ffe9e9f14f9.png)
268
-
269
- ## Hybrid Apps and Contexts
270
-
271
- Mobile applications may have different contexts. For instance, there can be native view and web view with a browser instance in it.
272
-
273
- To execute commands in context of a webview use `within('webview')` function:
274
-
275
- ```js
276
- I.click('~startWebView');
277
- within('webview', () => {
278
- I.see('Preferred car');
279
- I.click('Send me your name!');
280
- });
281
- ```
282
-
283
- It will locate first available webview, switch to it, and switch back to native application after.
284
- Inside WebView all browser features are enabled: CSS locators, JavaScript, etc.
285
-
286
- To set a specific context use `{ web: 'webview.context' }` instead:
287
-
288
- ```js
289
- within({webview: 'MyWEBVIEW_com.my.app'}, () => );
290
- ```
291
-
292
- Alternatively use `switchToWeb` or `switchToNative` methods to switch between contexts.
293
-
294
- ```js
295
- I.click('~startWebView');
296
- I.switchToWeb();
297
- I.see('Preferred car');
298
- I.click('Send me your name!');
299
- I.switchToNative();
300
- ```
301
-
302
- To get a list of all contexts use `grabAllContexts` method:
303
-
304
- ```js
305
- let contexts = await I.grabAllContexts();
306
- ```
307
-
308
- ## Cross-Platform Testing
309
-
310
- It is often happen that mobile applications behave similarly on different platforms. Can we build one test for them? Yes!
311
- CodeceptJS provides a way to specify different locators for Android and iOS platforms:
312
-
313
- ```js
314
- I.click({android: '//android.widget.Button', ios: '//UIAApplication[1]/UIAWindow[1]/UIAButton[1]'});
315
- ```
316
-
317
- In case some code should be executed on one platform and ignored on others use `runOnAndroid` and `runOnIOS` methods:
318
-
319
- ```js
320
- I.runOnAndroid(() => {
321
- I.click('Hello Android');
322
- });
323
- I.runOnIOS(() => {
324
- I.click('Hello iOS');
325
- });
326
- ```
327
-
328
- The same code can be shared for web applications as well. To execute some code in web browser only, use `I.runInWeb`:
329
-
330
- ```js
331
- I.runInWeb(() => {
332
- I.amOnPage('/login'); // not available for mobile
333
- I.fillField('name', 'jon');
334
- I.fillField('password', '123456');
335
- I.click('Login');
336
- I.waitForElement('#success'); // no available for mobile
337
- });
338
- ```
339
-
340
- Just as you can specify android, and ios-specific locators, you can do so for web:
341
-
342
- ```js
343
- I.click({web: '#login', ios: '//UIAApplication[1]/UIAWindow[1]/UIAButton[1]'});
344
- ```
package/docs/nightmare.md DELETED
@@ -1,223 +0,0 @@
1
- ---
2
- permalink: /nightmare
3
- title: Testing with Nightmare
4
- ---
5
-
6
- # Testing with Nightmare
7
-
8
- Selenium WebDriver is considered to be standard for end to end testing of web applications.
9
- Despite its popularity it have its drawbacks, it requires a real browser and Selenium server to control it.
10
- This hardens setting it up testing environment for CI server and slows down test execution.
11
-
12
- Is there a sane alternative to Selenium?
13
-
14
- Yes, how about [NightmareJS](https://www.nightmarejs.org)?
15
-
16
- It is modern Electron based testing framework which allows to execute tests in headless mode as well as in window mode for debug purposes.
17
- This makes Nightmare very useful, much more handy than PhantomJS. Nightmare is in active development and has nice API for writing acceptance tests.
18
- Unfortunately, as all other JavaScript testing frameworks it has its own very custom API.
19
- What if you choose it for a project and suddenly you realize that you need something more powerful, like Selenium?
20
- Yes, that might be a problem if you are not using CodeceptJS.
21
- The one idea behind CodeceptJS is to unify different testing backends under one API, so you could easily write tests the same way no matter what engines you use: webdriverio, Protractor, or Nightmare.
22
-
23
- Compare a test written using Nightmare API:
24
-
25
- ```js
26
- nightmare
27
- .goto('http://yahoo.com')
28
- .type('form[action*="/search"] [name=p]', 'github nightmare')
29
- .click('form[action*="/search"] [type=submit]')
30
- .wait('#main')
31
- .evaluate(function () {
32
- return document.querySelector('#main .searchCenterMiddle li a').href
33
- })
34
- ```
35
-
36
- with a similar CodeceptJS test:
37
-
38
- ```js
39
- I.amOnPage('http://yahoo.com');
40
- I.fillField('p', 'github nightmare');
41
- I.click('Search Web');
42
- I.waitForElement('#main');
43
- I.seeElement('#main .searchCenterMiddle li a');
44
- I.seeElement("//a[contains(@href,'github.com/segmentio/nightmare')]");
45
- I.see('segmentio/nightmare','#main li a');
46
- ```
47
-
48
- NightmareJS support only CSS locators for web elements, while CodeceptJS improves it to use XPath as well.
49
- This is how form can be located by labels, and buttons by text in examples above. It is done by injecting
50
- client-side scrips (for element location) to every loaded page. Also all events like click, doubleClick, keyPress are **simulated** by JavaScript,
51
- this makes testing less relevant, as they are not native to operating systems.
52
-
53
- ## How Fast Is Nightmare JS?
54
-
55
- Let's execute the test above within WebDriver using headless Firefox + Selenium Server packed in Docker container.
56
-
57
- ```sh
58
- docker run -d -p 4444:4444 selenium/standalone-firefox:2.53.0
59
- codeceptjs run yahoo_test.js --steps
60
- ```
61
-
62
- This provides use with output:
63
-
64
- ```sh
65
- Yahoo basic test
66
- > WebDriver._before
67
- • I am on page "http://yahoo.com"
68
- • I fill field "p", "github nightmare"
69
- • I click "Search Web"
70
- • I wait for element "#main", 2
71
- • I see element "#main .searchCenterMiddle li a"
72
- • I see "segmentio/nightmare", "li a"
73
- ✓ OK in 17591ms
74
- ```
75
-
76
- When we switch helper to Nightmare:
77
-
78
- ```sh
79
- Yahoo basic test
80
- > Nightmare._before
81
- • I am on page "http://yahoo.com"
82
- • I fill field "p", "github nightmare"
83
- • I click "Search Web"
84
- • I wait for element "#main", 2
85
- • I see element "#main .searchCenterMiddle li a"
86
- • I see "segmentio/nightmare", "li a"
87
- ✓ OK in 5490ms
88
- ```
89
-
90
- As you see the Nightmare test was almost **3 times faster** than Selenium test.
91
- Sure, this can't be taken as a valuable benchmark but more like a proof of concept.
92
-
93
- ## Setup
94
-
95
- To start you need CodeceptJS with nightmare package installed.
96
-
97
- ```bash
98
- npm install -g nightmare
99
- ```
100
-
101
- And a basic project initialized
102
-
103
- ```sh
104
- codeceptjs init
105
- ```
106
-
107
- You will be asked for a Helper to use, you should select Nightmare and provide url of a website you are testing.
108
- Setup process is explained on [QuickStart page](https://codecept.io/quickstart/).
109
-
110
- (If you already have CodeceptJS project, just install nightmare globally or locally and enable it in config)
111
-
112
- ## Configuring Nightmare
113
-
114
- Enable `Nightmare` helper in `codecept.json` config:
115
-
116
- ```js
117
- { // ..
118
- "helpers": {
119
- "Nightmare": {
120
- "url": "http://localhost",
121
- "show": false,
122
- "restart": false
123
- }
124
- }
125
- // ..
126
- }
127
- ```
128
-
129
- Turn on the `show` option if you want to follow test progress in a window. This is very useful for debugging.
130
- All other options can be taken from [NightmareJS API](https://github.com/segmentio/nightmare#api).
131
-
132
- Turn off the `restart` option if you want to run your suite in a single browser instance.
133
-
134
- Option `waitForAction` defines how long to wait after a click, doubleClick or pressKey action is performed.
135
- Test execution may happen much faster than the response is rendered, so make sure you set a proper delay value.
136
- By default CodeceptJS waits for 500ms.
137
-
138
- ## Opening a Web Page
139
-
140
- Nightmare provides you with more control to browser engine than Selenium does.
141
- This allows you to use headers in your tests. For instance, CodeceptJS provides `haveHeader` method
142
- to set default headers for all your HTTP requests:
143
-
144
- ```js
145
- I.haveHeader('x-tested-with', 'codeceptjs');
146
- ```
147
-
148
- When opening a web page you can set headers as well. `amOnPage` methods can take headers as second parameter:
149
-
150
- ```js
151
- // use basic http auth
152
- I.amOnPage('/admin', { 'Authorization': 'Basic '+token });
153
- ```
154
-
155
- As a small bonus: all `console.log` calls on a page will be also shown in `--debug` mode.
156
-
157
- ## Manipulating Web Page
158
-
159
- Nightmare helper is supposed to work in the same manner as WebDriver or Protractor.
160
- This means that all CodeceptJS actions like `click`, `fillField`, `selectOption` and others are supposed to work in the very same manner.
161
- They are expressive and flexible to accept CSS, XPath, names, values, or strict locators. Follow the helper reference for detailed description.
162
-
163
- Assertions start with `see` prefix. You can check text on a page, elements on page and others.
164
-
165
- ## Extending Nightmare Helper
166
-
167
- CodeceptJS allows you to define and connect own helpers. If some functionality of
168
- Nightmare helper is missing you can easily create `ExtendedNightmare` helper by running:
169
-
170
- ```sh
171
- codeceptjs gh
172
- ```
173
-
174
- Learn more about [Helpers](https://codecept.io/helpers/).
175
-
176
- Nightmare instance can be accessed by custom helper:
177
-
178
- ```js
179
- // returns current nightmare instance
180
- this.helpers['Nightmare'].browser;
181
- ```
182
-
183
- This way you can call [native Nightmare commands](https://github.com/segmentio/nightmare#interact-with-the-page).
184
-
185
- It is important to understand that Nightmare executes JavaScript on client and on server side.
186
- If you need to find an element you should search for it using client side script, but if you want
187
- to do an assertion you should return a data to server side.
188
-
189
- Nightmare provides `evaluate` method to execute client-side JavaScript. CodeceptJS registers `codeceptjs`
190
- object globally on client side with `findElement` and `findElements` methods in it. They return IDs of matched elements
191
- so you can access them in next calls to `evaluate`:
192
-
193
- ```js
194
- // inside a custom helper class
195
- async seeAttributeContains(locator, attribute, expectedValue) {
196
- // let's use chai assertion library
197
- const assert = require('chai').assert;
198
- // get nightmare instance
199
- const browser = this.helpers['Nightmare'].browser;
200
- // find an element by CSS or XPath:
201
- const els = await this.helpers['Nightmare']._locate(locator);
202
- // we received an array with IDs of matched elements
203
- // now let's execute client-side script to get attribute for the first element
204
- const attributeValue = await browser.evaluate(function(el, attribute) {
205
- // this is executed inside a web page!
206
- return codeceptjs.fetchElement(el).getAttribute(attribute);
207
- }, els[0], attribute); // function + its params
208
-
209
- // get attribute value and back to server side
210
- // execute an assertion
211
- assert.include(attributeValue, expectedValue);
212
- }
213
- ```
214
-
215
- It can be used in tests like:
216
-
217
- ```js
218
- I.seeAttributeContains('#main img', 'src', '/cat.jpg');
219
- ```
220
-
221
- This sample assertion used `_locate` helper method which searched for elements
222
- by CSS/XPath or a strict locator. Then `browser.evaluate` method was called to
223
- use locate found elements on a page and return attribute from the first of them.