Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@codeceptjs/detox-helper
Advanced tools
Testing Mobile Apps on iOS and Android can look like this:
I.setLandscapeOrientation();
I.fillField('#text', 'a new text');
I.see('a new text', '#textValue');
I.dontSeeElement('#createdAndVisibleText');
I.click({ ios: '#GoButton', android: 'Button' });
I.waitForElement('#createdAndVisibleText', 20);
I.seeElement('#createdAndVisibleText');
I.runOnAndroid(() => {
I.click('Save');
I.see('Text Saved', '#message');
});
I.runOnIOS(() => {
I.click('SAVE');
I.see('SAVED!');
});
CodeceptJS provides next features over standard Detox:
Extends Helper
This is a wrapper on top of Detox library, aimied to unify testing experience for CodeceptJS framework. Detox provides a grey box testing for mobile applications, playing especially good for React Native apps.
Detox plays quite differently from Appium. To establish detox testing you need to build a mobile application in a special way to inject Detox code. This why Detox is grey box testing solution, so you need an access to application source code, and a way to build and execute it on emulator.
Comparing to Appium, Detox runs faster and more stable but requires an additional setup for build.
Build an application using detox build
command.
Install CodeceptJS and detox-helper:
npm i @codeceptjs/detox-helper --save
Detox configuration is required in package.json
under detox
section.
If you completed step 1 and step 2 you should have a configuration similar this:
"detox": {
"configurations": {
"ios.sim.debug": {
"binaryPath": "ios/build/Build/Products/Debug-iphonesimulator/example.app",
"build": "xcodebuild -project ios/example.xcodeproj -scheme example -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build",
"type": "ios.simulator",
"name": "iPhone 7"
}
}
}
Besides Detox configuration, CodeceptJS should also be configured to use Detox.
In codecept.conf.js
enable Detox helper:
helpers: {
Detox: {
require: '@codeceptjs/detox-helper',
configuration: '<detox-configuration-name>',
}
}
It's important to specify a package name under require
section and current detox configuration taken from package.json
.
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.config
Saves a screenshot to the output dir
I.saveScreenshot('main-window.png');
name
string
nameRelaunches an application.
I.relaunchApp();
Launches an application. If application instance already exists, use relaunchApp.
I.launchApp();
Installs a configured application. Application is installed by default.
I.installApp();
Shakes the device.
I.shakeDevice();
Goes back on Android
I.goBack(); // on Android only
Switches device to landscape orientation
I.setLandscapeOrientation();
Switches device to portrait orientation
I.setPortraitOrientation();
Execute code only on iOS
I.runOnIOS(() => {
I.click('Button');
I.see('Hi, IOS');
});
fn
a function which will be executed on iOSExecute code only on Android
I.runOnAndroid(() => {
I.click('Button');
I.see('Hi, Android');
});
fn
a function which will be executed on androidTaps on an element. Element can be located by its text or id or accessibility id.
The second parameter is a context element to narrow the search.
Same as click
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
Multi taps on an element. Element can be located by its text or id or accessibility id.
Set the number of taps in second argument. Optionally define the context element by third argument.
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
locator
(string | object) element to locatenum
int number of tapscontext
(string | object) context element (optional, default null
)Taps an element and holds for a requested time.
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
locator
(string | object) element to locatesec
num number of seconds to hold tapcontext
(string | object) context element (optional, default null
)Clicks on an element. Element can be located by its text or id or accessibility id
The second parameter is a context (id | type | accessibility id) to narrow the search.
Same as tap
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
Performs click on element with horizontal and vertical offset. An element is located by text, id, accessibility id.
I.clickAtPoint('Save', 10, 10);
I.clickAtPoint('~save', 10, 10); // locate by accessibility id
locator
(string | object)x
int horizontal offset (optional, default 0
)y
int vertical offset (optional, default 0
)Checks text to be visible. Use second parameter to narrow down the search.
I.see('Record created');
I.see('Record updated', '#message');
I.see('Record deleted', '~message');
text
string to check visibilitycontext
(string | object) element inside which to search for text (optional, default null
)Checks text not to be visible. Use second parameter to narrow down the search.
I.dontSee('Record created');
I.dontSee('Record updated', '#message');
I.dontSee('Record deleted', '~message');
text
string to check invisibilitycontext
(string | object) element in which to search for text (optional, default null
)Checks for visibility of an element. Use second parameter to narrow down the search.
I.seeElement('~edit'); // located by accessibility id
I.seeElement('~edit', '#menu'); // element inside #menu
locator
(string | object) element to locatecontext
(string | object) context element (optional, default null
)Checks that element is not visible. Use second parameter to narrow down the search.
I.dontSeeElement('~edit'); // located by accessibility id
I.dontSeeElement('~edit', '#menu'); // element inside #menu
locator
(string | object) element to locatecontext
(string | object) context element (optional, default null
)Checks for existence of an element. An element can be visible or not. Use second parameter to narrow down the search.
I.seeElementExists('~edit'); // located by accessibility id
I.seeElementExists('~edit', '#menu'); // element inside #menu
locator
(string | object) element to locatecontext
(string | object) context element (optional, default null
)Checks that element not exists. Use second parameter to narrow down the search.
I.dontSeeElementExist('~edit'); // located by accessibility id
I.dontSeeElementExist('~edit', '#menu'); // element inside #menu
locator
(string | object) element to locatecontext
(string | object) context element (optional, default null
)Fills in text field in an app. A field can be located by text, accessibility id, id.
I.fillField('Username', 'davert');
I.fillField('~name', 'davert');
I.fillField({ android: 'NAME', ios: 'name' }, 'davert');
Clears a text field. A field can be located by text, accessibility id, id.
I.clearField('~name');
Appends text into the field. A field can be located by text, accessibility id, id.
I.appendField('name', 'davert');
Scrolls to the top of an element.
I.scrollUp('#container');
Scrolls to the bottom of an element.
I.scrollDown('#container');
Scrolls to the left of an element.
I.scrollLeft('#container');
Scrolls to the right of an element.
I.scrollRight('#container');
Performs a swipe up inside an element.
Can be slow
or fast
swipe.
I.swipeUp('#container');
locator
(string | object) an element on which to perform swipespeed
string a speed to perform: slow
or fast
. (optional, default 'slow'
)Performs a swipe up inside an element.
Can be slow
or fast
swipe.
I.swipeUp('#container');
locator
(string | object) an element on which to perform swipespeed
string a speed to perform: slow
or fast
. (optional, default 'slow'
)Performs a swipe up inside an element.
Can be slow
or fast
swipe.
I.swipeUp('#container');
locator
(string | object) an element on which to perform swipespeed
string a speed to perform: slow
or fast
. (optional, default 'slow'
)Performs a swipe up inside an element.
Can be slow
or fast
swipe.
I.swipeUp('#container');
locator
(string | object) an element on which to perform swipespeed
string a speed to perform: slow
or fast
. (optional, default 'slow'
)Waits for number of seconds
I.wait(2); // waits for 2 seconds
sec
int number of seconds to waitWaits for an element to exist on page.
I.waitForElement('#message', 1); // wait for 1 second
locator
(string | object) an element to wait forsec
int number of seconds to wait, 5 by default (optional, default 5
)Waits for an element to be visible on page.
I.waitForElementVisible('#message', 1); // wait for 1 second
locator
(string | object) an element to wait forsec
int number of seconds to wait (optional, default 5
)Waits an elment to become not visible.
I.waitToHide('#message', 2); // wait for 2 seconds
FAQs
Detox helper for CodeceptJS
The npm package @codeceptjs/detox-helper receives a total of 50,128 weekly downloads. As such, @codeceptjs/detox-helper popularity was classified as popular.
We found that @codeceptjs/detox-helper demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.