id | title |
---|---|
APIRef.ActionsOnElement |
Actions on Element |
Detox uses Matchers to find UI elements
in your app, Actions to emulate user interaction with those elements
and Expectations to verify values on those elements
.
Actions are functions that emulate user behavior. They are being performed on matched elements.
.tap()
.longPress()
.multiTap()
.tapAtPoint()
.tapBackspaceKey()
.tapReturnKey()
.typeText()
.replaceText()
.clearText()
.scroll()
.scrollTo()
.swipe()
.setColumnToValue()
iOS only.pinchWithAngle()
iOS only.setDatePickerDate()
iOS only
Simulate tap on an element.
await element(by.id('tappable')).tap();
Simulate long press on an element.
duration - long press time interval. (iOS only)
await element(by.id('tappable')).longPress();
Simulate multiple taps on an element.
await element(by.id('tappable')).multiTap(3);
Simulate tap at a specific point on an element.
Note: The point coordinates are relative to the matched element and the element size could changes on different devices or even when changing the device font size.
await element(by.id('tappable')).tapAtPoint({x:5, y:10});
Tap the backspace key on the built-in keyboard.
await element(by.id('textField')).tapBackspaceKey();
Tap the return key on the built-in keyboard.
await element(by.id('textField')).tapReturnKey();
Use the builtin keyboard to type text into a text field.
await element(by.id('textField')).typeText('passcode');
Note: Make sure hardware keyboard is disconnected. Otherwise, Detox may fail when attempting to type text.
To make sure hardware keyboard is disconnected, open the simulator from Xcode and make sure Hardware -> Keyboard -> Connect Hardware Keyboard is deselected (or press ⇧⌘K).
Paste text into a text field.
await element(by.id('textField')).replaceText('passcode again');
Clear text from a text field.
await element(by.id('textField')).clearText();
Scroll amount of pixels.
pixels - independent device pixels
direction - left/right/top/bottom
startPositionX - The X starting scroll position, in percentage; valid input: (0.0, 1.0), NaN
; default: NaN
—Choose the best value
startPositionY - The Y starting scroll position, in percentage; valid input: (0.0, 1.0), NaN
; default: NaN
—Choose the best value
await element(by.id('scrollView')).scroll(100, 'down', NaN, 0.85);
await element(by.id('scrollView')).scroll(100, 'up');
Scroll to edge.
edge - left/right/top/bottom
await element(by.id('scrollView')).scrollTo('bottom');
await element(by.id('scrollView')).scrollTo('top');
direction - left/right/up/down
speed - fast/slow - default is fast
percentage - (optional) screen percentage to swipe as float
await element(by.id('scrollView')).swipe('down');
await element(by.id('scrollView')).swipe('down', 'fast');
await element(by.id('scrollView')).swipe('down', 'fast', 0.5);
column - date picker column index
value - string value to set in column
await expect(element(by.type('UIPickerView'))).toBeVisible();
await element(by.type('UIPickerView')).setColumnToValue(1,"6");
await element(by.type('UIPickerView')).setColumnToValue(2,"34");
direction - inward/outward
speed - slow/fast - default is slow
angle - value in radiant - default is 0
await expect(element(by.id('PinchableScrollView'))).toBeVisible();
await element(by.id('PinchableScrollView')).pinchWithAngle('outward', 'slow', 0);
dateString - string representing a date in the supplied dateFormat
dateFormat - format for the dateString supplied
await expect(element(by.type('UIDatePicker'))).toBeVisible();
await element(by.type('UIDatePicker)).setDatePickerDate('2019-02-06T05:10:00-08:00', "yyyy-MM-dd'T'HH:mm:ssZZZZZ");