codeceptjs 3.4.1 → 3.5.1-2.beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -30
- package/bin/codecept.js +1 -1
- package/lib/actor.js +6 -3
- package/lib/ai.js +180 -0
- package/lib/cli.js +13 -3
- package/lib/codecept.js +8 -0
- package/lib/colorUtils.js +10 -0
- package/lib/command/definitions.js +2 -7
- package/lib/command/dryRun.js +11 -2
- package/lib/command/generate.js +46 -3
- package/lib/command/info.js +24 -0
- package/lib/command/init.js +64 -6
- package/lib/command/interactive.js +15 -1
- package/lib/command/run-multiple/collection.js +17 -5
- package/lib/command/run-multiple.js +4 -2
- package/lib/command/run-workers.js +68 -5
- package/lib/command/run.js +7 -0
- package/lib/command/workers/runTests.js +39 -0
- package/lib/container.js +13 -3
- package/lib/data/context.js +14 -6
- package/lib/event.js +4 -0
- package/lib/helper/ApiDataFactory.js +2 -1
- package/lib/helper/Appium.js +116 -29
- package/lib/helper/Expect.js +422 -0
- package/lib/helper/FileSystem.js +1 -1
- package/lib/helper/GraphQL.js +25 -0
- package/lib/helper/JSONResponse.js +4 -4
- package/lib/helper/Nightmare.js +10 -5
- package/lib/helper/OpenAI.js +126 -0
- package/lib/helper/Playwright.js +1298 -229
- package/lib/helper/Protractor.js +12 -7
- package/lib/helper/Puppeteer.js +204 -64
- package/lib/helper/REST.js +15 -5
- package/lib/helper/TestCafe.js +45 -10
- package/lib/helper/WebDriver.js +252 -83
- package/lib/helper/errors/ElementNotFound.js +2 -1
- package/lib/helper/extras/PlaywrightReactVueLocator.js +38 -0
- package/lib/helper/scripts/blurElement.js +17 -0
- package/lib/helper/scripts/focusElement.js +17 -0
- package/lib/helper/scripts/highlightElement.js +20 -0
- package/lib/html.js +258 -0
- package/lib/interfaces/bdd.js +1 -1
- package/lib/interfaces/gherkin.js +37 -3
- package/lib/interfaces/scenarioConfig.js +1 -0
- package/lib/listener/retry.js +2 -1
- package/lib/locator.js +17 -4
- package/lib/mochaFactory.js +2 -1
- package/lib/output.js +1 -1
- package/lib/pause.js +78 -19
- package/lib/plugin/autoLogin.js +45 -10
- package/lib/plugin/debugErrors.js +67 -0
- package/lib/plugin/fakerTransform.js +4 -6
- package/lib/plugin/heal.js +209 -0
- package/lib/plugin/retryFailedStep.js +10 -1
- package/lib/plugin/retryTo.js +2 -4
- package/lib/plugin/screenshotOnFail.js +11 -2
- package/lib/plugin/selenoid.js +6 -1
- package/lib/plugin/standardActingHelpers.js +0 -2
- package/lib/plugin/stepByStepReport.js +2 -2
- package/lib/plugin/tryTo.js +5 -7
- package/lib/plugin/wdio.js +0 -1
- package/lib/recorder.js +22 -11
- package/lib/secret.js +5 -4
- package/lib/session.js +1 -1
- package/lib/step.js +36 -12
- package/lib/ui.js +5 -3
- package/lib/utils.js +22 -1
- package/lib/workers.js +83 -10
- package/package.json +117 -95
- package/translations/de-DE.js +5 -0
- package/translations/fr-FR.js +14 -1
- package/translations/it-IT.js +1 -0
- package/translations/ja-JP.js +14 -9
- package/translations/pl-PL.js +5 -0
- package/translations/pt-BR.js +1 -0
- package/translations/ru-RU.js +1 -0
- package/translations/zh-CN.js +5 -0
- package/translations/zh-TW.js +5 -0
- package/typings/index.d.ts +51 -15
- package/typings/promiseBasedTypes.d.ts +864 -802
- package/typings/types.d.ts +1339 -744
- package/CHANGELOG.md +0 -2427
- package/docs/advanced.md +0 -351
- package/docs/api.md +0 -323
- package/docs/basics.md +0 -980
- package/docs/bdd.md +0 -535
- package/docs/best.md +0 -237
- package/docs/books.md +0 -37
- package/docs/bootstrap.md +0 -135
- package/docs/build/ApiDataFactory.js +0 -409
- package/docs/build/Appium.js +0 -1938
- package/docs/build/FileSystem.js +0 -228
- package/docs/build/GraphQL.js +0 -204
- package/docs/build/GraphQLDataFactory.js +0 -309
- package/docs/build/JSONResponse.js +0 -338
- package/docs/build/Mochawesome.js +0 -71
- package/docs/build/Nightmare.js +0 -2145
- package/docs/build/Playwright.js +0 -3986
- package/docs/build/Polly.js +0 -42
- package/docs/build/Protractor.js +0 -2699
- package/docs/build/Puppeteer.js +0 -3710
- package/docs/build/REST.js +0 -334
- package/docs/build/SeleniumWebdriver.js +0 -76
- package/docs/build/TestCafe.js +0 -2057
- package/docs/build/WebDriver.js +0 -4017
- package/docs/changelog.md +0 -2436
- package/docs/commands.md +0 -254
- package/docs/community-helpers.md +0 -58
- package/docs/configuration.md +0 -157
- package/docs/continuous-integration.md +0 -22
- package/docs/custom-helpers.md +0 -306
- package/docs/data.md +0 -375
- package/docs/detox.md +0 -235
- package/docs/docker.md +0 -137
- package/docs/email.md +0 -183
- package/docs/examples.md +0 -149
- package/docs/helpers/ApiDataFactory.md +0 -266
- package/docs/helpers/Appium.md +0 -1312
- package/docs/helpers/Detox.md +0 -586
- package/docs/helpers/FileSystem.md +0 -152
- package/docs/helpers/GraphQL.md +0 -130
- package/docs/helpers/GraphQLDataFactory.md +0 -226
- package/docs/helpers/JSONResponse.md +0 -254
- package/docs/helpers/Mochawesome.md +0 -8
- package/docs/helpers/MockRequest.md +0 -377
- package/docs/helpers/Nightmare.md +0 -1256
- package/docs/helpers/Playwright.md +0 -2208
- package/docs/helpers/Polly.md +0 -44
- package/docs/helpers/Puppeteer-firefox.md +0 -86
- package/docs/helpers/Puppeteer.md +0 -2141
- package/docs/helpers/REST.md +0 -217
- package/docs/helpers/TestCafe.md +0 -1222
- package/docs/helpers/WebDriver.md +0 -2319
- package/docs/hooks.md +0 -340
- package/docs/index.md +0 -111
- package/docs/installation.md +0 -75
- package/docs/internal-api.md +0 -265
- package/docs/locators.md +0 -331
- package/docs/mobile-react-native-locators.md +0 -67
- package/docs/mobile.md +0 -297
- package/docs/nightmare.md +0 -223
- package/docs/pageobjects.md +0 -291
- package/docs/parallel.md +0 -232
- package/docs/playwright.md +0 -609
- package/docs/plugins.md +0 -1171
- package/docs/puppeteer.md +0 -316
- package/docs/quickstart.md +0 -163
- package/docs/react.md +0 -69
- package/docs/reports.md +0 -392
- package/docs/secrets.md +0 -30
- package/docs/shadow.md +0 -68
- package/docs/shared/keys.mustache +0 -31
- package/docs/shared/react.mustache +0 -1
- package/docs/testcafe.md +0 -174
- package/docs/translation.md +0 -247
- package/docs/tutorial.md +0 -271
- package/docs/typescript.md +0 -180
- package/docs/ui.md +0 -59
- package/docs/videos.md +0 -28
- package/docs/visual.md +0 -202
- package/docs/vue.md +0 -121
- package/docs/webapi/amOnPage.mustache +0 -11
- package/docs/webapi/appendField.mustache +0 -9
- package/docs/webapi/attachFile.mustache +0 -12
- package/docs/webapi/checkOption.mustache +0 -13
- package/docs/webapi/clearCookie.mustache +0 -10
- package/docs/webapi/clearField.mustache +0 -9
- package/docs/webapi/click.mustache +0 -25
- package/docs/webapi/clickLink.mustache +0 -8
- package/docs/webapi/closeCurrentTab.mustache +0 -7
- package/docs/webapi/closeOtherTabs.mustache +0 -8
- package/docs/webapi/dontSee.mustache +0 -11
- package/docs/webapi/dontSeeCheckboxIsChecked.mustache +0 -10
- package/docs/webapi/dontSeeCookie.mustache +0 -8
- package/docs/webapi/dontSeeCurrentUrlEquals.mustache +0 -10
- package/docs/webapi/dontSeeElement.mustache +0 -8
- package/docs/webapi/dontSeeElementInDOM.mustache +0 -8
- package/docs/webapi/dontSeeInCurrentUrl.mustache +0 -4
- package/docs/webapi/dontSeeInField.mustache +0 -11
- package/docs/webapi/dontSeeInSource.mustache +0 -8
- package/docs/webapi/dontSeeInTitle.mustache +0 -8
- package/docs/webapi/doubleClick.mustache +0 -13
- package/docs/webapi/downloadFile.mustache +0 -12
- package/docs/webapi/dragAndDrop.mustache +0 -9
- package/docs/webapi/dragSlider.mustache +0 -11
- package/docs/webapi/executeAsyncScript.mustache +0 -24
- package/docs/webapi/executeScript.mustache +0 -26
- package/docs/webapi/fillField.mustache +0 -16
- package/docs/webapi/forceClick.mustache +0 -28
- package/docs/webapi/forceRightClick.mustache +0 -18
- package/docs/webapi/grabAllWindowHandles.mustache +0 -7
- package/docs/webapi/grabAttributeFrom.mustache +0 -10
- package/docs/webapi/grabAttributeFromAll.mustache +0 -9
- package/docs/webapi/grabBrowserLogs.mustache +0 -9
- package/docs/webapi/grabCookie.mustache +0 -11
- package/docs/webapi/grabCssPropertyFrom.mustache +0 -11
- package/docs/webapi/grabCssPropertyFromAll.mustache +0 -10
- package/docs/webapi/grabCurrentUrl.mustache +0 -9
- package/docs/webapi/grabCurrentWindowHandle.mustache +0 -6
- package/docs/webapi/grabDataFromPerformanceTiming.mustache +0 -20
- package/docs/webapi/grabElementBoundingRect.mustache +0 -20
- package/docs/webapi/grabGeoLocation.mustache +0 -8
- package/docs/webapi/grabHTMLFrom.mustache +0 -10
- package/docs/webapi/grabHTMLFromAll.mustache +0 -9
- package/docs/webapi/grabNumberOfOpenTabs.mustache +0 -8
- package/docs/webapi/grabNumberOfVisibleElements.mustache +0 -9
- package/docs/webapi/grabPageScrollPosition.mustache +0 -8
- package/docs/webapi/grabPopupText.mustache +0 -5
- package/docs/webapi/grabSource.mustache +0 -8
- package/docs/webapi/grabTextFrom.mustache +0 -10
- package/docs/webapi/grabTextFromAll.mustache +0 -9
- package/docs/webapi/grabTitle.mustache +0 -8
- package/docs/webapi/grabValueFrom.mustache +0 -9
- package/docs/webapi/grabValueFromAll.mustache +0 -8
- package/docs/webapi/moveCursorTo.mustache +0 -12
- package/docs/webapi/openNewTab.mustache +0 -7
- package/docs/webapi/pressKey.mustache +0 -12
- package/docs/webapi/pressKeyDown.mustache +0 -12
- package/docs/webapi/pressKeyUp.mustache +0 -12
- package/docs/webapi/pressKeyWithKeyNormalization.mustache +0 -60
- package/docs/webapi/refreshPage.mustache +0 -6
- package/docs/webapi/resizeWindow.mustache +0 -6
- package/docs/webapi/rightClick.mustache +0 -14
- package/docs/webapi/saveElementScreenshot.mustache +0 -10
- package/docs/webapi/saveScreenshot.mustache +0 -12
- package/docs/webapi/say.mustache +0 -10
- package/docs/webapi/scrollIntoView.mustache +0 -11
- package/docs/webapi/scrollPageToBottom.mustache +0 -6
- package/docs/webapi/scrollPageToTop.mustache +0 -6
- package/docs/webapi/scrollTo.mustache +0 -12
- package/docs/webapi/see.mustache +0 -11
- package/docs/webapi/seeAttributesOnElements.mustache +0 -9
- package/docs/webapi/seeCheckboxIsChecked.mustache +0 -10
- package/docs/webapi/seeCookie.mustache +0 -8
- package/docs/webapi/seeCssPropertiesOnElements.mustache +0 -9
- package/docs/webapi/seeCurrentUrlEquals.mustache +0 -11
- package/docs/webapi/seeElement.mustache +0 -8
- package/docs/webapi/seeElementInDOM.mustache +0 -8
- package/docs/webapi/seeInCurrentUrl.mustache +0 -8
- package/docs/webapi/seeInField.mustache +0 -12
- package/docs/webapi/seeInPopup.mustache +0 -8
- package/docs/webapi/seeInSource.mustache +0 -7
- package/docs/webapi/seeInTitle.mustache +0 -8
- package/docs/webapi/seeNumberOfElements.mustache +0 -11
- package/docs/webapi/seeNumberOfVisibleElements.mustache +0 -10
- package/docs/webapi/seeTextEquals.mustache +0 -9
- package/docs/webapi/seeTitleEquals.mustache +0 -8
- package/docs/webapi/selectOption.mustache +0 -21
- package/docs/webapi/setCookie.mustache +0 -16
- package/docs/webapi/setGeoLocation.mustache +0 -12
- package/docs/webapi/switchTo.mustache +0 -9
- package/docs/webapi/switchToNextTab.mustache +0 -10
- package/docs/webapi/switchToPreviousTab.mustache +0 -10
- package/docs/webapi/type.mustache +0 -18
- package/docs/webapi/uncheckOption.mustache +0 -13
- package/docs/webapi/wait.mustache +0 -8
- package/docs/webapi/waitForClickable.mustache +0 -11
- package/docs/webapi/waitForDetached.mustache +0 -10
- package/docs/webapi/waitForElement.mustache +0 -11
- package/docs/webapi/waitForEnabled.mustache +0 -6
- package/docs/webapi/waitForFunction.mustache +0 -17
- package/docs/webapi/waitForInvisible.mustache +0 -10
- package/docs/webapi/waitForText.mustache +0 -13
- package/docs/webapi/waitForValue.mustache +0 -10
- package/docs/webapi/waitForVisible.mustache +0 -10
- package/docs/webapi/waitInUrl.mustache +0 -9
- package/docs/webapi/waitNumberOfVisibleElements.mustache +0 -10
- package/docs/webapi/waitToHide.mustache +0 -10
- package/docs/webapi/waitUrlEquals.mustache +0 -10
- package/docs/webdriver.md +0 -657
- package/docs/wiki/Books-&-Posts.md +0 -27
- package/docs/wiki/Community-Helpers-&-Plugins.md +0 -49
- package/docs/wiki/Converting-Playwright-to-Istanbul-Coverage.md +0 -29
- package/docs/wiki/Examples.md +0 -139
- package/docs/wiki/Google-Summer-of-Code-(GSoC)-2020.md +0 -68
- package/docs/wiki/Home.md +0 -16
- package/docs/wiki/Release-Process.md +0 -24
- package/docs/wiki/Roadmap.md +0 -23
- package/docs/wiki/Tests.md +0 -1393
- package/docs/wiki/Upgrading-to-CodeceptJS-3.md +0 -153
- package/docs/wiki/Videos.md +0 -19
package/docs/mobile.md
DELETED
|
@@ -1,297 +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
|
-
Then you need to prepare application for execution.
|
|
49
|
-
It should be packed into apk (for Android) or .ipa (for iOS) or zip.
|
|
50
|
-
|
|
51
|
-
Next, is to launch the emulator or connect physical device.
|
|
52
|
-
Once they are prepared, launch Appium:
|
|
53
|
-
|
|
54
|
-
```sh
|
|
55
|
-
appium
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
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.
|
|
59
|
-
|
|
60
|
-
CodeceptJS should be installed with webdriverio support:
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
npm install codeceptjs webdriverio --save
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Configuring
|
|
67
|
-
|
|
68
|
-
Initialize CodeceptJS with `init` command:
|
|
69
|
-
|
|
70
|
-
```sh
|
|
71
|
-
npx codeceptjs init
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
Select [Appium helper](https://codecept.io/helpers/Appium/) when asked.
|
|
75
|
-
|
|
76
|
-
```sh
|
|
77
|
-
? What helpers do you want to use?
|
|
78
|
-
◯ WebDriver
|
|
79
|
-
◯ Protractor
|
|
80
|
-
◯ Puppeteer
|
|
81
|
-
◯ Nightmare
|
|
82
|
-
❯◉ Appium
|
|
83
|
-
◯ REST
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
You will also be asked for the platform and the application package.
|
|
87
|
-
|
|
88
|
-
```sh
|
|
89
|
-
? [Appium] Application package. Path to file or url
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
Check the newly created `codecept.conf.js` configuration file.
|
|
93
|
-
You may want to set some additional Appium settings via [desiredCapabilities](https://appium.io/docs/en/writing-running-appium/caps/)
|
|
94
|
-
|
|
95
|
-
```js
|
|
96
|
-
helpers: {
|
|
97
|
-
Appium: {
|
|
98
|
-
app: "my_app.apk",
|
|
99
|
-
platform: "Android",
|
|
100
|
-
desiredCapabilities: {}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
Once you configured Appium, create the first test by running
|
|
106
|
-
|
|
107
|
-
```sh
|
|
108
|
-
npx codeceptjs gt
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
## BrowserStack Configuration
|
|
112
|
-
|
|
113
|
-
If you wish to use BrowserStack's [Automated Mobile App Testing](https://www.browserstack.com/app-automate) platform. Configure the Appium helper like this:
|
|
114
|
-
|
|
115
|
-
```js
|
|
116
|
-
helpers: {
|
|
117
|
-
Appium: {
|
|
118
|
-
app: "bs://<hashed app-id>",
|
|
119
|
-
host: "hub-cloud.browserstack.com",
|
|
120
|
-
port: 4444,
|
|
121
|
-
platform: "ios",
|
|
122
|
-
user: "BROWSERSTACK_USER",
|
|
123
|
-
key: "BROWSERSTACK_KEY",
|
|
124
|
-
device: "iPhone 7"
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
```
|
|
128
|
-
Here is the full list of [capabilities](https://www.browserstack.com/app-automate/capabilities).
|
|
129
|
-
|
|
130
|
-
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.
|
|
131
|
-
|
|
132
|
-
```sh
|
|
133
|
-
curl -u "USERNAME:ACCESS_KEY" \
|
|
134
|
-
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
|
|
135
|
-
-F "file=@/path/to/app/file/Application-debug.apk"
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
## Writing a Test
|
|
139
|
-
|
|
140
|
-
A test is written in a scenario-driven manner, listing an actions taken by a user.
|
|
141
|
-
This is the sample test for a native mobile application:
|
|
142
|
-
|
|
143
|
-
```js
|
|
144
|
-
Scenario('test registration', ({ I }) => {
|
|
145
|
-
I.click('~startUserRegistrationCD');
|
|
146
|
-
I.fillField('~inputUsername', 'davert');
|
|
147
|
-
I.fillField('~inputEmail', 'davert@codecept.io');
|
|
148
|
-
I.fillField('~inputPassword', '123456');
|
|
149
|
-
I.hideDeviceKeyboard();
|
|
150
|
-
I.click('~input_preferredProgrammingLanguage');
|
|
151
|
-
I.click('Javascript');
|
|
152
|
-
I.checkOption('#io.demo.testapp:id/input_adds');
|
|
153
|
-
I.click('Register User (verify)');
|
|
154
|
-
I.swipeUp("#io.selendroid.testapp:id/LinearLayout1");
|
|
155
|
-
I.see('Javascript'); // see on the screen
|
|
156
|
-
I.see('davert', '~label_username_data'); // see in element
|
|
157
|
-
});
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
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.
|
|
161
|
-
However, mobile apps do not have URLs, Cookies, they have other features which may vary on a running platform.
|
|
162
|
-
|
|
163
|
-
There are mobile-only methods like:
|
|
164
|
-
|
|
165
|
-
* `swipeUp`, `swipeLeft`, ...
|
|
166
|
-
* `hideDeviceKeyboard`,
|
|
167
|
-
* `seeAppIsInstalled`, `installApp`, `removeApp`, `seeAppIsNotInstalled` - Android only
|
|
168
|
-
|
|
169
|
-
and [others](https://codecept.io/helpers/Appium/).
|
|
170
|
-
|
|
171
|
-
## Locating Elements
|
|
172
|
-
|
|
173
|
-
To start writing a test it is important to understand how to locate elements for native mobile applications.
|
|
174
|
-
In both Android and iPhone elements are defined in XML format and can be searched by XPath locators.
|
|
175
|
-
|
|
176
|
-
```js
|
|
177
|
-
I.seeElement('//android.widget.ScrollView/android.widget.LinearLayout')'
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
> 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.
|
|
181
|
-
|
|
182
|
-
CSS locators are not supported in native mobile apps, you need to switch to web context to use them.
|
|
183
|
-
|
|
184
|
-
Elements can also be located by their accessability id, available both at Android and iOS.
|
|
185
|
-
Accessibility id is recommended to use for locating element, as it rarely changed.
|
|
186
|
-
|
|
187
|
-
* iOS uses [UIAccessibilityIdentification](https://developer.apple.com/documentation/uikit/uiaccessibilityidentification)
|
|
188
|
-
* Android `accessibility id` matches the content-description
|
|
189
|
-
* Web view uses `[aria-label]` attribute as accessibility id
|
|
190
|
-
* For [React Native for Android see our special guide](mobile-react-native-locators.md).
|
|
191
|
-
|
|
192
|
-
> If you test React Native application, consider using [Detox helper](/detox) for faster tests.
|
|
193
|
-
|
|
194
|
-
Add `~` prefix to search for element by its accessibility id:
|
|
195
|
-
|
|
196
|
-
```js
|
|
197
|
-
I.seeElement('~startUserRegistrationButton');
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
Elements can also have ids, which can be located with `#` prefix.
|
|
201
|
-
On Android it it is important to keep full package name in id locator:
|
|
202
|
-
|
|
203
|
-
```js
|
|
204
|
-
I.seeElement('#io.selendroid.testapp:id/inputUsername');
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
Buttons can be matched by their visible text:
|
|
208
|
-
|
|
209
|
-
```js
|
|
210
|
-
I.tap('Click me!');
|
|
211
|
-
I.click('Click me!');
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
Native iOS/Android locators can be used with `android=` and `ios=` prefixes. [Learn more](https://webdriver.io/guide/usage/selectors.html#Mobile-Selectors).
|
|
215
|
-
|
|
216
|
-
But how to get all those locators? We recommend to use [Appium Inspector](https://github.com/appium/appium-desktop).
|
|
217
|
-
|
|
218
|
-
For Android you can use **UI Automator Viewer** bundled with Android SDK:
|
|
219
|
-
|
|
220
|
-

|
|
221
|
-
|
|
222
|
-
## Hybrid Apps and Contexts
|
|
223
|
-
|
|
224
|
-
Mobile applications may have different contexts. For instance, there can be native view and web view with a browser instance in it.
|
|
225
|
-
|
|
226
|
-
To execute commands in context of a webview use `within('webview')` function:
|
|
227
|
-
|
|
228
|
-
```js
|
|
229
|
-
I.click('~startWebView');
|
|
230
|
-
within('webview', () => {
|
|
231
|
-
I.see('Preferred car');
|
|
232
|
-
I.click('Send me your name!');
|
|
233
|
-
});
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
It will locate first available webview, switch to it, and switch back to native application after.
|
|
237
|
-
Inside WebView all browser features are enabled: CSS locators, JavaScript, etc.
|
|
238
|
-
|
|
239
|
-
To set a specific context use `{ web: 'webview.context' }` instead:
|
|
240
|
-
|
|
241
|
-
```js
|
|
242
|
-
within({webview: 'MyWEBVIEW_com.my.app'}, () => );
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
Alternatively use `switchToWeb` or `switchToNative` methods to switch between contexts.
|
|
246
|
-
|
|
247
|
-
```js
|
|
248
|
-
I.click('~startWebView');
|
|
249
|
-
I.switchToWeb();
|
|
250
|
-
I.see('Preferred car');
|
|
251
|
-
I.click('Send me your name!');
|
|
252
|
-
I.switchToNative();
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
To get a list of all contexts use `grabAllContexts` method:
|
|
256
|
-
|
|
257
|
-
```js
|
|
258
|
-
let contexts = await I.grabAllContexts();
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
## Cross-Platform Testing
|
|
262
|
-
|
|
263
|
-
It is often happen that mobile applications behave similarly on different platforms. Can we build one test for them? Yes!
|
|
264
|
-
CodeceptJS provides a way to specify different locators for Android and iOS platforms:
|
|
265
|
-
|
|
266
|
-
```js
|
|
267
|
-
I.click({android: '//android.widget.Button', ios: '//UIAApplication[1]/UIAWindow[1]/UIAButton[1]'});
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
In case some code should be executed on one platform and ignored on others use `runOnAndroid` and `runOnIOS` methods:
|
|
271
|
-
|
|
272
|
-
```js
|
|
273
|
-
I.runOnAndroid(() => {
|
|
274
|
-
I.click('Hello Android');
|
|
275
|
-
});
|
|
276
|
-
I.runOnIOS(() => {
|
|
277
|
-
I.click('Hello iOS');
|
|
278
|
-
});
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
The same code can be shared for web applications as well. To execute some code in web browser only, use `I.runInWeb`:
|
|
282
|
-
|
|
283
|
-
```js
|
|
284
|
-
I.runInWeb(() => {
|
|
285
|
-
I.amOnPage('/login'); // not available for mobile
|
|
286
|
-
I.fillField('name', 'jon');
|
|
287
|
-
I.fillField('password', '123456');
|
|
288
|
-
I.click('Login');
|
|
289
|
-
I.waitForElement('#success'); // no available for mobile
|
|
290
|
-
});
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
Just as you can specify android, and ios-specific locators, you can do so for web:
|
|
294
|
-
|
|
295
|
-
```js
|
|
296
|
-
I.click({web: '#login', ios: '//UIAApplication[1]/UIAWindow[1]/UIAButton[1]'});
|
|
297
|
-
```
|
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.
|