diff --git a/docs/helpers/AI.md b/docs/helpers/AI.md index 6e086ccde..96e0dc607 100644 --- a/docs/helpers/AI.md +++ b/docs/helpers/AI.md @@ -22,11 +22,11 @@ Use it only in development mode. It is recommended to run it only inside pause() This helper should be configured in codecept.conf.{js|ts} -- `chunkSize`: - The maximum number of characters to send to the AI API at once. We split HTML fragments by 8000 chars to not exceed token limit. Increase this value if you use GPT-4. +* `chunkSize`: - The maximum number of characters to send to the AI API at once. We split HTML fragments by 8000 chars to not exceed token limit. Increase this value if you use GPT-4. ### Parameters -- `config` +* `config` ### askForPageObject @@ -37,22 +37,22 @@ Prompt can be customized in a global config file. ```js // create page object for whole page -I.askForPageObject('home') +I.askForPageObject('home'); // create page object with extra prompt -I.askForPageObject('home', 'implement signIn(username, password) method') +I.askForPageObject('home', 'implement signIn(username, password) method'); // create page object for a specific element -I.askForPageObject('home', null, '.detail') +I.askForPageObject('home', null, '.detail'); ``` Asks for a page object based on the provided page name, locator, and extra prompt. #### Parameters -- `pageName` **[string][1]** The name of the page to retrieve the object for. -- `extraPrompt` **([string][1] | null)** An optional extra prompt for additional context or information. -- `locator` **([string][1] | null)** An optional locator to find a specific element on the page. +* `pageName` **[string][1]** The name of the page to retrieve the object for. +* `extraPrompt` **([string][1] | null)** An optional extra prompt for additional context or information. +* `locator` **([string][1] | null)** An optional locator to find a specific element on the page. Returns **[Promise][2]<[Object][3]>** A promise that resolves to the requested page object. @@ -62,7 +62,7 @@ Send a general request to AI and return response. #### Parameters -- `prompt` **[string][1]** +* `prompt` **[string][1]** Returns **[Promise][2]<[string][1]>** A Promise that resolves to the generated response from the GPT model. @@ -71,12 +71,12 @@ Returns **[Promise][2]<[string][1]>** A Promise that resolves to the generated r Asks the AI GPT language model a question based on the provided prompt within the context of the current page's HTML. ```js -I.askGptOnPage('what does this page do?') +I.askGptOnPage('what does this page do?'); ``` #### Parameters -- `prompt` **[string][1]** The question or prompt to ask the GPT model. +* `prompt` **[string][1]** The question or prompt to ask the GPT model. Returns **[Promise][2]<[string][1]>** A Promise that resolves to the generated responses from the GPT model, joined by newlines. @@ -85,16 +85,18 @@ Returns **[Promise][2]<[string][1]>** A Promise that resolves to the generated r Asks the AI a question based on the provided prompt within the context of a specific HTML fragment on the current page. ```js -I.askGptOnPageFragment('describe features of this screen', '.screen') +I.askGptOnPageFragment('describe features of this screen', '.screen'); ``` #### Parameters -- `prompt` **[string][1]** The question or prompt to ask the GPT-3.5 model. -- `locator` **[string][1]** The locator or selector used to identify the HTML fragment on the page. +* `prompt` **[string][1]** The question or prompt to ask the GPT-3.5 model. +* `locator` **[string][1]** The locator or selector used to identify the HTML fragment on the page. Returns **[Promise][2]<[string][1]>** A Promise that resolves to the generated response from the GPT model. [1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String + [2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise + [3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object diff --git a/docs/helpers/ApiDataFactory.md b/docs/helpers/ApiDataFactory.md index eefc97591..d76af53e0 100644 --- a/docs/helpers/ApiDataFactory.md +++ b/docs/helpers/ApiDataFactory.md @@ -28,9 +28,9 @@ Most of web application have API, and it can be used to create and delete test r By combining REST API with Factories you can easily create records for tests: ```js -I.have('user', { login: 'davert', email: 'davert@mail.com' }) -let id = await I.have('post', { title: 'My first post' }) -I.haveMultiple('comment', 3, { post_id: id }) +I.have('user', { login: 'davert', email: 'davert@mail.com' }); +let id = await I.have('post', { title: 'My first post'}); +I.haveMultiple('comment', 3, {post_id: id}); ``` To make this work you need @@ -53,14 +53,14 @@ See the example for Posts factories: ```js // tests/factories/posts.js -const { Factory } = require('rosie') -const { faker } = require('@faker-js/faker') +const { Factory } = require('rosie'); +const { faker } = require('@faker-js/faker'); module.exports = new Factory() - // no need to set id, it will be set by REST API - .attr('author', () => faker.person.findName()) - .attr('title', () => faker.lorem.sentence()) - .attr('body', () => faker.lorem.paragraph()) + // no need to set id, it will be set by REST API + .attr('author', () => faker.person.findName()) + .attr('title', () => faker.lorem.sentence()) + .attr('body', () => faker.lorem.paragraph()); ``` For more options see [rosie documentation][1]. @@ -71,12 +71,12 @@ Then configure ApiDataHelper to match factories and REST API: ApiDataFactory has following config options: -- `endpoint`: base URL for the API to send requests to. -- `cleanup` (default: true): should inserted records be deleted up after tests -- `factories`: list of defined factories -- `returnId` (default: false): return id instead of a complete response when creating items. -- `headers`: list of headers -- `REST`: configuration for REST requests +* `endpoint`: base URL for the API to send requests to. +* `cleanup` (default: true): should inserted records be deleted up after tests +* `factories`: list of defined factories +* `returnId` (default: false): return id instead of a complete response when creating items. +* `headers`: list of headers +* `REST`: configuration for REST requests See the example: @@ -121,19 +121,19 @@ For instance, to set timeout you should add: By default to create a record ApiDataFactory will use endpoint and plural factory name: -- create: `POST {endpoint}/{resource} data` -- delete: `DELETE {endpoint}/{resource}/id` +* create: `POST {endpoint}/{resource} data` +* delete: `DELETE {endpoint}/{resource}/id` Example (`endpoint`: `http://app.com/api`): -- create: POST request to `http://app.com/api/users` -- delete: DELETE request to `http://app.com/api/users/1` +* create: POST request to `http://app.com/api/users` +* delete: DELETE request to `http://app.com/api/users/1` This behavior can be configured with following options: -- `uri`: set different resource uri. Example: `uri: account` => `http://app.com/api/account`. -- `create`: override create options. Expected format: `{ method: uri }`. Example: `{ "post": "/users/create" }` -- `delete`: override delete options. Expected format: `{ method: uri }`. Example: `{ "post": "/users/delete/{id}" }` +* `uri`: set different resource uri. Example: `uri: account` => `http://app.com/api/account`. +* `create`: override create options. Expected format: `{ method: uri }`. Example: `{ "post": "/users/create" }` +* `delete`: override delete options. Expected format: `{ method: uri }`. Example: `{ "post": "/users/delete/{id}" }` Requests can also be overridden with a function which returns [axois request config][4]. @@ -146,11 +146,11 @@ delete: (id) => ({ method: 'delete', url: '/posts', data: { id } }) Requests can be updated on the fly by using `onRequest` function. For instance, you can pass in current session from a cookie. ```js -onRequest: async request => { - // using global codeceptjs instance - let cookie = await codeceptjs.container.helpers('WebDriver').grabCookie('session') - request.headers = { Cookie: `session=${cookie.value}` } -} + onRequest: async (request) => { + // using global codeceptjs instance + let cookie = await codeceptjs.container.helpers('WebDriver').grabCookie('session'); + request.headers = { Cookie: `session=${cookie.value}` }; + } ``` ### Responses @@ -158,7 +158,7 @@ onRequest: async request => { By default `I.have()` returns a promise with a created data: ```js -let client = await I.have('client') +let client = await I.have('client'); ``` Ids of created records are collected and used in the end of a test for the cleanup. @@ -166,11 +166,11 @@ If you need to receive `id` instead of full response enable `returnId` in a help ```js // returnId: false -let clientId = await I.have('client') +let clientId = await I.have('client'); // clientId == 1 // returnId: true -let clientId = await I.have('client') +let clientId = await I.have('client'); // client == { name: 'John', email: 'john@snow.com' } ``` @@ -190,27 +190,27 @@ By default `id` property of response is taken. This behavior can be changed by s ### Parameters -- `config` +* `config` -### \_requestCreate +### _requestCreate Executes request to create a record in API. Can be replaced from a in custom helper. #### Parameters -- `factory` **any** -- `data` **any** +* `factory` **any** +* `data` **any** -### \_requestDelete +### _requestDelete Executes request to delete a record in API Can be replaced from a custom helper. #### Parameters -- `factory` **any** -- `id` **any** +* `factory` **any** +* `id` **any** ### have @@ -218,19 +218,19 @@ Generates a new record using factory and saves API request to store it. ```js // create a user -I.have('user') +I.have('user'); // create user with defined email // and receive it when inside async function -const user = await I.have('user', { email: 'user@user.com' }) +const user = await I.have('user', { email: 'user@user.com'}); // create a user with options that will not be included in the final request -I.have('user', {}, { age: 33, height: 55 }) +I.have('user', { }, { age: 33, height: 55 }) ``` #### Parameters -- `factory` **any** factory to use -- `params` **any?** predefined parameters -- `options` **any?** options for programmatically generate the attributes +* `factory` **any** factory to use +* `params` **any?** predefined parameters +* `options` **any?** options for programmatically generate the attributes Returns **[Promise][5]** @@ -240,24 +240,28 @@ Generates bunch of records and saves multiple API requests to store them. ```js // create 3 posts -I.haveMultiple('post', 3) +I.haveMultiple('post', 3); // create 3 posts by one author -I.haveMultiple('post', 3, { author: 'davert' }) +I.haveMultiple('post', 3, { author: 'davert' }); // create 3 posts by one author with options -I.haveMultiple('post', 3, { author: 'davert' }, { publish_date: '01.01.1997' }) +I.haveMultiple('post', 3, { author: 'davert' }, { publish_date: '01.01.1997' }); ``` #### Parameters -- `factory` **any** -- `times` **any** -- `params` **any?** -- `options` **any?** +* `factory` **any** +* `times` **any** +* `params` **any?** +* `options` **any?** [1]: https://github.com/rosiejs/rosie + [2]: https://www.npmjs.com/package/faker + [3]: http://codecept.io/helpers/REST/ + [4]: https://github.com/axios/axios#request-config + [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise diff --git a/docs/helpers/Appium.md b/docs/helpers/Appium.md index d68b66484..7b9fdab62 100644 --- a/docs/helpers/Appium.md +++ b/docs/helpers/Appium.md @@ -32,20 +32,20 @@ Launch the daemon: `appium` This helper should be configured in codecept.conf.ts or codecept.conf.js -- `appiumV2`: set this to true if you want to run tests with AppiumV2. See more how to setup [here][3] -- `app`: Application path. Local path or remote URL to an .ipa or .apk file, or a .zip containing one of these. Alias to desiredCapabilities.appPackage -- `host`: (default: 'localhost') Appium host -- `port`: (default: '4723') Appium port -- `platform`: (Android or IOS), which mobile OS to use; alias to desiredCapabilities.platformName -- `restart`: restart browser or app between tests (default: true), if set to false cookies will be cleaned but browser window will be kept and for apps nothing will be changed. -- `desiredCapabilities`: \[], Appium capabilities, see below - - `platformName` - Which mobile OS platform to use - - `appPackage` - Java package of the Android app you want to run - - `appActivity` - Activity name for the Android activity you want to launch from your package. - - `deviceName`: The kind of mobile device or emulator to use - - `platformVersion`: Mobile OS version - - `app` - The absolute local path or remote http URL to an .ipa or .apk file, or a .zip containing one of these. Appium will attempt to install this app binary on the appropriate device first. - - `browserName`: Name of mobile web browser to automate. Should be an empty string if automating an app instead. +* `appiumV2`: set this to true if you want to run tests with AppiumV2. See more how to setup [here][3] +* `app`: Application path. Local path or remote URL to an .ipa or .apk file, or a .zip containing one of these. Alias to desiredCapabilities.appPackage +* `host`: (default: 'localhost') Appium host +* `port`: (default: '4723') Appium port +* `platform`: (Android or IOS), which mobile OS to use; alias to desiredCapabilities.platformName +* `restart`: restart browser or app between tests (default: true), if set to false cookies will be cleaned but browser window will be kept and for apps nothing will be changed. +* `desiredCapabilities`: \[], Appium capabilities, see below + * `platformName` - Which mobile OS platform to use + * `appPackage` - Java package of the Android app you want to run + * `appActivity` - Activity name for the Android activity you want to launch from your package. + * `deviceName`: The kind of mobile device or emulator to use + * `platformVersion`: Mobile OS version + * `app` - The absolute local path or remote http URL to an .ipa or .apk file, or a .zip containing one of these. Appium will attempt to install this app binary on the appropriate device first. + * `browserName`: Name of mobile web browser to automate. Should be an empty string if automating an app instead. Example Android App: @@ -157,7 +157,7 @@ let browser = this.helpers['Appium'].browser ### Parameters -- `config` +* `config` ### runOnIOS @@ -165,38 +165,35 @@ Execute code only on iOS ```js I.runOnIOS(() => { - I.click('//UIAApplication[1]/UIAWindow[1]/UIAButton[1]') - I.see('Hi, IOS', '~welcome') -}) + I.click('//UIAApplication[1]/UIAWindow[1]/UIAButton[1]'); + I.see('Hi, IOS', '~welcome'); +}); ``` Additional filter can be applied by checking for capabilities. For instance, this code will be executed only on iPhone 5s: ```js -I.runOnIOS({ deviceName: 'iPhone 5s' }, () => { - // ... -}) +I.runOnIOS({deviceName: 'iPhone 5s'},() => { + // ... +}); ``` Also capabilities can be checked by a function. ```js -I.runOnAndroid( - caps => { - // caps is current config of desiredCapabiliites - return caps.platformVersion >= 6 - }, - () => { - // ... - }, -) +I.runOnAndroid((caps) => { + // caps is current config of desiredCapabiliites + return caps.platformVersion >= 6 +},() => { + // ... +}); ``` #### Parameters -- `caps` **any** -- `fn` **any** +* `caps` **any** +* `fn` **any** ### runOnAndroid @@ -204,38 +201,35 @@ Execute code only on Android ```js I.runOnAndroid(() => { - I.click('io.selendroid.testapp:id/buttonTest') -}) + I.click('io.selendroid.testapp:id/buttonTest'); +}); ``` Additional filter can be applied by checking for capabilities. For instance, this code will be executed only on Android 6.0: ```js -I.runOnAndroid({ platformVersion: '6.0' }, () => { - // ... -}) +I.runOnAndroid({platformVersion: '6.0'},() => { + // ... +}); ``` Also capabilities can be checked by a function. In this case, code will be executed only on Android >= 6. ```js -I.runOnAndroid( - caps => { - // caps is current config of desiredCapabiliites - return caps.platformVersion >= 6 - }, - () => { - // ... - }, -) +I.runOnAndroid((caps) => { + // caps is current config of desiredCapabiliites + return caps.platformVersion >= 6 +},() => { + // ... +}); ``` #### Parameters -- `caps` **any** -- `fn` **any** +* `caps` **any** +* `fn` **any** ### runInWeb @@ -243,9 +237,9 @@ Execute code only in Web mode. ```js I.runInWeb(() => { - I.waitForElement('#data') - I.seeInCurrentUrl('/data') -}) + I.waitForElement('#data'); + I.seeInCurrentUrl('/data'); +}); ``` ### checkIfAppIsInstalled @@ -253,12 +247,12 @@ I.runInWeb(() => { Returns app installation status. ```js -I.checkIfAppIsInstalled('com.example.android.apis') +I.checkIfAppIsInstalled("com.example.android.apis"); ``` #### Parameters -- `bundleId` **[string][5]** String ID of bundled app +* `bundleId` **[string][5]** String ID of bundled app Returns **[Promise][6]<[boolean][7]>** Appium: support only Android @@ -267,12 +261,12 @@ Returns **[Promise][6]<[boolean][7]>** Appium: support only Android Check if an app is installed. ```js -I.seeAppIsInstalled('com.example.android.apis') +I.seeAppIsInstalled("com.example.android.apis"); ``` #### Parameters -- `bundleId` **[string][5]** String ID of bundled app +* `bundleId` **[string][5]** String ID of bundled app Returns **[Promise][6]\** Appium: support only Android @@ -281,12 +275,12 @@ Returns **[Promise][6]\** Appium: support only Android Check if an app is not installed. ```js -I.seeAppIsNotInstalled('com.example.android.apis') +I.seeAppIsNotInstalled("com.example.android.apis"); ``` #### Parameters -- `bundleId` **[string][5]** String ID of bundled app +* `bundleId` **[string][5]** String ID of bundled app Returns **[Promise][6]\** Appium: support only Android @@ -295,12 +289,12 @@ Returns **[Promise][6]\** Appium: support only Android Install an app on device. ```js -I.installApp('/path/to/file.apk') +I.installApp('/path/to/file.apk'); ``` #### Parameters -- `path` **[string][5]** path to apk file +* `path` **[string][5]** path to apk file Returns **[Promise][6]\** Appium: support only Android @@ -309,22 +303,22 @@ Returns **[Promise][6]\** Appium: support only Android Remove an app from the device. ```js -I.removeApp('appName', 'com.example.android.apis') +I.removeApp('appName', 'com.example.android.apis'); ``` Appium: support only Android #### Parameters -- `appId` **[string][5]** -- `bundleId` **[string][5]?** ID of bundle +* `appId` **[string][5]** +* `bundleId` **[string][5]?** ID of bundle ### resetApp Reset the currently running app for current session. ```js -I.resetApp() +I.resetApp(); ``` ### seeCurrentActivityIs @@ -332,12 +326,12 @@ I.resetApp() Check current activity on an Android device. ```js -I.seeCurrentActivityIs('.HomeScreenActivity') +I.seeCurrentActivityIs(".HomeScreenActivity") ``` #### Parameters -- `currentActivity` **[string][5]** +* `currentActivity` **[string][5]** Returns **[Promise][6]\** Appium: support only Android @@ -346,7 +340,7 @@ Returns **[Promise][6]\** Appium: support only Android Check whether the device is locked. ```js -I.seeDeviceIsLocked() +I.seeDeviceIsLocked(); ``` Returns **[Promise][6]\** Appium: support only Android @@ -356,7 +350,7 @@ Returns **[Promise][6]\** Appium: support only Android Check whether the device is not locked. ```js -I.seeDeviceIsUnlocked() +I.seeDeviceIsUnlocked(); ``` Returns **[Promise][6]\** Appium: support only Android @@ -366,13 +360,13 @@ Returns **[Promise][6]\** Appium: support only Android Check the device orientation ```js -I.seeOrientationIs('PORTRAIT') +I.seeOrientationIs('PORTRAIT'); I.seeOrientationIs('LANDSCAPE') ``` #### Parameters -- `orientation` **(`"LANDSCAPE"` | `"PORTRAIT"`)** LANDSCAPE or PORTRAITAppium: support Android and iOS +* `orientation` **(`"LANDSCAPE"` | `"PORTRAIT"`)** LANDSCAPE or PORTRAITAppium: support Android and iOS Returns **[Promise][6]\** @@ -381,13 +375,13 @@ Returns **[Promise][6]\** Set a device orientation. Will fail, if app will not set orientation ```js -I.setOrientation('PORTRAIT') +I.setOrientation('PORTRAIT'); I.setOrientation('LANDSCAPE') ``` #### Parameters -- `orientation` **(`"LANDSCAPE"` | `"PORTRAIT"`)** LANDSCAPE or PORTRAITAppium: support Android and iOS +* `orientation` **(`"LANDSCAPE"` | `"PORTRAIT"`)** LANDSCAPE or PORTRAITAppium: support Android and iOS ### grabAllContexts @@ -402,7 +396,7 @@ Returns **[Promise][6]<[Array][8]<[string][5]>>** Appium: support Android and iO Retrieve current context ```js -let context = await I.grabContext() +let context = await I.grabContext(); ``` Returns **[Promise][6]<([string][5] | null)>** Appium: support Android and iOS @@ -412,7 +406,7 @@ Returns **[Promise][6]<([string][5] | null)>** Appium: support Android and iOS Get current device activity. ```js -let activity = await I.grabCurrentActivity() +let activity = await I.grabCurrentActivity(); ``` Returns **[Promise][6]<[string][5]>** Appium: support only Android @@ -424,7 +418,7 @@ The actual server value will be a number. However WebdriverIO additional properties to the response object to allow easier assertions. ```js -let con = await I.grabNetworkConnection() +let con = await I.grabNetworkConnection(); ``` Returns **[Promise][6]<{}>** Appium: support only Android @@ -434,7 +428,7 @@ Returns **[Promise][6]<{}>** Appium: support only Android Get current orientation. ```js -let orientation = await I.grabOrientation() +let orientation = await I.grabOrientation(); ``` Returns **[Promise][6]<[string][5]>** Appium: support Android and iOS @@ -444,7 +438,7 @@ Returns **[Promise][6]<[string][5]>** Appium: support Android and iOS Get all the currently specified settings. ```js -let settings = await I.grabSettings() +let settings = await I.grabSettings(); ``` Returns **[Promise][6]<[string][5]>** Appium: support Android and iOS @@ -455,7 +449,7 @@ Switch to the specified context. #### Parameters -- `context` **any** the context to switch to +* `context` **any** the context to switch to ### switchToWeb @@ -464,33 +458,33 @@ If no context is provided switches to the first detected web context ```js // switch to first web context -I.switchToWeb() +I.switchToWeb(); // or set the context explicitly -I.switchToWeb('WEBVIEW_io.selendroid.testapp') +I.switchToWeb('WEBVIEW_io.selendroid.testapp'); ``` #### Parameters -- `context` **[string][5]?** +* `context` **[string][5]?** Returns **[Promise][6]\** ### switchToNative Switches to native context. -By default switches to NATIVE_APP context unless other specified. +By default switches to NATIVE\_APP context unless other specified. ```js -I.switchToNative() +I.switchToNative(); // or set context explicitly -I.switchToNative('SOME_OTHER_CONTEXT') +I.switchToNative('SOME_OTHER_CONTEXT'); ``` #### Parameters -- `context` **any?** (optional, default `null`) +* `context` **any?** (optional, default `null`) Returns **[Promise][6]\** @@ -499,15 +493,15 @@ Returns **[Promise][6]\** Start an arbitrary Android activity during a session. ```js -I.startActivity('io.selendroid.testapp', '.RegisterUserActivity') +I.startActivity('io.selendroid.testapp', '.RegisterUserActivity'); ``` Appium: support only Android #### Parameters -- `appPackage` **[string][5]** -- `appActivity` **[string][5]** +* `appPackage` **[string][5]** +* `appActivity` **[string][5]** Returns **[Promise][6]\** @@ -515,9 +509,9 @@ Returns **[Promise][6]\** Set network connection mode. -- airplane mode -- wifi mode -- data data +* airplane mode +* wifi mode +* data data ```js I.setNetworkConnection(0) // airplane mode off, wifi off, data off @@ -533,7 +527,7 @@ Appium: support only Android #### Parameters -- `value` **[number][10]** The network connection mode bitmask +* `value` **[number][10]** The network connection mode bitmask Returns **[Promise][6]<[number][10]>** @@ -542,12 +536,12 @@ Returns **[Promise][6]<[number][10]>** Update the current setting on the device ```js -I.setSettings({ cyberdelia: 'open' }) +I.setSettings({cyberdelia: 'open'}); ``` #### Parameters -- `settings` **[object][11]** objectAppium: support Android and iOS +* `settings` **[object][11]** objectAppium: support Android and iOS ### hideDeviceKeyboard @@ -555,19 +549,19 @@ Hide the keyboard. ```js // taps outside to hide keyboard per default -I.hideDeviceKeyboard() -I.hideDeviceKeyboard('tapOutside') +I.hideDeviceKeyboard(); +I.hideDeviceKeyboard('tapOutside'); // or by pressing key -I.hideDeviceKeyboard('pressKey', 'Done') +I.hideDeviceKeyboard('pressKey', 'Done'); ``` Appium: support Android and iOS #### Parameters -- `strategy` **(`"tapOutside"` | `"pressKey"`)?** Desired strategy to close keyboard (‘tapOutside’ or ‘pressKey’) -- `key` **[string][5]?** Optional key +* `strategy` **(`"tapOutside"` | `"pressKey"`)?** Desired strategy to close keyboard (‘tapOutside’ or ‘pressKey’) +* `key` **[string][5]?** Optional key ### sendDeviceKeyEvent @@ -575,12 +569,12 @@ Send a key event to the device. List of keys: [https://developer.android.com/reference/android/view/KeyEvent.html][12] ```js -I.sendDeviceKeyEvent(3) +I.sendDeviceKeyEvent(3); ``` #### Parameters -- `keyValue` **[number][10]** Device specific key value +* `keyValue` **[number][10]** Device specific key value Returns **[Promise][6]\** Appium: support only Android @@ -589,7 +583,7 @@ Returns **[Promise][6]\** Appium: support only Android Open the notifications panel on the device. ```js -I.openNotifications() +I.openNotifications(); ``` Returns **[Promise][6]\** Appium: support only Android @@ -603,13 +597,13 @@ application on the device. [See complete documentation][13] ```js -I.makeTouchAction('~buttonStartWebviewCD', 'tap') +I.makeTouchAction("~buttonStartWebviewCD", 'tap'); ``` #### Parameters -- `locator` -- `action` +* `locator` +* `action` Returns **[Promise][6]\** Appium: support Android and iOS @@ -618,14 +612,14 @@ Returns **[Promise][6]\** Appium: support Android and iOS Taps on element. ```js -I.tap('~buttonStartWebviewCD') +I.tap("~buttonStartWebviewCD"); ``` Shortcut for `makeTouchAction` #### Parameters -- `locator` **any** +* `locator` **any** Returns **[Promise][6]\** @@ -634,18 +628,18 @@ Returns **[Promise][6]\** Perform a swipe on the screen or an element. ```js -let locator = '#io.selendroid.testapp:id/LinearLayout1' -I.swipe(locator, 800, 1200, 1000) +let locator = "#io.selendroid.testapp:id/LinearLayout1"; +I.swipe(locator, 800, 1200, 1000); ``` [See complete reference][14] #### Parameters -- `locator` **([string][5] | [object][11])** -- `xoffset` **[number][10]** -- `yoffset` **[number][10]** -- `speed` **[number][10]** (optional), 1000 by default (optional, default `1000`) +* `locator` **([string][5] | [object][11])** +* `xoffset` **[number][10]** +* `yoffset` **[number][10]** +* `speed` **[number][10]** (optional), 1000 by default (optional, default `1000`) Returns **[Promise][6]\** Appium: support Android and iOS @@ -654,30 +648,30 @@ Returns **[Promise][6]\** Appium: support Android and iOS Perform a swipe on the screen. ```js -I.performSwipe({ x: 300, y: 100 }, { x: 200, y: 100 }) +I.performSwipe({ x: 300, y: 100 }, { x: 200, y: 100 }); ``` #### Parameters -- `from` **[object][11]** -- `to` **[object][11]** Appium: support Android and iOS +* `from` **[object][11]** +* `to` **[object][11]** Appium: support Android and iOS ### swipeDown Perform a swipe down on an element. ```js -let locator = '#io.selendroid.testapp:id/LinearLayout1' -I.swipeDown(locator) // simple swipe -I.swipeDown(locator, 500) // set speed -I.swipeDown(locator, 1200, 1000) // set offset and speed +let locator = "#io.selendroid.testapp:id/LinearLayout1"; +I.swipeDown(locator); // simple swipe +I.swipeDown(locator, 500); // set speed +I.swipeDown(locator, 1200, 1000); // set offset and speed ``` #### Parameters -- `locator` **([string][5] | [object][11])** -- `yoffset` **[number][10]?** (optional) (optional, default `1000`) -- `speed` **[number][10]** (optional), 1000 by default (optional, default `1000`) +* `locator` **([string][5] | [object][11])** +* `yoffset` **[number][10]?** (optional) (optional, default `1000`) +* `speed` **[number][10]** (optional), 1000 by default (optional, default `1000`) Returns **[Promise][6]\** Appium: support Android and iOS @@ -686,17 +680,17 @@ Returns **[Promise][6]\** Appium: support Android and iOS Perform a swipe left on an element. ```js -let locator = '#io.selendroid.testapp:id/LinearLayout1' -I.swipeLeft(locator) // simple swipe -I.swipeLeft(locator, 500) // set speed -I.swipeLeft(locator, 1200, 1000) // set offset and speed +let locator = "#io.selendroid.testapp:id/LinearLayout1"; +I.swipeLeft(locator); // simple swipe +I.swipeLeft(locator, 500); // set speed +I.swipeLeft(locator, 1200, 1000); // set offset and speed ``` #### Parameters -- `locator` **([string][5] | [object][11])** -- `xoffset` **[number][10]?** (optional) (optional, default `1000`) -- `speed` **[number][10]** (optional), 1000 by default (optional, default `1000`) +* `locator` **([string][5] | [object][11])** +* `xoffset` **[number][10]?** (optional) (optional, default `1000`) +* `speed` **[number][10]** (optional), 1000 by default (optional, default `1000`) Returns **[Promise][6]\** Appium: support Android and iOS @@ -705,17 +699,17 @@ Returns **[Promise][6]\** Appium: support Android and iOS Perform a swipe right on an element. ```js -let locator = '#io.selendroid.testapp:id/LinearLayout1' -I.swipeRight(locator) // simple swipe -I.swipeRight(locator, 500) // set speed -I.swipeRight(locator, 1200, 1000) // set offset and speed +let locator = "#io.selendroid.testapp:id/LinearLayout1"; +I.swipeRight(locator); // simple swipe +I.swipeRight(locator, 500); // set speed +I.swipeRight(locator, 1200, 1000); // set offset and speed ``` #### Parameters -- `locator` **([string][5] | [object][11])** -- `xoffset` **[number][10]?** (optional) (optional, default `1000`) -- `speed` **[number][10]** (optional), 1000 by default (optional, default `1000`) +* `locator` **([string][5] | [object][11])** +* `xoffset` **[number][10]?** (optional) (optional, default `1000`) +* `speed` **[number][10]** (optional), 1000 by default (optional, default `1000`) Returns **[Promise][6]\** Appium: support Android and iOS @@ -724,17 +718,17 @@ Returns **[Promise][6]\** Appium: support Android and iOS Perform a swipe up on an element. ```js -let locator = '#io.selendroid.testapp:id/LinearLayout1' -I.swipeUp(locator) // simple swipe -I.swipeUp(locator, 500) // set speed -I.swipeUp(locator, 1200, 1000) // set offset and speed +let locator = "#io.selendroid.testapp:id/LinearLayout1"; +I.swipeUp(locator); // simple swipe +I.swipeUp(locator, 500); // set speed +I.swipeUp(locator, 1200, 1000); // set offset and speed ``` #### Parameters -- `locator` **([string][5] | [object][11])** -- `yoffset` **[number][10]?** (optional) (optional, default `1000`) -- `speed` **[number][10]** (optional), 1000 by default (optional, default `1000`) +* `locator` **([string][5] | [object][11])** +* `yoffset` **[number][10]?** (optional) (optional, default `1000`) +* `speed` **[number][10]** (optional), 1000 by default (optional, default `1000`) Returns **[Promise][6]\** Appium: support Android and iOS @@ -744,23 +738,22 @@ Perform a swipe in selected direction on an element to searchable element. ```js I.swipeTo( - 'android.widget.CheckBox', // searchable element - '//android.widget.ScrollView/android.widget.LinearLayout', // scroll element - 'up', // direction - 30, - 100, - 500, -) + "android.widget.CheckBox", // searchable element + "//android.widget.ScrollView/android.widget.LinearLayout", // scroll element + "up", // direction + 30, + 100, + 500); ``` #### Parameters -- `searchableLocator` **[string][5]** -- `scrollLocator` **[string][5]** -- `direction` **[string][5]** -- `timeout` **[number][10]** -- `offset` **[number][10]** -- `speed` **[number][10]** +* `searchableLocator` **[string][5]** +* `scrollLocator` **[string][5]** +* `direction` **[string][5]** +* `timeout` **[number][10]** +* `offset` **[number][10]** +* `speed` **[number][10]** Returns **[Promise][6]\** Appium: support Android and iOS @@ -770,50 +763,45 @@ Performs a specific touch action. The action object need to contain the action name, x/y coordinates ```js -I.touchPerform([ - { +I.touchPerform([{ action: 'press', options: { x: 100, - y: 200, - }, - }, - { action: 'release' }, -]) - -I.touchPerform([ - { - action: 'tap', - options: { - element: '1', // json web element was queried before - x: 10, // x offset - y: 20, // y offset - count: 1, // number of touches - }, - }, -]) + y: 200 + } +}, {action: 'release'}]) + +I.touchPerform([{ + action: 'tap', + options: { + element: '1', // json web element was queried before + x: 10, // x offset + y: 20, // y offset + count: 1 // number of touches + } +}]); ``` Appium: support Android and iOS #### Parameters -- `actions` **[Array][8]** Array of touch actions +* `actions` **[Array][8]** Array of touch actions ### pullFile Pulls a file from the device. ```js -I.pullFile('/storage/emulated/0/DCIM/logo.png', 'my/path') +I.pullFile('/storage/emulated/0/DCIM/logo.png', 'my/path'); // save file to output dir -I.pullFile('/storage/emulated/0/DCIM/logo.png', output_dir) +I.pullFile('/storage/emulated/0/DCIM/logo.png', output_dir); ``` #### Parameters -- `path` **[string][5]** -- `dest` **[string][5]** +* `path` **[string][5]** +* `dest` **[string][5]** Returns **[Promise][6]<[string][5]>** Appium: support Android and iOS @@ -822,7 +810,7 @@ Returns **[Promise][6]<[string][5]>** Appium: support Android and iOS Perform a shake action on the device. ```js -I.shakeDevice() +I.shakeDevice(); ``` Returns **[Promise][6]\** Appium: support only iOS @@ -839,12 +827,12 @@ See corresponding [webdriverio reference][15]. #### Parameters -- `x` -- `y` -- `duration` -- `radius` -- `rotation` -- `touchCount` +* `x` +* `y` +* `duration` +* `radius` +* `rotation` +* `touchCount` Returns **[Promise][6]\** Appium: support only iOS @@ -856,8 +844,8 @@ See corresponding [webdriverio reference][16]. #### Parameters -- `id` -- `value` +* `id` +* `value` Returns **[Promise][6]\** Appium: support only iOS @@ -866,14 +854,14 @@ Returns **[Promise][6]\** Appium: support only iOS Simulate Touch ID with either valid (match == true) or invalid (match == false) fingerprint. ```js -I.touchId() // simulates valid fingerprint -I.touchId(true) // simulates valid fingerprint -I.touchId(false) // simulates invalid fingerprint +I.touchId(); // simulates valid fingerprint +I.touchId(true); // simulates valid fingerprint +I.touchId(false); // simulates invalid fingerprint ``` #### Parameters -- `match` +* `match` Returns **[Promise][6]\** Appium: support only iOS TODO: not tested @@ -883,7 +871,7 @@ TODO: not tested Close the given application. ```js -I.closeApp() +I.closeApp(); ``` Returns **[Promise][6]\** Appium: support both Android and iOS @@ -894,15 +882,15 @@ Appends text to a input field or textarea. Field is located by name, label, CSS or XPath ```js -I.appendField('#myTextField', 'appended') +I.appendField('#myTextField', 'appended'); // typing secret -I.appendField('password', secret('123456')) +I.appendField('password', secret('123456')); ``` #### Parameters -- `field` **([string][5] | [object][11])** located by label|name|CSS|XPath|strict locator -- `value` **[string][5]** text value to append. +* `field` **([string][5] | [object][11])** located by label|name|CSS|XPath|strict locator +* `value` **[string][5]** text value to append. Returns **void** automatically synchronized promise through #recorder @@ -914,15 +902,15 @@ Element is located by label or name or CSS or XPath. The second parameter is a context (CSS or XPath locator) to narrow the search. ```js -I.checkOption('#agree') -I.checkOption('I Agree to Terms and Conditions') -I.checkOption('agree', '//form') +I.checkOption('#agree'); +I.checkOption('I Agree to Terms and Conditions'); +I.checkOption('agree', '//form'); ``` #### Parameters -- `field` **([string][5] | [object][11])** checkbox located by label | name | CSS | XPath | strict locator. -- `context` **([string][5]? | [object][11])** (optional, `null` by default) element located by CSS | XPath | strict locator. (optional, default `null`) +* `field` **([string][5] | [object][11])** checkbox located by label | name | CSS | XPath | strict locator. +* `context` **([string][5]? | [object][11])** (optional, `null` by default) element located by CSS | XPath | strict locator. (optional, default `null`) Returns **void** automatically synchronized promise through #recorder @@ -937,23 +925,23 @@ The second parameter is a context (CSS or XPath locator) to narrow the search. ```js // simple link -I.click('Logout') +I.click('Logout'); // button of form -I.click('Submit') +I.click('Submit'); // CSS button -I.click('#form input[type=submit]') +I.click('#form input[type=submit]'); // XPath -I.click('//form/*[@type=submit]') +I.click('//form/*[@type=submit]'); // link in context -I.click('Logout', '#nav') +I.click('Logout', '#nav'); // using strict locator -I.click({ css: 'nav a.login' }) +I.click({css: 'nav a.login'}); ``` #### Parameters -- `locator` **([string][5] | [object][11])** clickable link or button located by text, or any element located by CSS|XPath|strict locator. -- `context` **([string][5]? | [object][11] | null)** (optional, `null` by default) element to search in CSS|XPath|Strict locator. (optional, default `null`) +* `locator` **([string][5] | [object][11])** clickable link or button located by text, or any element located by CSS|XPath|strict locator. +* `context` **([string][5]? | [object][11] | null)** (optional, `null` by default) element to search in CSS|XPath|Strict locator. (optional, default `null`) Returns **void** automatically synchronized promise through #recorder @@ -962,14 +950,14 @@ Returns **void** automatically synchronized promise through #recorder Verifies that the specified checkbox is not checked. ```js -I.dontSeeCheckboxIsChecked('#agree') // located by ID -I.dontSeeCheckboxIsChecked('I agree to terms') // located by label -I.dontSeeCheckboxIsChecked('agree') // located by name +I.dontSeeCheckboxIsChecked('#agree'); // located by ID +I.dontSeeCheckboxIsChecked('I agree to terms'); // located by label +I.dontSeeCheckboxIsChecked('agree'); // located by name ``` #### Parameters -- `field` **([string][5] | [object][11])** located by label|name|CSS|XPath|strict locator. +* `field` **([string][5] | [object][11])** located by label|name|CSS|XPath|strict locator. Returns **void** automatically synchronized promise through #recorder @@ -978,12 +966,12 @@ Returns **void** automatically synchronized promise through #recorder Opposite to `seeElement`. Checks that element is not visible (or in DOM) ```js -I.dontSeeElement('.modal') // modal is not shown +I.dontSeeElement('.modal'); // modal is not shown ``` #### Parameters -- `locator` **([string][5] | [object][11])** located by CSS|XPath|Strict locator. +* `locator` **([string][5] | [object][11])** located by CSS|XPath|Strict locator. Returns **void** automatically synchronized promise through #recorder @@ -993,14 +981,14 @@ Checks that value of input field or textarea doesn't equal to given value Opposite to `seeInField`. ```js -I.dontSeeInField('email', 'user@user.com') // field by name -I.dontSeeInField({ css: 'form input.email' }, 'user@user.com') // field by CSS +I.dontSeeInField('email', 'user@user.com'); // field by name +I.dontSeeInField({ css: 'form input.email' }, 'user@user.com'); // field by CSS ``` #### Parameters -- `field` **([string][5] | [object][11])** located by label|name|CSS|XPath|strict locator. -- `value` **([string][5] | [object][11])** value to check. +* `field` **([string][5] | [object][11])** located by label|name|CSS|XPath|strict locator. +* `value` **([string][5] | [object][11])** value to check. Returns **void** automatically synchronized promise through #recorder @@ -1010,14 +998,14 @@ Opposite to `see`. Checks that a text is not present on a page. Use context parameter to narrow down the search. ```js -I.dontSee('Login') // assume we are already logged in. -I.dontSee('Login', '.nav') // no login inside .nav element +I.dontSee('Login'); // assume we are already logged in. +I.dontSee('Login', '.nav'); // no login inside .nav element ``` #### Parameters -- `text` **[string][5]** which is not present. -- `context` **([string][5] | [object][11])?** (optional) element located by CSS|XPath|strict locator in which to perfrom search. (optional, default `null`) +* `text` **[string][5]** which is not present. +* `context` **([string][5] | [object][11])?** (optional) element located by CSS|XPath|strict locator in which to perfrom search. (optional, default `null`) Returns **void** automatically synchronized promise through #recorder @@ -1028,19 +1016,19 @@ Field is located by name, label, CSS, or XPath. ```js // by label -I.fillField('Email', 'hello@world.com') +I.fillField('Email', 'hello@world.com'); // by name -I.fillField('password', secret('123456')) +I.fillField('password', secret('123456')); // by CSS -I.fillField('form#login input[name=username]', 'John') +I.fillField('form#login input[name=username]', 'John'); // or by strict locator -I.fillField({ css: 'form#login input[name=username]' }, 'John') +I.fillField({css: 'form#login input[name=username]'}, 'John'); ``` #### Parameters -- `field` **([string][5] | [object][11])** located by label|name|CSS|XPath|strict locator. -- `value` **([string][5] | [object][11])** text value to fill. +* `field` **([string][5] | [object][11])** located by label|name|CSS|XPath|strict locator. +* `value` **([string][5] | [object][11])** text value to fill. Returns **void** automatically synchronized promise through #recorder @@ -1050,12 +1038,12 @@ Retrieves all texts from an element located by CSS or XPath and returns it to te Resumes test execution, so **should be used inside async with `await`** operator. ```js -let pins = await I.grabTextFromAll('#pin li') +let pins = await I.grabTextFromAll('#pin li'); ``` #### Parameters -- `locator` **([string][5] | [object][11])** element located by CSS|XPath|strict locator. +* `locator` **([string][5] | [object][11])** element located by CSS|XPath|strict locator. Returns **[Promise][6]<[Array][8]<[string][5]>>** attribute value @@ -1065,14 +1053,14 @@ Retrieves a text from an element located by CSS or XPath and returns it to test. Resumes test execution, so **should be used inside async with `await`** operator. ```js -let pin = await I.grabTextFrom('#pin') +let pin = await I.grabTextFrom('#pin'); ``` If multiple elements found returns first element. #### Parameters -- `locator` **([string][5] | [object][11])** element located by CSS|XPath|strict locator. +* `locator` **([string][5] | [object][11])** element located by CSS|XPath|strict locator. Returns **[Promise][6]<[string][5]>** attribute value @@ -1082,12 +1070,12 @@ Grab number of visible elements by locator. Resumes test execution, so **should be used inside async function with `await`** operator. ```js -let numOfElements = await I.grabNumberOfVisibleElements('p') +let numOfElements = await I.grabNumberOfVisibleElements('p'); ``` #### Parameters -- `locator` **([string][5] | [object][11])** located by CSS|XPath|strict locator. +* `locator` **([string][5] | [object][11])** located by CSS|XPath|strict locator. Returns **[Promise][6]<[number][10]>** number of visible elements @@ -1100,13 +1088,13 @@ Resumes test execution, so **should be used inside async with `await`** operator If more than one element is found - attribute of first element is returned. ```js -let hint = await I.grabAttributeFrom('#tooltip', 'title') +let hint = await I.grabAttributeFrom('#tooltip', 'title'); ``` #### Parameters -- `locator` **([string][5] | [object][11])** element located by CSS|XPath|strict locator. -- `attr` **[string][5]** attribute name. +* `locator` **([string][5] | [object][11])** element located by CSS|XPath|strict locator. +* `attr` **[string][5]** attribute name. Returns **[Promise][6]<[string][5]>** attribute value @@ -1117,13 +1105,13 @@ Retrieves an array of attributes from elements located by CSS or XPath and retur Resumes test execution, so **should be used inside async with `await`** operator. ```js -let hints = await I.grabAttributeFromAll('.tooltip', 'title') +let hints = await I.grabAttributeFromAll('.tooltip', 'title'); ``` #### Parameters -- `locator` **([string][5] | [object][11])** element located by CSS|XPath|strict locator. -- `attr` **[string][5]** attribute name. +* `locator` **([string][5] | [object][11])** element located by CSS|XPath|strict locator. +* `attr` **[string][5]** attribute name. Returns **[Promise][6]<[Array][8]<[string][5]>>** attribute value @@ -1133,12 +1121,12 @@ Retrieves an array of value from a form located by CSS or XPath and returns it t Resumes test execution, so **should be used inside async function with `await`** operator. ```js -let inputs = await I.grabValueFromAll('//form/input') +let inputs = await I.grabValueFromAll('//form/input'); ``` #### Parameters -- `locator` **([string][5] | [object][11])** field located by label|name|CSS|XPath|strict locator. +* `locator` **([string][5] | [object][11])** field located by label|name|CSS|XPath|strict locator. Returns **[Promise][6]<[Array][8]<[string][5]>>** attribute value @@ -1149,12 +1137,12 @@ Resumes test execution, so **should be used inside async function with `await`** If more than one element is found - value of first element is returned. ```js -let email = await I.grabValueFrom('input[name=email]') +let email = await I.grabValueFrom('input[name=email]'); ``` #### Parameters -- `locator` **([string][5] | [object][11])** field located by label|name|CSS|XPath|strict locator. +* `locator` **([string][5] | [object][11])** field located by label|name|CSS|XPath|strict locator. Returns **[Promise][6]<[string][5]>** attribute value @@ -1164,12 +1152,12 @@ Saves a screenshot to ouput folder (set in codecept.conf.ts or codecept.conf.js) Filename is relative to output folder. ```js -I.saveScreenshot('debug.png') +I.saveScreenshot('debug.png'); ``` #### Parameters -- `fileName` **[string][5]** file name to save. +* `fileName` **[string][5]** file name to save. Returns **[Promise][6]\** @@ -1178,15 +1166,15 @@ Returns **[Promise][6]\** Scroll element into viewport. ```js -I.scrollIntoView('#submit') -I.scrollIntoView('#submit', true) -I.scrollIntoView('#submit', { behavior: 'smooth', block: 'center', inline: 'center' }) +I.scrollIntoView('#submit'); +I.scrollIntoView('#submit', true); +I.scrollIntoView('#submit', { behavior: "smooth", block: "center", inline: "center" }); ``` #### Parameters -- `locator` **([string][5] | [object][11])** located by CSS|XPath|strict locator. -- `scrollIntoViewOptions` **(ScrollIntoViewOptions | [boolean][7])** either alignToTop=true|false or scrollIntoViewOptions. See [https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView][17]. +* `locator` **([string][5] | [object][11])** located by CSS|XPath|strict locator. +* `scrollIntoViewOptions` **(ScrollIntoViewOptions | [boolean][7])** either alignToTop=true|false or scrollIntoViewOptions. See [https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView][17]. Returns **void** automatically synchronized promise through #recorderSupported only for web testing @@ -1195,14 +1183,14 @@ Returns **void** automatically synchronized promise through #recorderSupported o Verifies that the specified checkbox is checked. ```js -I.seeCheckboxIsChecked('Agree') -I.seeCheckboxIsChecked('#agree') // I suppose user agreed to terms -I.seeCheckboxIsChecked({ css: '#signup_form input[type=checkbox]' }) +I.seeCheckboxIsChecked('Agree'); +I.seeCheckboxIsChecked('#agree'); // I suppose user agreed to terms +I.seeCheckboxIsChecked({css: '#signup_form input[type=checkbox]'}); ``` #### Parameters -- `field` **([string][5] | [object][11])** located by label|name|CSS|XPath|strict locator. +* `field` **([string][5] | [object][11])** located by label|name|CSS|XPath|strict locator. Returns **void** automatically synchronized promise through #recorder @@ -1212,12 +1200,12 @@ Checks that a given Element is visible Element is located by CSS or XPath. ```js -I.seeElement('#modal') +I.seeElement('#modal'); ``` #### Parameters -- `locator` **([string][5] | [object][11])** located by CSS|XPath|strict locator. +* `locator` **([string][5] | [object][11])** located by CSS|XPath|strict locator. Returns **void** automatically synchronized promise through #recorder @@ -1227,16 +1215,16 @@ Checks that the given input field or textarea equals to given value. For fuzzy locators, fields are matched by label text, the "name" attribute, CSS, and XPath. ```js -I.seeInField('Username', 'davert') -I.seeInField({ css: 'form textarea' }, 'Type your comment here') -I.seeInField('form input[type=hidden]', 'hidden_value') -I.seeInField('#searchform input', 'Search') +I.seeInField('Username', 'davert'); +I.seeInField({css: 'form textarea'},'Type your comment here'); +I.seeInField('form input[type=hidden]','hidden_value'); +I.seeInField('#searchform input','Search'); ``` #### Parameters -- `field` **([string][5] | [object][11])** located by label|name|CSS|XPath|strict locator. -- `value` **([string][5] | [object][11])** value to check. +* `field` **([string][5] | [object][11])** located by label|name|CSS|XPath|strict locator. +* `value` **([string][5] | [object][11])** value to check. Returns **void** automatically synchronized promise through #recorder @@ -1246,15 +1234,15 @@ Checks that a page contains a visible text. Use context parameter to narrow down the search. ```js -I.see('Welcome') // text welcome on a page -I.see('Welcome', '.content') // text inside .content div -I.see('Register', { css: 'form.register' }) // use strict locator +I.see('Welcome'); // text welcome on a page +I.see('Welcome', '.content'); // text inside .content div +I.see('Register', {css: 'form.register'}); // use strict locator ``` #### Parameters -- `text` **[string][5]** expected on page. -- `context` **([string][5]? | [object][11])** (optional, `null` by default) element located by CSS|Xpath|strict locator in which to search for text. (optional, default `null`) +* `text` **[string][5]** expected on page. +* `context` **([string][5]? | [object][11])** (optional, `null` by default) element located by CSS|Xpath|strict locator in which to search for text. (optional, default `null`) Returns **void** automatically synchronized promise through #recorder @@ -1265,24 +1253,24 @@ Field is searched by label | name | CSS | XPath. Option is selected by visible text or by value. ```js -I.selectOption('Choose Plan', 'Monthly') // select by label -I.selectOption('subscription', 'Monthly') // match option by text -I.selectOption('subscription', '0') // or by value -I.selectOption('//form/select[@name=account]', 'Premium') -I.selectOption('form select[name=account]', 'Premium') -I.selectOption({ css: 'form select[name=account]' }, 'Premium') +I.selectOption('Choose Plan', 'Monthly'); // select by label +I.selectOption('subscription', 'Monthly'); // match option by text +I.selectOption('subscription', '0'); // or by value +I.selectOption('//form/select[@name=account]','Premium'); +I.selectOption('form select[name=account]', 'Premium'); +I.selectOption({css: 'form select[name=account]'}, 'Premium'); ``` Provide an array for the second argument to select multiple options. ```js -I.selectOption('Which OS do you use?', ['Android', 'iOS']) +I.selectOption('Which OS do you use?', ['Android', 'iOS']); ``` #### Parameters -- `select` **([string][5] | [object][11])** field located by label|name|CSS|XPath|strict locator. -- `option` **([string][5] | [Array][8]\)** visible text or value of option. +* `select` **([string][5] | [object][11])** field located by label|name|CSS|XPath|strict locator. +* `option` **([string][5] | [Array][8]\)** visible text or value of option. Returns **void** automatically synchronized promise through #recorderSupported only for web testing @@ -1292,14 +1280,14 @@ Waits for element to be present on page (by default waits for 1sec). Element can be located by CSS or XPath. ```js -I.waitForElement('.btn.continue') -I.waitForElement('.btn.continue', 5) // wait for 5 secs +I.waitForElement('.btn.continue'); +I.waitForElement('.btn.continue', 5); // wait for 5 secs ``` #### Parameters -- `locator` **([string][5] | [object][11])** element located by CSS|XPath|strict locator. -- `sec` **[number][10]?** (optional, `1` by default) time in seconds to wait (optional, default `null`) +* `locator` **([string][5] | [object][11])** element located by CSS|XPath|strict locator. +* `sec` **[number][10]?** (optional, `1` by default) time in seconds to wait (optional, default `null`) Returns **void** automatically synchronized promise through #recorder @@ -1309,13 +1297,13 @@ Waits for an element to become visible on a page (by default waits for 1sec). Element can be located by CSS or XPath. ```js -I.waitForVisible('#popup') +I.waitForVisible('#popup'); ``` #### Parameters -- `locator` **([string][5] | [object][11])** element located by CSS|XPath|strict locator. -- `sec` **[number][10]** (optional, `1` by default) time in seconds to wait (optional, default `1`) +* `locator` **([string][5] | [object][11])** element located by CSS|XPath|strict locator. +* `sec` **[number][10]** (optional, `1` by default) time in seconds to wait (optional, default `1`) Returns **void** automatically synchronized promise through #recorder @@ -1325,13 +1313,13 @@ Waits for an element to be removed or become invisible on a page (by default wai Element can be located by CSS or XPath. ```js -I.waitForInvisible('#popup') +I.waitForInvisible('#popup'); ``` #### Parameters -- `locator` **([string][5] | [object][11])** element located by CSS|XPath|strict locator. -- `sec` **[number][10]** (optional, `1` by default) time in seconds to wait (optional, default `1`) +* `locator` **([string][5] | [object][11])** element located by CSS|XPath|strict locator. +* `sec` **[number][10]** (optional, `1` by default) time in seconds to wait (optional, default `1`) Returns **void** automatically synchronized promise through #recorder @@ -1342,32 +1330,48 @@ Element can be located by CSS or XPath. Narrow down search results by providing context. ```js -I.waitForText('Thank you, form has been submitted') -I.waitForText('Thank you, form has been submitted', 5, '#modal') +I.waitForText('Thank you, form has been submitted'); +I.waitForText('Thank you, form has been submitted', 5, '#modal'); ``` #### Parameters -- `text` **[string][5]** to wait for. -- `sec` **[number][10]** (optional, `1` by default) time in seconds to wait (optional, default `1`) -- `context` **([string][5] | [object][11])?** (optional) element located by CSS|XPath|strict locator. (optional, default `null`) +* `text` **[string][5]** to wait for. +* `sec` **[number][10]** (optional, `1` by default) time in seconds to wait (optional, default `1`) +* `context` **([string][5] | [object][11])?** (optional) element located by CSS|XPath|strict locator. (optional, default `null`) Returns **void** automatically synchronized promise through #recorder [1]: http://codecept.io/helpers/WebDriver/ + [2]: https://appium.io/docs/en/2.1/ + [3]: https://codecept.io/mobile/#setting-up + [4]: https://github.com/appium/appium/blob/master/packages/appium/docs/en/guides/caps.md + [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String + [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise + [7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean + [8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array + [9]: https://webdriver.io/docs/api/chromium/#setnetworkconnection + [10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number + [11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object + [12]: https://developer.android.com/reference/android/view/KeyEvent.html + [13]: http://webdriver.io/api/mobile/touchAction.html + [14]: http://webdriver.io/api/mobile/swipe.html + [15]: http://webdriver.io/api/mobile/rotate.html + [16]: http://webdriver.io/api/mobile/setImmediateValue.html + [17]: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView diff --git a/docs/helpers/Detox.md b/docs/helpers/Detox.md index bfe37c6aa..4d5c46204 100644 --- a/docs/helpers/Detox.md +++ b/docs/helpers/Detox.md @@ -6,6 +6,7 @@ title: Detox # Detox + ## Detox @@ -80,15 +81,15 @@ It's important to specify a package name under `require` section and current det Options: -- `configuration` - a detox configuration name. Required. -- `reloadReactNative` - should be enabled for React Native applications. -- `reuse` - reuse application for tests. By default, Detox reinstalls and relaunches app. -- `registerGlobals` - (default: true) Register Detox helper functions `by`, `element`, `expect`, `waitFor` globally. -- `url` - URL to open via deep-link each time the app is launched (android) or immediately afterwards (iOS). Useful for opening a bundle URL at the beginning of tests when working with Expo. +* `configuration` - a detox configuration name. Required. +* `reloadReactNative` - should be enabled for React Native applications. +* `reuse` - reuse application for tests. By default, Detox reinstalls and relaunches app. +* `registerGlobals` - (default: true) Register Detox helper functions `by`, `element`, `expect`, `waitFor` globally. +* `url` - URL to open via deep-link each time the app is launched (android) or immediately afterwards (iOS). Useful for opening a bundle URL at the beginning of tests when working with Expo. ### Parameters -- `config` +* `config` ### appendField @@ -96,27 +97,27 @@ Appends text into the field. A field can be located by text, accessibility id, id. ```js -I.appendField('name', 'davert') +I.appendField('name', 'davert'); ``` #### Parameters -- `field` **([string][5] | [object][6])** -- `value` **[string][5]** +* `field` **([string][5] | [object][6])** +* `value` **[string][5]** ### checkIfElementExists Checks if an element exists. ```js -I.checkIfElementExists('~edit') // located by accessibility id -I.checkIfElementExists('~edit', '#menu') // element inside #menu +I.checkIfElementExists('~edit'); // located by accessibility id +I.checkIfElementExists('~edit', '#menu'); // element inside #menu ``` #### Parameters -- `locator` **([string][5] | [object][6])** element to locate -- `context` **([string][5] | [object][6] | null)** context element (optional, default `null`) +* `locator` **([string][5] | [object][6])** element to locate +* `context` **([string][5] | [object][6] | null)** context element (optional, default `null`) ### clearField @@ -124,12 +125,12 @@ Clears a text field. A field can be located by text, accessibility id, id. ```js -I.clearField('~name') +I.clearField('~name'); ``` #### Parameters -- `field` **([string][5] | [object][6])** an input element to clear +* `field` **([string][5] | [object][6])** an input element to clear ### click @@ -141,17 +142,17 @@ The second parameter is a context (id | type | accessibility id) to narrow the s Same as [tap][7] ```js -I.click('Login') // locate by text -I.click('~nav-1') // locate by accessibility label -I.click('#user') // locate by id -I.click('Login', '#nav') // locate by text inside #nav -I.click({ ios: 'Save', android: 'SAVE' }, '#main') // different texts on iOS and Android +I.click('Login'); // locate by text +I.click('~nav-1'); // locate by accessibility label +I.click('#user'); // locate by id +I.click('Login', '#nav'); // locate by text inside #nav +I.click({ ios: 'Save', android: 'SAVE' }, '#main'); // different texts on iOS and Android ``` #### Parameters -- `locator` **([string][5] | [object][6])** -- `context` **([string][5] | [object][6] | null)** (optional, default `null`) +* `locator` **([string][5] | [object][6])** +* `context` **([string][5] | [object][6] | null)** (optional, default `null`) ### clickAtPoint @@ -159,15 +160,15 @@ Performs click on element with horizontal and vertical offset. An element is located by text, id, accessibility id. ```js -I.clickAtPoint('Save', 10, 10) -I.clickAtPoint('~save', 10, 10) // locate by accessibility id +I.clickAtPoint('Save', 10, 10); +I.clickAtPoint('~save', 10, 10); // locate by accessibility id ``` #### Parameters -- `locator` **([string][5] | [object][6])** -- `x` **[number][8]** horizontal offset (optional, default `0`) -- `y` **[number][8]** vertical offset (optional, default `0`) +* `locator` **([string][5] | [object][6])** +* `x` **[number][8]** horizontal offset (optional, default `0`) +* `y` **[number][8]** vertical offset (optional, default `0`) ### dontSee @@ -175,15 +176,15 @@ Checks text not to be visible. Use second parameter to narrow down the search. ```js -I.dontSee('Record created') -I.dontSee('Record updated', '#message') -I.dontSee('Record deleted', '~message') +I.dontSee('Record created'); +I.dontSee('Record updated', '#message'); +I.dontSee('Record deleted', '~message'); ``` #### Parameters -- `text` **[string][5]** to check invisibility -- `context` **([string][5] | [object][6] | null)** element in which to search for text (optional, default `null`) +* `text` **[string][5]** to check invisibility +* `context` **([string][5] | [object][6] | null)** element in which to search for text (optional, default `null`) ### dontSeeElement @@ -191,14 +192,14 @@ Checks that element is not visible. Use second parameter to narrow down the search. ```js -I.dontSeeElement('~edit') // located by accessibility id -I.dontSeeElement('~edit', '#menu') // element inside #menu +I.dontSeeElement('~edit'); // located by accessibility id +I.dontSeeElement('~edit', '#menu'); // element inside #menu ``` #### Parameters -- `locator` **([string][5] | [object][6])** element to locate -- `context` **([string][5] | [object][6] | null)** context element (optional, default `null`) +* `locator` **([string][5] | [object][6])** element to locate +* `context` **([string][5] | [object][6] | null)** context element (optional, default `null`) ### dontSeeElementExists @@ -206,14 +207,14 @@ Checks that element not exists. Use second parameter to narrow down the search. ```js -I.dontSeeElementExist('~edit') // located by accessibility id -I.dontSeeElementExist('~edit', '#menu') // element inside #menu +I.dontSeeElementExist('~edit'); // located by accessibility id +I.dontSeeElementExist('~edit', '#menu'); // element inside #menu ``` #### Parameters -- `locator` **([string][5] | [object][6])** element to locate -- `context` **([string][5] | [object][6])** context element (optional, default `null`) +* `locator` **([string][5] | [object][6])** element to locate +* `context` **([string][5] | [object][6])** context element (optional, default `null`) ### fillField @@ -221,22 +222,22 @@ Fills in text field in an app. A field can be located by text, accessibility id, id. ```js -I.fillField('Username', 'davert') -I.fillField('~name', 'davert') -I.fillField({ android: 'NAME', ios: 'name' }, 'davert') +I.fillField('Username', 'davert'); +I.fillField('~name', 'davert'); +I.fillField({ android: 'NAME', ios: 'name' }, 'davert'); ``` #### Parameters -- `field` **([string][5] | [object][6])** an input element to fill in -- `value` **[string][5]** value to fill +* `field` **([string][5] | [object][6])** an input element to fill in +* `value` **[string][5]** value to fill ### goBack Goes back on Android ```js -I.goBack() // on Android only +I.goBack(); // on Android only ``` ### grabPlatform @@ -244,7 +245,7 @@ I.goBack() // on Android only Grab the device platform ```js -const platform = await I.grabPlatform() +const platform = await I.grabPlatform(); ``` ### installApp @@ -253,7 +254,7 @@ Installs a configured application. Application is installed by default. ```js -I.installApp() +I.installApp(); ``` ### launchApp @@ -261,7 +262,7 @@ I.installApp() Launches an application. If application instance already exists, use [relaunchApp][9]. ```js -I.launchApp() +I.launchApp(); ``` ### longPress @@ -269,16 +270,16 @@ I.launchApp() Taps an element and holds for a requested time. ```js -I.longPress('Login', 2) // locate by text, hold for 2 seconds -I.longPress('~nav', 1) // locate by accessibility label, hold for second -I.longPress('Update', 2, '#menu') // locate by text inside #menu, hold for 2 seconds +I.longPress('Login', 2); // locate by text, hold for 2 seconds +I.longPress('~nav', 1); // locate by accessibility label, hold for second +I.longPress('Update', 2, '#menu'); // locate by text inside #menu, hold for 2 seconds ``` #### Parameters -- `locator` **([string][5] | [object][6])** element to locate -- `sec` **[number][8]** number of seconds to hold tap -- `context` **([string][5] | [object][6] | null)** context element (optional, default `null`) +* `locator` **([string][5] | [object][6])** element to locate +* `sec` **[number][8]** number of seconds to hold tap +* `context` **([string][5] | [object][6] | null)** context element (optional, default `null`) ### multiTap @@ -289,24 +290,24 @@ Set the number of taps in second argument. Optionally define the context element by third argument. ```js -I.multiTap('Login', 2) // locate by text -I.multiTap('~nav', 2) // locate by accessibility label -I.multiTap('#user', 2) // locate by id -I.multiTap('Update', 2, '#menu') // locate by id +I.multiTap('Login', 2); // locate by text +I.multiTap('~nav', 2); // locate by accessibility label +I.multiTap('#user', 2); // locate by id +I.multiTap('Update', 2, '#menu'); // locate by id ``` #### Parameters -- `locator` **([string][5] | [object][6])** element to locate -- `num` **[number][8]** number of taps -- `context` **([string][5] | [object][6] | null)** context element (optional, default `null`) +* `locator` **([string][5] | [object][6])** element to locate +* `num` **[number][8]** number of taps +* `context` **([string][5] | [object][6] | null)** context element (optional, default `null`) ### relaunchApp Relaunches an application. ```js -I.relaunchApp() +I.relaunchApp(); ``` ### runOnAndroid @@ -315,14 +316,14 @@ Execute code only on Android ```js I.runOnAndroid(() => { - I.click('Button') - I.see('Hi, Android') -}) + I.click('Button'); + I.see('Hi, Android'); +}); ``` #### Parameters -- `fn` **[Function][10]** a function which will be executed on android +* `fn` **[Function][10]** a function which will be executed on android ### runOnIOS @@ -330,62 +331,62 @@ Execute code only on iOS ```js I.runOnIOS(() => { - I.click('Button') - I.see('Hi, IOS') -}) + I.click('Button'); + I.see('Hi, IOS'); +}); ``` #### Parameters -- `fn` **[Function][10]** a function which will be executed on iOS +* `fn` **[Function][10]** a function which will be executed on iOS ### saveScreenshot Saves a screenshot to the output dir ```js -I.saveScreenshot('main-window.png') +I.saveScreenshot('main-window.png'); ``` #### Parameters -- `name` **[string][5]** +* `name` **[string][5]** ### scrollDown Scrolls to the bottom of an element. ```js -I.scrollDown('#container') +I.scrollDown('#container'); ``` #### Parameters -- `locator` **([string][5] | [object][6])** +* `locator` **([string][5] | [object][6])** ### scrollLeft Scrolls to the left of an element. ```js -I.scrollLeft('#container') +I.scrollLeft('#container'); ``` #### Parameters -- `locator` **([string][5] | [object][6])** +* `locator` **([string][5] | [object][6])** ### scrollRight Scrolls to the right of an element. ```js -I.scrollRight('#container') +I.scrollRight('#container'); ``` #### Parameters -- `locator` **([string][5] | [object][6])** +* `locator` **([string][5] | [object][6])** ### scrollToElement @@ -393,22 +394,22 @@ Scrolls within a scrollable container to an element. #### Parameters -- `targetLocator` **([string][5] | [object][6])** Locator of the element to scroll to -- `containerLocator` **([string][5] | [object][6])** Locator of the scrollable container -- `direction` **[string][5]** 'up' or 'down' (optional, default `'down'`) -- `offset` **[number][8]** Offset for scroll, can be adjusted based on need (optional, default `100`) +* `targetLocator` **([string][5] | [object][6])** Locator of the element to scroll to +* `containerLocator` **([string][5] | [object][6])** Locator of the scrollable container +* `direction` **[string][5]** 'up' or 'down' (optional, default `'down'`) +* `offset` **[number][8]** Offset for scroll, can be adjusted based on need (optional, default `100`) ### scrollUp Scrolls to the top of an element. ```js -I.scrollUp('#container') +I.scrollUp('#container'); ``` #### Parameters -- `locator` **([string][5] | [object][6])** +* `locator` **([string][5] | [object][6])** ### see @@ -416,15 +417,15 @@ Checks text to be visible. Use second parameter to narrow down the search. ```js -I.see('Record created') -I.see('Record updated', '#message') -I.see('Record deleted', '~message') +I.see('Record created'); +I.see('Record updated', '#message'); +I.see('Record deleted', '~message'); ``` #### Parameters -- `text` **[string][5]** to check visibility -- `context` **([string][5] | [object][6] | null)** element inside which to search for text (optional, default `null`) +* `text` **[string][5]** to check visibility +* `context` **([string][5] | [object][6] | null)** element inside which to search for text (optional, default `null`) ### seeElement @@ -432,14 +433,14 @@ Checks for visibility of an element. Use second parameter to narrow down the search. ```js -I.seeElement('~edit') // located by accessibility id -I.seeElement('~edit', '#menu') // element inside #menu +I.seeElement('~edit'); // located by accessibility id +I.seeElement('~edit', '#menu'); // element inside #menu ``` #### Parameters -- `locator` **([string][5] | [object][6])** element to locate -- `context` **([string][5] | [object][6] | null)** context element (optional, default `null`) +* `locator` **([string][5] | [object][6])** element to locate +* `context` **([string][5] | [object][6] | null)** context element (optional, default `null`) ### seeElementExists @@ -447,21 +448,21 @@ Checks for existence of an element. An element can be visible or not. Use second parameter to narrow down the search. ```js -I.seeElementExists('~edit') // located by accessibility id -I.seeElementExists('~edit', '#menu') // element inside #menu +I.seeElementExists('~edit'); // located by accessibility id +I.seeElementExists('~edit', '#menu'); // element inside #menu ``` #### Parameters -- `locator` **([string][5] | [object][6])** element to locate -- `context` **([string][5] | [object][6])** context element (optional, default `null`) +* `locator` **([string][5] | [object][6])** element to locate +* `context` **([string][5] | [object][6])** context element (optional, default `null`) ### setLandscapeOrientation Switches device to landscape orientation ```js -I.setLandscapeOrientation() +I.setLandscapeOrientation(); ``` ### setPortraitOrientation @@ -469,7 +470,7 @@ I.setLandscapeOrientation() Switches device to portrait orientation ```js -I.setPortraitOrientation() +I.setPortraitOrientation(); ``` ### shakeDevice @@ -477,7 +478,7 @@ I.setPortraitOrientation() Shakes the device. ```js -I.shakeDevice() +I.shakeDevice(); ``` ### swipeDown @@ -486,13 +487,13 @@ Performs a swipe up inside an element. Can be `slow` or `fast` swipe. ```js -I.swipeUp('#container') +I.swipeUp('#container'); ``` #### Parameters -- `locator` **([string][5] | [object][6])** an element on which to perform swipe -- `speed` **[string][5]** a speed to perform: `slow` or `fast`. (optional, default `'slow'`) +* `locator` **([string][5] | [object][6])** an element on which to perform swipe +* `speed` **[string][5]** a speed to perform: `slow` or `fast`. (optional, default `'slow'`) ### swipeLeft @@ -500,13 +501,13 @@ Performs a swipe up inside an element. Can be `slow` or `fast` swipe. ```js -I.swipeUp('#container') +I.swipeUp('#container'); ``` #### Parameters -- `locator` **([string][5] | [object][6])** an element on which to perform swipe -- `speed` **[string][5]** a speed to perform: `slow` or `fast`. (optional, default `'slow'`) +* `locator` **([string][5] | [object][6])** an element on which to perform swipe +* `speed` **[string][5]** a speed to perform: `slow` or `fast`. (optional, default `'slow'`) ### swipeRight @@ -514,13 +515,13 @@ Performs a swipe up inside an element. Can be `slow` or `fast` swipe. ```js -I.swipeUp('#container') +I.swipeUp('#container'); ``` #### Parameters -- `locator` **([string][5] | [object][6])** an element on which to perform swipe -- `speed` **[string][5]** a speed to perform: `slow` or `fast`. (optional, default `'slow'`) +* `locator` **([string][5] | [object][6])** an element on which to perform swipe +* `speed` **[string][5]** a speed to perform: `slow` or `fast`. (optional, default `'slow'`) ### swipeUp @@ -528,13 +529,13 @@ Performs a swipe up inside an element. Can be `slow` or `fast` swipe. ```js -I.swipeUp('#container') +I.swipeUp('#container'); ``` #### Parameters -- `locator` **([string][5] | [object][6])** an element on which to perform swipe -- `speed` **[string][5]** a speed to perform: `slow` or `fast`. (optional, default `'slow'`) +* `locator` **([string][5] | [object][6])** an element on which to perform swipe +* `speed` **[string][5]** a speed to perform: `slow` or `fast`. (optional, default `'slow'`) ### tap @@ -546,17 +547,17 @@ The second parameter is a context element to narrow the search. Same as [click][11] ```js -I.tap('Login') // locate by text -I.tap('~nav-1') // locate by accessibility label -I.tap('#user') // locate by id -I.tap('Login', '#nav') // locate by text inside #nav -I.tap({ ios: 'Save', android: 'SAVE' }, '#main') // different texts on iOS and Android +I.tap('Login'); // locate by text +I.tap('~nav-1'); // locate by accessibility label +I.tap('#user'); // locate by id +I.tap('Login', '#nav'); // locate by text inside #nav +I.tap({ ios: 'Save', android: 'SAVE' }, '#main'); // different texts on iOS and Android ``` #### Parameters -- `locator` **([string][5] | [object][6])** -- `context` **([string][5] | [object][6] | null)** (optional, default `null`) +* `locator` **([string][5] | [object][6])** +* `context` **([string][5] | [object][6] | null)** (optional, default `null`) ### tapByLabel @@ -566,14 +567,14 @@ Element can be located by its label The second parameter is a context (id | type | accessibility id) to narrow the search. ```js -I.tapByLabel('Login') // locate by text -I.tapByLabel('Login', '#nav') // locate by text inside #nav +I.tapByLabel('Login'); // locate by text +I.tapByLabel('Login', '#nav'); // locate by text inside #nav ``` #### Parameters -- `locator` **([string][5] | [object][6])** -- `context` **([string][5] | [object][6] | null)** (optional, default `null`) +* `locator` **([string][5] | [object][6])** +* `context` **([string][5] | [object][6] | null)** (optional, default `null`) ### tapReturnKey @@ -581,74 +582,84 @@ Taps return key. A field can be located by text, accessibility id, id. ```js -I.tapReturnKey('Username') -I.tapReturnKey('~name') -I.tapReturnKey({ android: 'NAME', ios: 'name' }) +I.tapReturnKey('Username'); +I.tapReturnKey('~name'); +I.tapReturnKey({ android: 'NAME', ios: 'name' }); ``` #### Parameters -- `field` **([string][5] | [object][6])** an input element to fill in +* `field` **([string][5] | [object][6])** an input element to fill in ### wait Waits for number of seconds ```js -I.wait(2) // waits for 2 seconds +I.wait(2); // waits for 2 seconds ``` #### Parameters -- `sec` **[number][8]** number of seconds to wait +* `sec` **[number][8]** number of seconds to wait ### waitForElement Waits for an element to exist on page. ```js -I.waitForElement('#message', 1) // wait for 1 second +I.waitForElement('#message', 1); // wait for 1 second ``` #### Parameters -- `locator` **([string][5] | [object][6])** an element to wait for -- `sec` **[number][8]** number of seconds to wait, 5 by default (optional, default `5`) +* `locator` **([string][5] | [object][6])** an element to wait for +* `sec` **[number][8]** number of seconds to wait, 5 by default (optional, default `5`) ### waitForElementVisible Waits for an element to be visible on page. ```js -I.waitForElementVisible('#message', 1) // wait for 1 second +I.waitForElementVisible('#message', 1); // wait for 1 second ``` #### Parameters -- `locator` **([string][5] | [object][6])** an element to wait for -- `sec` **[number][8]** number of seconds to wait (optional, default `5`) +* `locator` **([string][5] | [object][6])** an element to wait for +* `sec` **[number][8]** number of seconds to wait (optional, default `5`) ### waitToHide Waits an elmenet to become not visible. ```js -I.waitToHide('#message', 2) // wait for 2 seconds +I.waitToHide('#message', 2); // wait for 2 seconds ``` #### Parameters -- `locator` **([string][5] | [object][6])** an element to wait for -- `sec` **[number][8]** number of seconds to wait (optional, default `5`) +* `locator` **([string][5] | [object][6])** an element to wait for +* `sec` **[number][8]** number of seconds to wait (optional, default `5`) [1]: https://github.com/wix/Detox + [2]: https://wix.github.io/Detox/docs/introduction/project-setup + [3]: https://wix.github.io/Detox/docs/introduction/project-setup#step-5-build-the-app + [4]: https://codecept.io + [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String + [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object + [7]: #tap + [8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number + [9]: #relaunchApp + [10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function + [11]: #click diff --git a/docs/helpers/FileSystem.md b/docs/helpers/FileSystem.md index d85220a3f..cd3d1351a 100644 --- a/docs/helpers/FileSystem.md +++ b/docs/helpers/FileSystem.md @@ -15,10 +15,10 @@ Helper for testing filesystem. Can be easily used to check file structures: ```js -I.amInPath('test') -I.seeFile('codecept.js') -I.seeInThisFile('FileSystem') -I.dontSeeInThisFile('WebDriver') +I.amInPath('test'); +I.seeFile('codecept.js'); +I.seeInThisFile('FileSystem'); +I.dontSeeInThisFile("WebDriver"); ``` ## Configuration @@ -40,7 +40,7 @@ Starts from a current directory #### Parameters -- `openPath` **[string][1]** +* `openPath` **[string][1]** ### dontSeeFileContentsEqual @@ -48,8 +48,8 @@ Checks that contents of file found by `seeFile` doesn't equal to text. #### Parameters -- `text` **[string][1]** -- `encoding` **[string][1]** +* `text` **[string][1]** +* `encoding` **[string][1]** ### dontSeeInThisFile @@ -57,18 +57,18 @@ Checks that file found by `seeFile` doesn't include text. #### Parameters -- `text` **[string][1]** -- `encoding` **[string][1]** +* `text` **[string][1]** +* `encoding` **[string][1]** ### grabFileNames Returns file names in current directory. ```js -I.handleDownloads() -I.click('Download Files') -I.amInPath('output/downloads') -const downloadedFileNames = I.grabFileNames() +I.handleDownloads(); +I.click('Download Files'); +I.amInPath('output/downloads'); +const downloadedFileNames = I.grabFileNames(); ``` ### seeFile @@ -77,7 +77,7 @@ Checks that file exists #### Parameters -- `name` **[string][1]** +* `name` **[string][1]** ### seeFileContentsEqual @@ -85,8 +85,8 @@ Checks that contents of file found by `seeFile` equal to text. #### Parameters -- `text` **[string][1]** -- `encoding` **[string][1]** +* `text` **[string][1]** +* `encoding` **[string][1]** ### seeFileContentsEqualReferenceFile @@ -94,24 +94,24 @@ Checks that contents of the file found by `seeFile` equal to contents of the fil #### Parameters -- `pathToReferenceFile` **[string][1]** -- `encoding` **[string][1]** -- `encodingReference` **[string][1]** +* `pathToReferenceFile` **[string][1]** +* `encoding` **[string][1]** +* `encodingReference` **[string][1]** ### seeFileNameMatching Checks that file with a name including given text exists in the current directory. ```js -I.handleDownloads() -I.click('Download as PDF') -I.amInPath('output/downloads') -I.seeFileNameMatching('.pdf') +I.handleDownloads(); +I.click('Download as PDF'); +I.amInPath('output/downloads'); +I.seeFileNameMatching('.pdf'); ``` #### Parameters -- `text` **[string][1]** +* `text` **[string][1]** ### seeInThisFile @@ -119,24 +119,24 @@ Checks that file found by `seeFile` includes a text. #### Parameters -- `text` **[string][1]** -- `encoding` **[string][1]** +* `text` **[string][1]** +* `encoding` **[string][1]** ### waitForFile Waits for the file to be present in the current directory. ```js -I.handleDownloads('downloads/largeFilesName.txt') -I.click('Download large File') -I.amInPath('output/downloads') -I.waitForFile('largeFilesName.txt', 10) // wait 10 seconds for file +I.handleDownloads('downloads/largeFilesName.txt'); +I.click('Download large File'); +I.amInPath('output/downloads'); +I.waitForFile('largeFilesName.txt', 10); // wait 10 seconds for file ``` #### Parameters -- `name` **[string][1]** -- `sec` **[number][2]** seconds to wait +* `name` **[string][1]** +* `sec` **[number][2]** seconds to wait ### writeToFile @@ -144,8 +144,9 @@ Writes text to file #### Parameters -- `name` **[string][1]** -- `text` **[string][1]** +* `name` **[string][1]** +* `text` **[string][1]** [1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String + [2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number diff --git a/docs/helpers/GraphQL.md b/docs/helpers/GraphQL.md index 2daed8d04..7aa35c637 100644 --- a/docs/helpers/GraphQL.md +++ b/docs/helpers/GraphQL.md @@ -16,10 +16,10 @@ GraphQL helper allows to send additional requests to a GraphQl endpoint during a ## Configuration -- endpoint: GraphQL base URL -- timeout: timeout for requests in milliseconds. 10000ms by default -- defaultHeaders: a list of default headers -- onRequest: a async function which can update request object. +* endpoint: GraphQL base URL +* timeout: timeout for requests in milliseconds. 10000ms by default +* defaultHeaders: a list of default headers +* onRequest: a async function which can update request object. ## Example @@ -38,33 +38,33 @@ Send GraphQL requests by accessing `_executeQuery` method: ```js this.helpers['GraphQL']._executeQuery({ - url, - data, -}) + url, + data, +}); ``` ## Methods ### Parameters -- `config` +* `config` -### \_executeQuery +### _executeQuery Executes query via axios call #### Parameters -- `request` **[object][2]** +* `request` **[object][2]** -### \_prepareGraphQLRequest +### _prepareGraphQLRequest Prepares request for axios call #### Parameters -- `operation` **[object][2]** -- `headers` **[object][2]** +* `operation` **[object][2]** +* `headers` **[object][2]** Returns **[object][2]** graphQLRequest @@ -79,7 +79,7 @@ I.amBearerAuthenticated(secret('heregoestoken')) #### Parameters -- `accessToken` **([string][3] | CodeceptJS.Secret)** Bearer access token +* `accessToken` **([string][3] | CodeceptJS.Secret)** Bearer access token ### haveRequestHeaders @@ -87,7 +87,7 @@ Sets request headers for all requests of this test #### Parameters -- `headers` **[object][2]** headers list +* `headers` **[object][2]** headers list ### sendMutation @@ -113,10 +113,10 @@ I.sendMutation(` #### Parameters -- `mutation` **[String][3]** -- `variables` **[object][2]?** that may go along with the mutation -- `options` **[object][2]?** are additional query options -- `headers` **[object][2]?** +* `mutation` **[String][3]** +* `variables` **[object][2]?** that may go along with the mutation +* `options` **[object][2]?** are additional query options +* `headers` **[object][2]?** Returns **any** Promise @@ -126,21 +126,27 @@ Send query to GraphQL endpoint over http. Returns a response as a promise. ```js -const response = await I.sendQuery('{ users { name email }}') + +const response = await I.sendQuery('{ users { name email }}'); // with variables -const response = await I.sendQuery('query getUser($id: ID) { user(id: $id) { name email }}', { id: 1 }) -const user = response.data.data +const response = await I.sendQuery( + 'query getUser($id: ID) { user(id: $id) { name email }}', + { id: 1 }, +) +const user = response.data.data; ``` #### Parameters -- `query` **[String][3]** -- `variables` **[object][2]?** that may go along with the query -- `options` **[object][2]?** are additional query options -- `headers` **[object][2]?** +* `query` **[String][3]** +* `variables` **[object][2]?** that may go along with the query +* `options` **[object][2]?** are additional query options +* `headers` **[object][2]?** Returns **any** Promise [1]: https://github.com/axios/axios + [2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object + [3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String diff --git a/docs/helpers/GraphQLDataFactory.md b/docs/helpers/GraphQLDataFactory.md index 6d1370ebb..277cf2cd6 100644 --- a/docs/helpers/GraphQLDataFactory.md +++ b/docs/helpers/GraphQLDataFactory.md @@ -28,9 +28,9 @@ If a web application has GraphQL support, it can be used to create and delete te By combining GraphQL with Factories you can easily create records for tests: ```js -I.mutateData('createUser', { name: 'davert', email: 'davert@mail.com' }) -let user = await I.mutateData('createUser', { name: 'davert' }) -I.mutateMultiple('createPost', 3, { post_id: user.id }) +I.mutateData('createUser', { name: 'davert', email: 'davert@mail.com' }); +let user = await I.mutateData('createUser', { name: 'davert'}); +I.mutateMultiple('createPost', 3, {post_id: user.id}); ``` To make this work you need @@ -53,17 +53,17 @@ See the example for Users factories: ```js // tests/factories/users.js -const { Factory } = require('rosie').Factory -const { faker } = require('@faker-js/faker') +const { Factory } = require('rosie').Factory; +const { faker } = require('@faker-js/faker'); // Used with a constructor function passed to Factory, so that the final build // object matches the necessary pattern to be sent as the variables object. -module.exports = new Factory(buildObj => ({ - input: { ...buildObj }, +module.exports = new Factory((buildObj) => ({ + input: { ...buildObj }, })) - // 'attr'-id can be left out depending on the GraphQl resolvers - .attr('name', () => faker.person.findName()) - .attr('email', () => faker.interact.email()) + // 'attr'-id can be left out depending on the GraphQl resolvers + .attr('name', () => faker.person.findName()) + .attr('email', () => faker.interact.email()) ``` For more options see [rosie documentation][1]. @@ -74,11 +74,11 @@ Then configure GraphQLDataHelper to match factories and GraphQL schema: GraphQLDataFactory has following config options: -- `endpoint`: URL for the GraphQL server. -- `cleanup` (default: true): should inserted records be deleted up after tests -- `factories`: list of defined factories -- `headers`: list of headers -- `GraphQL`: configuration for GraphQL requests. +* `endpoint`: URL for the GraphQL server. +* `cleanup` (default: true): should inserted records be deleted up after tests +* `factories`: list of defined factories +* `headers`: list of headers +* `GraphQL`: configuration for GraphQL requests. See the example: @@ -121,27 +121,27 @@ For instance, to set timeout you should add: Factory contains operations - -- `operation`: The operation/mutation that needs to be performed for creating a record in the backend. +* `operation`: The operation/mutation that needs to be performed for creating a record in the backend. Each operation must have the following: -- `query`: The mutation(query) string. It is expected to use variables to send data with the query. -- `factory`: The path to factory file. The object built by the factory in this file will be passed - as the 'variables' object to go along with the mutation. -- `revert`: A function called with the data returned when an item is created. The object returned by - this function is will be used to later delete the items created. So, make sure RELEVANT DATA IS RETURNED - when a record is created by a mutation. +* `query`: The mutation(query) string. It is expected to use variables to send data with the query. +* `factory`: The path to factory file. The object built by the factory in this file will be passed + as the 'variables' object to go along with the mutation. +* `revert`: A function called with the data returned when an item is created. The object returned by + this function is will be used to later delete the items created. So, make sure RELEVANT DATA IS RETURNED + when a record is created by a mutation. ### Requests Requests can be updated on the fly by using `onRequest` function. For instance, you can pass in current session from a cookie. ```js -onRequest: async request => { - // using global codeceptjs instance - let cookie = await codeceptjs.container.helpers('WebDriver').grabCookie('session') - request.headers = { Cookie: `session=${cookie.value}` } -} + onRequest: async (request) => { + // using global codeceptjs instance + let cookie = await codeceptjs.container.helpers('WebDriver').grabCookie('session'); + request.headers = { Cookie: `session=${cookie.value}` }; + } ``` ### Responses @@ -149,7 +149,7 @@ onRequest: async request => { By default `I.mutateData()` returns a promise with created data as specified in operation query string: ```js -let client = await I.mutateData('createClient') +let client = await I.mutateData('createClient'); ``` Data of created records are collected and used in the end of a test for the cleanup. @@ -158,27 +158,27 @@ Data of created records are collected and used in the end of a test for the clea ### Parameters -- `config` +* `config` -### \_requestCreate +### _requestCreate Executes request to create a record to the GraphQL endpoint. Can be replaced from a custom helper. #### Parameters -- `operation` **[string][4]** -- `variables` **any** to be sent along with the query +* `operation` **[string][4]** +* `variables` **any** to be sent along with the query -### \_requestDelete +### _requestDelete Executes request to delete a record to the GraphQL endpoint. Can be replaced from a custom helper. #### Parameters -- `operation` **[string][4]** -- `data` **any** of the record to be deleted. +* `operation` **[string][4]** +* `data` **any** of the record to be deleted. ### mutateData @@ -186,16 +186,16 @@ Generates a new record using factory, sends a GraphQL mutation to store it. ```js // create a user -I.mutateData('createUser') +I.mutateData('createUser'); // create user with defined email // and receive it when inside async function -const user = await I.mutateData('createUser', { email: 'user@user.com' }) +const user = await I.mutateData('createUser', { email: 'user@user.com'}); ``` #### Parameters -- `operation` **[string][4]** to be performed -- `params` **any** predefined parameters +* `operation` **[string][4]** to be performed +* `params` **any** predefined parameters ### mutateMultiple @@ -203,20 +203,24 @@ Generates bunch of records and sends multiple GraphQL mutation requests to store ```js // create 3 users -I.mutateMultiple('createUser', 3) +I.mutateMultiple('createUser', 3); // create 3 users of same age -I.mutateMultiple('createUser', 3, { age: 25 }) +I.mutateMultiple('createUser', 3, { age: 25 }); ``` #### Parameters -- `operation` **[string][4]** -- `times` **[number][5]** -- `params` **any** +* `operation` **[string][4]** +* `times` **[number][5]** +* `params` **any** [1]: https://github.com/rosiejs/rosie + [2]: https://www.npmjs.com/package/faker + [3]: http://codecept.io/helpers/GraphQL/ + [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String + [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number diff --git a/docs/helpers/JSONResponse.md b/docs/helpers/JSONResponse.md index c29de46a9..e9c12ca9c 100644 --- a/docs/helpers/JSONResponse.md +++ b/docs/helpers/JSONResponse.md @@ -13,15 +13,15 @@ title: JSONResponse This helper allows performing assertions on JSON responses paired with following helpers: -- REST -- GraphQL -- Playwright +* REST +* GraphQL +* Playwright It can check status codes, response data, response structure. ## Configuration -- `requestHelper` - a helper which will perform requests. `REST` by default, also `Playwright` or `GraphQL` can be used. Custom helpers must have `onResponse` hook in their config, which will be executed when request is performed. +* `requestHelper` - a helper which will perform requests. `REST` by default, also `Playwright` or `GraphQL` can be used. Custom helpers must have `onResponse` hook in their config, which will be executed when request is performed. ### Examples @@ -61,26 +61,26 @@ If you plan to add custom assertions it is recommended to create a helper that w ```js // inside custom helper -const response = this.helpers.JSONResponse.response +const response = this.helpers.JSONResponse.response; ``` ## Methods ### Parameters -- `config` +* `config` ### dontSeeResponseCodeIs Checks that response code is not equal to the provided one ```js -I.dontSeeResponseCodeIs(500) +I.dontSeeResponseCodeIs(500); ``` #### Parameters -- `code` **[number][1]** +* `code` **[number][1]** ### dontSeeResponseContainsJson @@ -89,7 +89,7 @@ Checks for deep inclusion of a provided json in a response data. ```js // response.data == { data: { user: 1 } } -I.dontSeeResponseContainsJson({ user: 2 }) +I.dontSeeResponseContainsJson({ user: 2 }); ``` If an array is received, checks that no element of array contains json: @@ -97,24 +97,24 @@ If an array is received, checks that no element of array contains json: ```js // response.data == [{ user: 1 }, { user: 3 }] -I.dontSeeResponseContainsJson({ user: 2 }) +I.dontSeeResponseContainsJson({ user: 2 }); ``` #### Parameters -- `json` **[object][2]** +* `json` **[object][2]** ### seeResponseCodeIs Checks that response code is equal to the provided one ```js -I.seeResponseCodeIs(200) +I.seeResponseCodeIs(200); ``` #### Parameters -- `code` **[number][1]** +* `code` **[number][1]** ### seeResponseCodeIsClientError @@ -134,7 +134,7 @@ Checks that the response code is 2xx Use it instead of seeResponseCodeIs(200) if server can return 204 instead. ```js -I.seeResponseCodeIsSuccessful() +I.seeResponseCodeIsSuccessful(); ``` ### seeResponseContainsJson @@ -144,7 +144,7 @@ Checks for deep inclusion of a provided json in a response data. ```js // response.data == { user: { name: 'jon', email: 'jon@doe.com' } } -I.seeResponseContainsJson({ user: { email: 'jon@doe.com' } }) +I.seeResponseContainsJson({ user: { email: 'jon@doe.com' } }); ``` If an array is received, checks that at least one element contains JSON @@ -152,12 +152,12 @@ If an array is received, checks that at least one element contains JSON ```js // response.data == [{ user: { name: 'jon', email: 'jon@doe.com' } }] -I.seeResponseContainsJson({ user: { email: 'jon@doe.com' } }) +I.seeResponseContainsJson({ user: { email: 'jon@doe.com' } }); ``` #### Parameters -- `json` **[object][2]** +* `json` **[object][2]** ### seeResponseContainsKeys @@ -166,7 +166,7 @@ Checks for deep inclusion of a provided json in a response data. ```js // response.data == { user: { name: 'jon', email: 'jon@doe.com' } } -I.seeResponseContainsKeys(['user']) +I.seeResponseContainsKeys(['user']); ``` If an array is received, check is performed for each element of array: @@ -174,12 +174,12 @@ If an array is received, check is performed for each element of array: ```js // response.data == [{ user: 'jon' }, { user: 'matt'}] -I.seeResponseContainsKeys(['user']) +I.seeResponseContainsKeys(['user']); ``` #### Parameters -- `keys` **[array][3]** +* `keys` **[array][3]** ### seeResponseEquals @@ -193,7 +193,7 @@ I.seeResponseEquals({ error: 'Not allowed' }) #### Parameters -- `resp` **[object][2]** +* `resp` **[object][2]** ### seeResponseMatchesJsonSchema @@ -223,7 +223,7 @@ I.seeResponseMatchesJsonSchema(joi.object({ #### Parameters -- `fnOrSchema` **any** +* `fnOrSchema` **any** ### seeResponseValidByCallback @@ -232,19 +232,24 @@ Use it to perform custom checks of response data ```js I.seeResponseValidByCallback(({ data, status }) => { - assert.strictEqual(status, 200) - assert('user' in data) - assert('company' in data) -}) + assert.strictEqual(status, 200); + assert('user' in data); + assert('company' in data); +}); ``` #### Parameters -- `fn` **[function][6]** +* `fn` **[function][6]** [1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number + [2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object + [3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array + [4]: https://joi.dev + [5]: https://joi.dev/api/ + [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function diff --git a/docs/helpers/MockRequest.md b/docs/helpers/MockRequest.md index 91f2adf46..3fd179964 100644 --- a/docs/helpers/MockRequest.md +++ b/docs/helpers/MockRequest.md @@ -6,6 +6,7 @@ title: MockRequest # MockRequest + ## MockRequest @@ -16,9 +17,9 @@ Another way of using is to emulate requests from server by passing prepared data MockRequest helper works in these [modes][1]: -- passthrough (default) - mock prefefined HTTP requests -- record - record all requests into a file -- replay - replay all recorded requests from a file +* passthrough (default) - mock prefefined HTTP requests +* record - record all requests into a file +* replay - replay all recorded requests from a file Combining record/replay modes allows testing websites with large datasets. @@ -26,16 +27,16 @@ To use in passthrough mode set rules to mock requests and they will be automatic ```js // default mode -I.mockRequest('GET', '/api/users', '[]') +I.mockRequest('GET', '/api/users', '[]'); ``` In record-replay mode start mocking to make HTTP requests recorded/replayed, and stop when you don't need to block requests anymore: ```js // record or replay all XHR for /users page -I.startMocking() -I.amOnPage('/users') -I.stopMocking() +I.startMocking(); +I.amOnPage('/users'); +I.stopMocking(); ``` ### Installations @@ -82,7 +83,7 @@ helpers: { } ``` ---- +*** **TROUBLESHOOTING**: Puppeteer does not mock requests in headless mode: @@ -103,7 +104,7 @@ Solution: update Puppeteer config to include `--disable-web-security` arguments: }, ``` ---- +*** #### With WebDriver @@ -128,17 +129,17 @@ helpers: { To intercept API requests and mock them use following API -- [startMocking()][4] - to enable request interception -- [mockRequest()][5] - to define mock in a simple way -- [mockServer()][6] - to use PollyJS server API to define complex mocks -- [stopMocking()][7] - to stop intercepting requests and disable mocks. +* [startMocking()][4] - to enable request interception +* [mockRequest()][5] - to define mock in a simple way +* [mockServer()][6] - to use PollyJS server API to define complex mocks +* [stopMocking()][7] - to stop intercepting requests and disable mocks. Calling `mockRequest` or `mockServer` will start mocking, if it was not enabled yet. ```js I.startMocking(); // optionally I.mockRequest('/google-analytics/*path', 200); -// return an empty successful response +// return an empty successful response I.mockRequest('GET', '/api/users', 200); // mock users api I.mockServer(server => { @@ -183,18 +184,18 @@ I.startMocking('users') // record requests under 'users' name Use `I.mockServer()` to customize which requests should be recorded and under which name: ```js -I.startMocking() -I.mockServer(server => { +I.startMocking(); +I.mockServer((server) => { // mock request only from ap1.com and api2.com and // store recording into two different files - server.any('https://api1.com/*').passthrough(false).recordingName('api1') - server.any('https://api2.com/*').passthrough(false).recordingName('api2') -}) + server.any('https://api1.com/*').passthrough(false).recordingName('api1'); + server.any('https://api2.com/*').passthrough(false).recordingName('api2'); +}); ``` To stop request recording/replaying use `I.stopMocking()`. -🎥 To record HTTP interactions execute tests with MOCK_MODE environment variable set as "record": +🎥 To record HTTP interactions execute tests with MOCK\_MODE environment variable set as "record": MOCK_MODE=record npx codeceptjs run --debug @@ -204,14 +205,14 @@ To stop request recording/replaying use `I.stopMocking()`. ### Parameters -- `config` +* `config` ### flushMocking Waits for all requests handled by MockRequests to be resolved: ```js -I.flushMocking() +I.flushMocking(); ``` ### mockRequest @@ -219,60 +220,61 @@ I.flushMocking() Mock response status ```js -I.mockRequest('GET', '/api/users', 200) -I.mockRequest('ANY', '/secretsRoutes/*', 403) -I.mockRequest('POST', '/secrets', { secrets: 'fakeSecrets' }) -I.mockRequest('GET', '/api/users/1', 404, 'User not found') +I.mockRequest('GET', '/api/users', 200); +I.mockRequest('ANY', '/secretsRoutes/*', 403); +I.mockRequest('POST', '/secrets', { secrets: 'fakeSecrets' }); +I.mockRequest('GET', '/api/users/1', 404, 'User not found'); ``` Multiple requests ```js -I.mockRequest('GET', ['/secrets', '/v2/secrets'], 403) +I.mockRequest('GET', ['/secrets', '/v2/secrets'], 403); ``` #### Parameters -- `method` **[string][8]** request method. Can be `GET`, `POST`, `PUT`, etc or `ANY`. -- `oneOrMoreUrls` **([string][8] | [Array][9]<[string][8]>)** url(s) to mock. Can be exact URL, a pattern, or an array of URLs. -- `dataOrStatusCode` **([number][10] | [string][8] | [object][11])** status code when number provided. A response body otherwise -- `additionalData` **([string][8] | [object][11])** response body when a status code is set by previous parameter. (optional, default `null`) +* `method` **[string][8]** request method. Can be `GET`, `POST`, `PUT`, etc or `ANY`. +* `oneOrMoreUrls` **([string][8] | [Array][9]<[string][8]>)** url(s) to mock. Can be exact URL, a pattern, or an array of URLs. +* `dataOrStatusCode` **([number][10] | [string][8] | [object][11])** status code when number provided. A response body otherwise +* `additionalData` **([string][8] | [object][11])** response body when a status code is set by previous parameter. (optional, default `null`) ### mockServer Use PollyJS [Server Routes API][12] to declare mocks via callback function: ```js -I.mockServer(server => { +I.mockServer((server) => { // basic usage server.get('/api/v2/users').intercept((req, res) => { - res.sendStatus(200).json({ users }) - }) + res.sendStatus(200).json({ users }); + }); // passthrough requests to "/api/v2" - server.get('/api/v1').passthrough() -}) + server.get('/api/v1').passthrough(); +}); ``` In record replay mode you can define which routes should be recorded and where to store them: ```js -I.startMocking('mock') -I.mockServer(server => { - // record requests from cdn1.com and save them to data/recording/xml - server.any('https://cdn1.com/*').passthrough(false).recordingName('xml') +I.startMocking('mock'); +I.mockServer((server) => { + // record requests from cdn1.com and save them to data/recording/xml + server.any('https://cdn1.com/*').passthrough(false).recordingName('xml'); + // record requests from cdn2.com and save them to data/recording/svg - server.any('https://cdn2.com/*').passthrough(false).recordingName('svg') + server.any('https://cdn2.com/*').passthrough(false).recordingName('svg'); // record requests from /api and save them to data/recording/mock (default) - server.any('/api/*').passthrough(false) -}) + server.any('/api/*').passthrough(false); +}); ``` #### Parameters -- `configFn` +* `configFn` ### passthroughMocking @@ -280,7 +282,7 @@ Forces passthrough mode for mocking. Requires mocking to be started. ```js -I.passthroughMocking() +I.passthroughMocking(); ``` ### recordMocking @@ -289,7 +291,7 @@ Forces record mode for mocking. Requires mocking to be started. ```js -I.recordMocking() +I.recordMocking(); ``` ### replayMocking @@ -298,7 +300,7 @@ Forces replay mode for mocking. Requires mocking to be started. ```js -I.replayMocking() +I.replayMocking(); ``` ### startMocking @@ -311,31 +313,31 @@ If inside one test you plan to record/replay requests in several places, provide ```js // start mocking requests for a test -I.startMocking() +I.startMocking(); // start mocking requests for main page -I.startMocking('main-page') +I.startMocking('main-page'); // do actions -I.stopMocking() -I.startMocking('login-page') +I.stopMocking(); +I.startMocking('login-page'); ``` To update [PollyJS configuration][14] use secon argument: ```js // change mode -I.startMocking('comments', { mode: 'replay' }) +I.startMocking('comments', { mode: 'replay' }); // override config I.startMocking('users-loaded', { - recordFailedRequests: true, + recordFailedRequests: true }) ``` #### Parameters -- `title` **any** (optional, default `'Test'`) -- `config` (optional, default `{}`) +* `title` **any** (optional, default `'Test'`) +* `config` (optional, default `{}`) ### stopMocking @@ -343,20 +345,33 @@ Stops mocking requests. Must be called to save recorded requests into faile. ```js -I.stopMocking() +I.stopMocking(); ``` [1]: https://netflix.github.io/pollyjs/#/configuration?id=mode + [2]: https://netflix.github.io/pollyjs/#/configuration?id=configuration + [3]: https://netflix.github.io/pollyjs/#/examples?id=rest-persister + [4]: #startMocking + [5]: #mockRequest + [6]: #mockServer + [7]: #stopMocking + [8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String + [9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array + [10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number + [11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object + [12]: https://netflix.github.io/pollyjs/#/server/overview + [13]: https://netflix.github.io/pollyjs/#/api?id=recordingname + [14]: https://netflix.github.io/pollyjs/#/configuration diff --git a/docs/helpers/Nightmare.md b/docs/helpers/Nightmare.md index 43f6d013f..12727861e 100644 --- a/docs/helpers/Nightmare.md +++ b/docs/helpers/Nightmare.md @@ -22,28 +22,28 @@ Requires `nightmare` package to be installed. This helper should be configured in codecept.conf.ts or codecept.conf.js -- `url` - base url of website to be tested -- `restart` - restart browser between tests. -- `disableScreenshots` - don't save screenshot on failure. -- `uniqueScreenshotNames` - option to prevent screenshot override if you have scenarios with the same name in different suites. -- `fullPageScreenshots` - make full page screenshots on failure. -- `keepBrowserState` - keep browser state between tests when `restart` set to false. -- `keepCookies` - keep cookies between tests when `restart` set to false. -- `waitForAction`: (optional) how long to wait after click, doubleClick or PressKey actions in ms. Default: 500. -- `waitForTimeout`: (optional) default wait\* timeout in ms. Default: 1000. -- `windowSize`: (optional) default window size. Set a dimension like `640x480`. +* `url` - base url of website to be tested +* `restart` - restart browser between tests. +* `disableScreenshots` - don't save screenshot on failure. +* `uniqueScreenshotNames` - option to prevent screenshot override if you have scenarios with the same name in different suites. +* `fullPageScreenshots` - make full page screenshots on failure. +* `keepBrowserState` - keep browser state between tests when `restart` set to false. +* `keepCookies` - keep cookies between tests when `restart` set to false. +* `waitForAction`: (optional) how long to wait after click, doubleClick or PressKey actions in ms. Default: 500. +* `waitForTimeout`: (optional) default wait* timeout in ms. Default: 1000. +* `windowSize`: (optional) default window size. Set a dimension like `640x480`. -- options from [Nightmare configuration][2] +* options from [Nightmare configuration][2] ## Methods ### Parameters -- `config` +* `config` -### \_locate +### _locate Locate elements by different locator types, including strict locator. Should be used in custom helpers. @@ -55,17 +55,17 @@ client-side function: ```js // get an inner text of an element -let browser = this.helpers['Nightmare'].browser -let value = this.helpers['Nightmare']._locate({ name: 'password' }).then(function (els) { - return browser.evaluate(function (el) { - return codeceptjs.fetchElement(el).value - }, els[0]) -}) +let browser = this.helpers['Nightmare'].browser; +let value = this.helpers['Nightmare']._locate({name: 'password'}).then(function(els) { + return browser.evaluate(function(el) { + return codeceptjs.fetchElement(el).value; + }, els[0]); +}); ``` #### Parameters -- `locator` +* `locator` ### amOnPage @@ -73,15 +73,15 @@ Opens a web page in a browser. Requires relative or absolute url. If url starts with `/`, opens a web page of a site defined in `url` config parameter. ```js -I.amOnPage('/') // opens main page of website -I.amOnPage('https://github.com') // opens github -I.amOnPage('/login') // opens a login page +I.amOnPage('/'); // opens main page of website +I.amOnPage('https://github.com'); // opens github +I.amOnPage('/login'); // opens a login page ``` #### Parameters -- `url` **[string][3]** url path or global url. -- `headers` **[object][4]?** list of request headers can be passed +* `url` **[string][3]** url path or global url. +* `headers` **[object][4]?** list of request headers can be passed Returns **void** automatically synchronized promise through #recorder @@ -91,15 +91,15 @@ Appends text to a input field or textarea. Field is located by name, label, CSS or XPath ```js -I.appendField('#myTextField', 'appended') +I.appendField('#myTextField', 'appended'); // typing secret -I.appendField('password', secret('123456')) +I.appendField('password', secret('123456')); ``` #### Parameters -- `field` **([string][3] | [object][4])** located by label|name|CSS|XPath|strict locator -- `value` **[string][3]** text value to append. +* `field` **([string][3] | [object][4])** located by label|name|CSS|XPath|strict locator +* `value` **[string][3]** text value to append. Returns **void** automatically synchronized promise through #recorder @@ -110,14 +110,14 @@ Path to file is relative current codecept directory (where codecept.conf.ts or c File will be uploaded to remote system (if tests are running remotely). ```js -I.attachFile('Avatar', 'data/avatar.jpg') -I.attachFile('form input[name=avatar]', 'data/avatar.jpg') +I.attachFile('Avatar', 'data/avatar.jpg'); +I.attachFile('form input[name=avatar]', 'data/avatar.jpg'); ``` #### Parameters -- `locator` **([string][3] | [object][4])** field located by label|name|CSS|XPath|strict locator. -- `pathToFile` **[string][3]** local file path relative to codecept.conf.ts or codecept.conf.js config file. +* `locator` **([string][3] | [object][4])** field located by label|name|CSS|XPath|strict locator. +* `pathToFile` **[string][3]** local file path relative to codecept.conf.ts or codecept.conf.js config file. Returns **void** automatically synchronized promise through #recorderDoesn't work if the Chromium DevTools panel is open (as Chromium allows only one attachment to the debugger at a time. [See more][5]) @@ -129,15 +129,15 @@ Element is located by label or name or CSS or XPath. The second parameter is a context (CSS or XPath locator) to narrow the search. ```js -I.checkOption('#agree') -I.checkOption('I Agree to Terms and Conditions') -I.checkOption('agree', '//form') +I.checkOption('#agree'); +I.checkOption('I Agree to Terms and Conditions'); +I.checkOption('agree', '//form'); ``` #### Parameters -- `field` **([string][3] | [object][4])** checkbox located by label | name | CSS | XPath | strict locator. -- `context` **([string][3]? | [object][4])** (optional, `null` by default) element located by CSS | XPath | strict locator. +* `field` **([string][3] | [object][4])** checkbox located by label | name | CSS | XPath | strict locator. +* `context` **([string][3]? | [object][4])** (optional, `null` by default) element located by CSS | XPath | strict locator. Returns **void** automatically synchronized promise through #recorder @@ -147,28 +147,28 @@ Clears a cookie by name, if none provided clears all cookies. ```js -I.clearCookie() -I.clearCookie('test') +I.clearCookie(); +I.clearCookie('test'); ``` #### Parameters -- `cookie` **[string][3]?** (optional, `null` by default) cookie name +* `cookie` **[string][3]?** (optional, `null` by default) cookie name ### clearField Clears a `