Skip to content

Commit

Permalink
feat: Add doubleClick mobile geature (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Feb 11, 2021
1 parent 33e47ce commit 0d8ef1a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ UiAutomator2 provides several extensions that allow to automate popular mobile g

- mobile: dragGesture
- mobile: flingGesture
- mobile: doubleClickGesture
- mobile: longClickGesture
- mobile: pinchCloseGesture
- mobile: pinchOpenGesture
Expand Down
1 change: 1 addition & 0 deletions lib/commands/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ extensions.executeMobile = async function (mobileCommand, opts = {}) {

dragGesture: 'mobileDragGesture',
flingGesture: 'mobileFlingGesture',
doubleClickGesture: 'mobileDoubleClickGesture',
longClickGesture: 'mobileLongClickGesture',
pinchCloseGesture: 'mobilePinchCloseGesture',
pinchOpenGesture: 'mobilePinchOpenGesture',
Expand Down
27 changes: 27 additions & 0 deletions lib/commands/gestures.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,33 @@ commands.mobileLongClickGesture = async function mobileLongClickGesture (opts =
});
};

/**
* @typedef {Object} DoubleClickOptions
* @property {?string} elementId - The id of the element to be double clicked.
* If the element is missing then both click offset coordinates must be provided.
* If both the element id and offset are provided then the coordinates
* are parsed as relative offsets from the top left corner of the element.
* @property {?number} x - The x coordinate to double click on
* @property {?number} y - The y coordinate to double click on
*/

/**
* Performs a click that lasts for the given duration
*
* @param {?DoubleClickOptions} opts
* @throws {Error} if provided options are not valid
*/
commands.mobileDoubleClickGesture = async function mobileDoubleClickGesture (opts = {}) {
const {
elementId,
x, y,
} = opts;
return await this.uiautomator2.jwproxy.command('/appium/gestures/double_click', 'POST', {
origin: toOrigin(elementId),
offset: toPoint(x, y),
});
};

/**
* @typedef {Object} DragOptions
* @property {?string} elementId - The id of the element to be dragged.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"appium-base-driver": "^7.0.0",
"appium-chromedriver": "^4.23.1",
"appium-support": "^2.49.0",
"appium-uiautomator2-server": "^4.17.4",
"appium-uiautomator2-server": "^4.20.0",
"asyncbox": "^2.3.1",
"axios": "^0.21.0",
"bluebird": "^3.5.1",
Expand Down

0 comments on commit 0d8ef1a

Please sign in to comment.