Extends Webdriver
Appium helper extends Webriver helper. It supports all browser methods and also includes special methods for mobile apps testing. You can use this helper to test Web on desktop and mobile devices and mobile apps.
Appium is an open source test automation framework for use with native, hybrid and mobile web apps that implements the WebDriver protocol. It allows you to run Selenium tests on mobile devices and also test native, hybrid and mobile web apps.
Download and install Appium
npm install -g appium
Launch the daemon: appium
This helper should be configured in codecept.json or codecept.conf.js
app
: Application path. Local path or remote URL to an .ipa or .apk file, or a .zip containing one of these. Alias to desiredCapabilities.appPackagehost
: (default: 'localhost') Appium hostport
: (default: '4723') Appium portplatform
: (Android or IOS), which mobile OS to use; alias to desiredCapabilities.platformNamerestart
: 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 belowplatformName
- Which mobile OS platform to useappPackage
- Java package of the Android app you want to runappActivity
- Activity name for the Android activity you want to launch from your package.deviceName
: The kind of mobile device or emulator to useplatformVersion
: Mobile OS versionapp
- 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:
{
helpers: {
Appium: {
platform: "Android",
desiredCapabilities: {
appPackage: "com.example.android.myApp",
appActivity: "MainActivity",
deviceName: "OnePlus3",
platformVersion: "6.0.1"
}
}
}
}
Example iOS Mobile Web with local Appium:
{
helpers: {
Appium: {
platform: "iOS",
url: "https://the-internet.herokuapp.com/",
desiredCapabilities: {
deviceName: "iPhone X",
platformVersion: "12.0",
browserName: "safari"
}
}
}
}
Example iOS Mobile Web on BrowserStack:
{
helpers: {
Appium: {
host: "hub-cloud.browserstack.com",
port: 4444,
user: process.env.BROWSERSTACK_USER,
key: process.env.BROWSERSTACK_KEY,
platform: "iOS",
url: "https://the-internet.herokuapp.com/",
desiredCapabilities: {
realMobile: "true",
device: "iPhone 8",
os_version: "12",
browserName: "safari"
}
}
}
}
Additional configuration params can be used from https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md
Receive a Appium client from a custom helper by accessing browser
property:
let browser = this.helpers['Appium'].browser
config
Execute code only on iOS
I.runOnIOS(() => {
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:
I.runOnIOS({deviceName: 'iPhone 5s'},() => {
// ...
});
Also capabilities can be checked by a function.
I.runOnAndroid((caps) => {
// caps is current config of desiredCapabiliites
return caps.platformVersion >= 6
},() => {
// ...
});
caps
anyfn
any
Execute code only on Android
I.runOnAndroid(() => {
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:
I.runOnAndroid({platformVersion: '6.0'},() => {
// ...
});
Also capabilities can be checked by a function. In this case, code will be executed only on Android >= 6.
I.runOnAndroid((caps) => {
// caps is current config of desiredCapabiliites
return caps.platformVersion >= 6
},() => {
// ...
});
caps
anyfn
any
Execute code only in Web mode.
I.runInWeb(() => {
I.waitForElement('#data');
I.seeInCurrentUrl('/data');
});
fn
any
Check if an app is installed.
I.seeAppIsInstalled("com.example.android.apis");
bundleId
string String ID of bundled appAppium: support only Android
Check if an app is not installed.
I.seeAppIsNotInstalled("com.example.android.apis");
bundleId
string String ID of bundled appAppium: support only Android
Install an app on device.
I.installApp('/path/to/file.apk');
path
string path to apk fileAppium: support only Android
Remove an app from the device.
I.removeApp('appName', 'com.example.android.apis');
Check current activity on an Android device.
I.seeCurrentActivityIs(".HomeScreenActivity")
currentActivity
string Appium: support only Android
Check whether the device is locked.
I.seeDeviceIsLocked();
Appium: support only Android
Check whether the device is not locked.
I.seeDeviceIsUnlocked();
Appium: support only Android
Check the device orientation
I.seeOrientationIs('PORTRAIT');
I.seeOrientationIs('LANDSCAPE')
orientation
("LANDSCAPE"
|"PORTRAIT"
) LANDSCAPE or PORTRAITAppium: support Android and iOS
Set a device orientation. Will fail, if app will not set orientation
I.setOrientation('PORTRAIT');
I.setOrientation('LANDSCAPE')
orientation
("LANDSCAPE"
|"PORTRAIT"
) LANDSCAPE or PORTRAITAppium: support Android and iOS
Get list of all available contexts
let contexts = await I.grabAllContexts();
Appium: support Android and iOS
Retrieve current context
let context = await I.grabContext();
Appium: support Android and iOS
Get current device activity.
let activity = await I.grabCurrentActivity();
Appium: support only Android
Get information about the current network connection (Data/WIFI/Airplane). The actual server value will be a number. However WebdriverIO additional properties to the response object to allow easier assertions.
let con = await I.grabNetworkConnection();
Appium: support only Android
Get current orientation.
let orientation = await I.grabOrientation();
Appium: support Android and iOS
Get all the currently specified settings.
let settings = await I.grabSettings();
Appium: support Android and iOS
Switch to the specified context.
context
any the context to switch to
Switches to web context. If no context is provided switches to the first detected web context
// switch to first web context
I.switchToWeb();
// or set the context explicitly
I.switchToWeb('WEBVIEW_io.selendroid.testapp');
context
string?
Switches to native context. By default switches to NATIVE_APP context unless other specified.
I.switchToNative();
// or set context explicitly
I.switchToNative('SOME_OTHER_CONTEXT');
context
any (optional, defaultnull
)
Start an arbitrary Android activity during a session.
I.startActivity('io.selendroid.testapp', '.RegisterUserActivity');
Appium: support only Android
appPackage
appActivity
Set network connection mode.
- airplane mode
- wifi mode
- data data
I.setNetworkConnection(0) // airplane mode off, wifi off, data off
I.setNetworkConnection(1) // airplane mode on, wifi off, data off
I.setNetworkConnection(2) // airplane mode off, wifi on, data off
I.setNetworkConnection(4) // airplane mode off, wifi off, data on
I.setNetworkConnection(6) // airplane mode off, wifi on, data on
See corresponding webdriverio reference.
Appium: support only Android
value
Update the current setting on the device
I.setSettings({cyberdelia: 'open'});
settings
object objectAppium: support Android and iOS
Hide the keyboard.
// taps outside to hide keyboard per default
I.hideDeviceKeyboard();
I.hideDeviceKeyboard('tapOutside');
// or by pressing key
I.hideDeviceKeyboard('pressKey', 'Done');
strategy
("tapOutside"
|"pressKey"
) desired strategy to close keyboard (‘tapOutside’ or ‘pressKey’)Appium: support Android and iOSkey
Send a key event to the device. List of keys: https://developer.android.com/reference/android/view/KeyEvent.html
I.sendDeviceKeyEvent(3);
keyValue
number Device specific key valueAppium: support only Android
Open the notifications panel on the device.
I.openNotifications();
Appium: support only Android
The Touch Action API provides the basis of all gestures that can be automated in Appium. At its core is the ability to chain together ad hoc individual actions, which will then be applied to an element in the application on the device. See complete documentation
I.makeTouchAction("~buttonStartWebviewCD", 'tap');
Appium: support Android and iOS
locator
action
Taps on element.
I.tap("~buttonStartWebviewCD");
Shortcut for makeTouchAction
locator
any
Perform a swipe on the screen or an element.
let locator = "#io.selendroid.testapp:id/LinearLayout1";
I.swipe(locator, 800, 1200, 1000);
locator
(string | object)xoffset
numberyoffset
numberspeed
number (optional), 1000 by defaultAppium: support Android and iOS (optional, default1000
)
Perform a swipe on the screen.
I.performswipe(100,200);
Perform a swipe down on an element.
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
locator
(string | object)yoffset
number? (optional) (optional, default1000
)speed
number (optional), 1000 by defaultAppium: support Android and iOS (optional, default1000
)
Perform a swipe left on an element.
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
locator
(string | object)xoffset
number? (optional) (optional, default1000
)speed
number (optional), 1000 by defaultAppium: support Android and iOS (optional, default1000
)
Perform a swipe right on an element.
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
locator
(string | object)xoffset
number? (optional) (optional, default1000
)speed
number (optional), 1000 by defaultAppium: support Android and iOS (optional, default1000
)
Perform a swipe up on an element.
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
locator
(string | object)yoffset
number? (optional) (optional, default1000
)speed
number (optional), 1000 by defaultAppium: support Android and iOS (optional, default1000
)
Perform a swipe in selected direction on an element to searchable element.
I.swipeTo(
"android.widget.CheckBox", // searchable element
"//android.widget.ScrollView/android.widget.LinearLayout", // scroll element
"up", // direction
30,
100,
500);
searchableLocator
stringscrollLocator
stringdirection
stringtimeout
numberoffset
numberspeed
number Appium: support Android and iOS
Performs a specific touch action. The action object need to contain the action name, x/y coordinates
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
}
}]);
Appium: support Android and iOS
actions
Pulls a file from the device.
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);
Appium: support Android and iOS
path
dest
Perform a shake action on the device.
I.shakeDevice();
Appium: support only iOS
Perform a rotation gesture centered on the specified element.
I.rotate(120, 120)
See corresponding webdriverio reference.
Appium: support only iOS
x
y
duration
radius
rotation
touchCount
Set immediate value in app.
See corresponding webdriverio reference.
Appium: support only iOS
id
value
Simulate Touch ID with either valid (match == true) or invalid (match == false) fingerprint.
I.touchId(); // simulates valid fingerprint
I.touchId(true); // simulates valid fingerprint
I.touchId(false); // simulates invalid fingerprint
Appium: support only iOS TODO: not tested
match
Close the given application.
I.closeApp();
Appium: support only iOS
Appends text to a input field or textarea. Field is located by name, label, CSS or XPath
I.appendField('#myTextField', 'appended');
field
(string | object) located by label|name|CSS|XPath|strict locatorvalue
string text value to append.
Selects a checkbox or radio button. 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.
I.checkOption('#agree');
I.checkOption('I Agree to Terms and Conditions');
I.checkOption('agree', '//form');
field
(string | object) checkbox located by label | name | CSS | XPath | strict locator.context
(string? | object) (optional,null
by default) element located by CSS | XPath | strict locator. (optional, defaultnull
)
Perform a click on a link or a button, given by a locator. If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string. For buttons, the "value" attribute, "name" attribute, and inner text are searched. For links, the link text is searched. For images, the "alt" attribute and inner text of any parent links are searched.
The second parameter is a context (CSS or XPath locator) to narrow the search.
// simple link
I.click('Logout');
// button of form
I.click('Submit');
// CSS button
I.click('#form input[type=submit]');
// XPath
I.click('//form/*[@type=submit]');
// link in context
I.click('Logout', '#nav');
// using strict locator
I.click({css: 'nav a.login'});
locator
(string | object) clickable link or button located by text, or any element located by CSS|XPath|strict locator.context
(string? | object) (optional,null
by default) element to search in CSS|XPath|Strict locator. (optional, defaultnull
)
Verifies that the specified checkbox is not checked.
I.dontSeeCheckboxIsChecked('#agree'); // located by ID
I.dontSeeCheckboxIsChecked('I agree to terms'); // located by label
I.dontSeeCheckboxIsChecked('agree'); // located by name
Opposite to seeElement
. Checks that element is not visible (or in DOM)
I.dontSeeElement('.modal'); // modal is not shown
Checks that value of input field or textarea doesn't equal to given value
Opposite to seeInField
.
I.dontSeeInField('email', '[email protected]'); // field by name
I.dontSeeInField({ css: 'form input.email' }, '[email protected]'); // field by CSS
field
(string | object) located by label|name|CSS|XPath|strict locator.value
string value to check.
Opposite to see
. Checks that a text is not present on a page.
Use context parameter to narrow down the search.
I.dontSee('Login'); // assume we are already logged in.
I.dontSee('Login', '.nav'); // no login inside .nav element
text
string which is not present.context
(string | object)? (optional) element located by CSS|XPath|strict locator in which to perfrom search. (optional, defaultnull
)
Fills a text field or textarea, after clearing its value, with the given string. Field is located by name, label, CSS, or XPath.
// by label
I.fillField('Email', '[email protected]');
// by name
I.fillField('password', secret('123456'));
// by CSS
I.fillField('form#login input[name=username]', 'John');
// or by strict locator
I.fillField({css: 'form#login input[name=username]'}, 'John');
field
(string | object) located by label|name|CSS|XPath|strict locator.value
string text value to fill.
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.
let pin = await I.grabTextFrom('#pin');
If multiple elements found returns an array of texts.
Returns Promise<(string | Array<string>)> attribute value
Retrieves a value from a form element located by CSS or XPath and returns it to test.
Resumes test execution, so should be used inside async function with await
operator.
let email = await I.grabValueFrom('input[name=email]');
Returns Promise<string> attribute value
Scroll element into viewport.
I.scrollIntoView('#submit');
I.scrollIntoView('#submit', true);
I.scrollIntoView('#submit', { behavior: "smooth", block: "center", inline: "center" });
locator
(string | object) located by CSS|XPath|strict locator.scrollIntoViewOptions
alignToTop
(boolean | object) (optional) or scrollIntoViewOptions (optional), see https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView.Supported only for web testing
Verifies that the specified checkbox is checked.
I.seeCheckboxIsChecked('Agree');
I.seeCheckboxIsChecked('#agree'); // I suppose user agreed to terms
I.seeCheckboxIsChecked({css: '#signup_form input[type=checkbox]'});
Checks that a given Element is visible Element is located by CSS or XPath.
I.seeElement('#modal');
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.
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');
field
(string | object) located by label|name|CSS|XPath|strict locator.value
string value to check.
Checks that a page contains a visible text. Use context parameter to narrow down the search.
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
text
string expected on page.context
(string? | object) (optional,null
by default) element located by CSS|Xpath|strict locator in which to search for text. (optional, defaultnull
)
Selects an option in a drop-down select. Field is searched by label | name | CSS | XPath. Option is selected by visible text or by value.
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.
I.selectOption('Which OS do you use?', ['Android', 'iOS']);
select
(string | object) field located by label|name|CSS|XPath|strict locator.option
(string | Array<any>) visible text or value of option.Supported only for web testing
Waits for element to be present on page (by default waits for 1sec). Element can be located by CSS or XPath.
I.waitForElement('.btn.continue');
I.waitForElement('.btn.continue', 5); // wait for 5 secs
locator
(string | object) element located by CSS|XPath|strict locator.sec
number? (optional,1
by default) time in seconds to wait (optional, defaultnull
)
Waits for an element to become visible on a page (by default waits for 1sec). Element can be located by CSS or XPath.
I.waitForVisible('#popup');
locator
(string | object) element located by CSS|XPath|strict locator.sec
number (optional,1
by default) time in seconds to wait (optional, default1
)
Waits for an element to be removed or become invisible on a page (by default waits for 1sec). Element can be located by CSS or XPath.
I.waitForInvisible('#popup');
locator
(string | object) element located by CSS|XPath|strict locator.sec
number (optional,1
by default) time in seconds to wait (optional, default1
)
Waits for a text to appear (by default waits for 1sec). Element can be located by CSS or XPath. Narrow down search results by providing context.
I.waitForText('Thank you, form has been submitted');
I.waitForText('Thank you, form has been submitted', 5, '#modal');
text
string to wait for.sec
number (optional,1
by default) time in seconds to wait (optional, default1
)context
(string | object)? (optional) element located by CSS|XPath|strict locator. (optional, defaultnull
)
Check if locator is type of "Shadow"
locator
object
Locate Element within the Shadow Dom
locator
object
Smart Wait to locate an element
locator
object
Get elements by different locator types, including strict locator. Should be used in custom helpers:
this.helpers['WebDriver']._locate({name: 'password'}).then //...
locator
(string | object) element located by CSS|XPath|strict locator.smartWait
(optional, defaultfalse
)
Find a checkbox by providing human readable text:
this.helpers['WebDriver']._locateCheckable('I agree with terms and conditions').then // ...
Find a clickable element by providing human readable text:
const els = await this.helpers.WebDriver._locateClickable('Next page');
const els = await this.helpers.WebDriver._locateClickable('Next page', '.pages');
Find field elements by providing human readable text:
this.helpers['WebDriver']._locateFields('Your email').then // ...
Set WebDriver timeouts in realtime.
Timeouts are expected to be passed as object:
I.defineTimeout({ script: 5000 });
I.defineTimeout({ implicit: 10000, pageLoad: 10000, script: 5000 });
timeouts
WebdriverIO.Timeouts WebDriver timeouts object.
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.
I.amOnPage('/'); // opens main page of website
I.amOnPage('https://github.com'); // opens github
I.amOnPage('/login'); // opens a login page
url
string url path or global url.
Perform an emulated click on a link or a button, given by a locator. Unlike normal click instead of sending native event, emulates a click with JavaScript. This works on hidden, animated or inactive elements as well.
If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string. For buttons, the "value" attribute, "name" attribute, and inner text are searched. For links, the link text is searched. For images, the "alt" attribute and inner text of any parent links are searched.
The second parameter is a context (CSS or XPath locator) to narrow the search.
// simple link
I.forceClick('Logout');
// button of form
I.forceClick('Submit');
// CSS button
I.forceClick('#form input[type=submit]');
// XPath
I.forceClick('//form/*[@type=submit]');
// link in context
I.forceClick('Logout', '#nav');
// using strict locator
I.forceClick({css: 'nav a.login'});
locator
(string | object) clickable link or button located by text, or any element located by CSS|XPath|strict locator.context
(string? | object) (optional,null
by default) element to search in CSS|XPath|Strict locator.{{ react }} (optional, defaultnull
)
Performs a double-click on an element matched by link|button|label|CSS or XPath. Context can be specified as second parameter to narrow search.
I.doubleClick('Edit');
I.doubleClick('Edit', '.actions');
I.doubleClick({css: 'button.accept'});
I.doubleClick('.btn.edit');
locator
(string | object) clickable link or button located by text, or any element located by CSS|XPath|strict locator.context
(string? | object) (optional,null
by default) element to search in CSS|XPath|Strict locator.{{ react }} (optional, defaultnull
)
Performs right click on a clickable element matched by semantic locator, CSS or XPath.
// right click element with id el
I.rightClick('#el');
// right click link or button with text "Click me"
I.rightClick('Click me');
// right click button with text "Click me" inside .context
I.rightClick('Click me', '.context');
locator
(string | object) clickable element located by CSS|XPath|strict locator.context
(string? | object) (optional,null
by default) element located by CSS|XPath|strict locator.{{ react }} (optional, defaultnull
)
Emulates right click on an element. Unlike normal click instead of sending native event, emulates a click with JavaScript. This works on hidden, animated or inactive elements as well.
If a fuzzy locator is given, the page will be searched for a button, link, or image matching the locator string. For buttons, the "value" attribute, "name" attribute, and inner text are searched. For links, the link text is searched. For images, the "alt" attribute and inner text of any parent links are searched.
The second parameter is a context (CSS or XPath locator) to narrow the search.
// simple link
I.forceRightClick('Menu');
locator
(string | object) clickable link or button located by text, or any element located by CSS|XPath|strict locator.context
(string? | object) (optional,null
by default) element to search in CSS|XPath|Strict locator.{{ react }} (optional, defaultnull
)
Clears a <textarea>
or text <input>
element's value.
I.clearField('Email');
I.clearField('user[email]');
I.clearField('#email');
Attaches a file to element located by label, name, CSS or XPath Path to file is relative current codecept directory (where codecept.json or codecept.conf.js is located). File will be uploaded to remote system (if tests are running remotely).
I.attachFile('Avatar', 'data/avatar.jpg');
I.attachFile('form input[name=avatar]', 'data/avatar.jpg');
locator
(string | object) field located by label|name|CSS|XPath|strict locator.pathToFile
string local file path relative to codecept.json config file. Appium: not tested
Unselects a checkbox or radio button. 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.
I.uncheckOption('#agree');
I.uncheckOption('I Agree to Terms and Conditions');
I.uncheckOption('agree', '//form');
field
(string | object) checkbox located by label | name | CSS | XPath | strict locator.context
(string? | object) (optional,null
by default) element located by CSS | XPath | strict locator. Appium: not tested (optional, defaultnull
)
Retrieves the innerHTML from an element located by CSS or XPath and returns it to test.
Resumes test execution, so should be used inside async function with await
operator.
If more than one element is found - an array of HTMLs returned.
let postHTML = await I.grabHTMLFrom('#post');
Returns Promise<string> HTML code for an element
Retrieves an attribute from an element located by CSS or XPath and returns it to test.
An array as a result will be returned if there are more than one matched element.
Resumes test execution, so should be used inside async function with await
operator.
let hint = await I.grabAttributeFrom('#tooltip', 'title');
Returns Promise<string> attribute value Appium: can be used for apps only with several values ("contentDescription", "text", "className", "resourceId")
Checks that text is equal to provided one.
I.seeTextEquals('text', 'h1');
text
string element value to check.context
(string | object?) element located by CSS|XPath|strict locator. (optional, defaultnull
)
Checks that a given Element is present in the DOM Element is located by CSS or XPath.
I.seeElementInDOM('#modal');
Opposite to seeElementInDOM
. Checks that element is not on page.
I.dontSeeElementInDOM('.nav'); // checks that element is not on page visible or not
Checks that the current page contains the given string in its raw source code.
I.seeInSource('<h1>Green eggs & ham</h1>');
text
string value to check.
Retrieves page source and returns it to test.
Resumes test execution, so should be used inside async function with await
operator.
let pageSource = await I.grabSource();
Returns Promise<string> source code
Get JS log from browser. Log buffer is reset after each request.
let logs = await I.grabBrowserLogs();
console.log(JSON.stringify(logs))
Returns Promise<(string | undefined)>
Checks that the current page does not contains the given string in its raw source code.
I.dontSeeInSource('<!--'); // no comments in source
text
value
string to check.
Asserts that an element appears a given number of times in the DOM. Element is located by label or name or CSS or XPath.
I.seeNumberOfElements('#submitBtn', 1);
locator
(string | object) element located by CSS|XPath|strict locator.num
number number of elements.{{ react }}
Asserts that an element is visible a given number of times. Element is located by CSS or XPath.
I.seeNumberOfVisibleElements('.buttons', 3);
locator
(string | object) element located by CSS|XPath|strict locator.num
number number of elements.{{ react }}
Checks that all elements with given locator have given attributes.
I.seeAttributesOnElements('//form', { method: "post"});
locator
(string | object) located by CSS|XPath|strict locator.attributes
object attributes and their values to check.
Grab number of visible elements by locator.
Resumes test execution, so should be used inside async function with await
operator.
let numOfElements = await I.grabNumberOfVisibleElements('p');
Returns Promise<number> number of visible elements
Scrolls to element matched by locator. Extra shift can be set with offsetX and offsetY options.
I.scrollTo('footer');
I.scrollTo('#submit', 5, 5);
locator
(string | object) located by CSS|XPath|strict locator.offsetX
number (optional,0
by default) X-axis offset. (optional, default0
)offsetY
number (optional,0
by default) Y-axis offset. (optional, default0
)
Moves cursor to element matched by locator. Extra shift can be set with offsetX and offsetY options.
I.moveCursorTo('.tooltip');
I.moveCursorTo('#submit', 5,5);
locator
(string | object) located by CSS|XPath|strict locator.xOffset
yOffset
offsetX
number (optional,0
by default) X-axis offset. (optional, default0
)offsetY
number (optional,0
by default) Y-axis offset. (optional, default0
)
Saves screenshot of the specified locator to ouput folder (set in codecept.json or codecept.conf.js). Filename is relative to output folder.
I.saveElementScreenshot(`#submit`,'debug.png');
locator
(string | object) element located by CSS|XPath|strict locator.fileName
string file name to save.
Saves a screenshot to ouput folder (set in codecept.json or codecept.conf.js).
Filename is relative to output folder.
Optionally resize the window to the full available page scrollHeight
and scrollWidth
to capture the entire page by passing true
in as the second argument.
I.saveScreenshot('debug.png');
I.saveScreenshot('debug.png', true) //resizes to available scrollHeight and scrollWidth before taking screenshot
fileName
string file name to save.fullPage
boolean (optional,false
by default) flag to enable fullscreen screenshot mode. (optional, defaultfalse
)
Types out the given text into an active field.
To slow down typing use a second parameter, to set interval between key presses.
Note: Should be used when fillField
is not an option.
// passing in a string
I.type('Type this out.');
// typing values with a 100ms interval
I.type('4141555311111111', 100);
// passing in an array
I.type(['T', 'E', 'X', 'T']);
keys
delay
number? (optional) delay in ms between key presses (optional, defaultnull
)key
(string | Array<string>) or array of keys to type.
Drag an item to a destination element.
I.dragAndDrop('#dragHandle', '#container');
srcElement
(string | object) located by CSS|XPath|strict locator.destElement
(string | object) located by CSS|XPath|strict locator. Appium: not tested
Drag the scrubber of a slider to a given position For fuzzy locators, fields are matched by label text, the "name" attribute, CSS, and XPath.
I.dragSlider('#slider', 30);
I.dragSlider('#slider', -70);
locator
(string | object) located by label|name|CSS|XPath|strict locator.offsetX
number position to drag. (optional, default0
)
Get all Window Handles.
Useful for referencing a specific handle when calling I.switchToWindow(handle)
const windows = await I.grabAllWindowHandles();
Get the current Window Handle.
Useful for referencing it when calling I.switchToWindow(handle)
const window = await I.grabCurrentWindowHandle();
Switch to the window with a specified handle.
const windows = await I.grabAllWindowHandles();
// ... do something
await I.switchToWindow( windows[0] );
const window = await I.grabCurrentWindowHandle();
// ... do something
await I.switchToWindow( window );
window
Close all tabs except for the current one.
I.closeOtherTabs();
Switches frame or in case of null locator reverts to parent.
I.switchTo('iframe'); // switch to first iframe
I.switchTo(); // switch back to main page
locator
(string? | object) (optional,null
by default) element located by CSS|XPath|strict locator. (optional, defaultnull
)
Grab number of open tabs.
Resumes test execution, so should be used inside async function with await
operator.
let tabs = await I.grabNumberOfOpenTabs();
Returns Promise<number> number of open tabs
Scroll page to the top.
I.scrollPageToTop();
Scroll page to the bottom.
I.scrollPageToBottom();
Retrieves a page scroll position and returns it to test.
Resumes test execution, so should be used inside an async function with await
operator.
let { x, y } = await I.grabPageScrollPosition();
Returns Promise<Object<string, any>> scroll position
Set the current geo location
I.setGeoLocation(121.21, 11.56);
I.setGeoLocation(121.21, 11.56, 10);
latitude
number to set.longitude
number to setaltitude
number (optional, null by default) to set (optional, defaultnull
)
Return the current geo location
Resumes test execution, so should be used inside async function with await
operator.
let geoLocation = await I.grabGeoLocation();
Returns Promise<{latitude: number, longitude: number, altitude: number}>
Grab the width, height, location of given locator.
Provide width
or height
as second param to get your desired prop.
Resumes test execution, so should be used inside an async function with await
operator.
Returns an object with x
, y
, width
, height
keys.
const value = await I.grabElementBoundingRect('h3');
// value is like { x: 226.5, y: 89, width: 527, height: 220 }
To get only one metric use second parameter:
const width = await I.grabElementBoundingRect('h3', 'width');
// width == 527
locator
(string | object) element located by CSS|XPath|strict locator.prop
elementSize
string x, y, width or height of the given element.
Returns object Element bounding rectangle