UNPKG

wd-intent-click

Version:
63 lines (50 loc) 2.6 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } var _wd = require('wd'); var _wd2 = _interopRequireDefault(_wd); var Utils = (function () { function Utils() { _classCallCheck(this, Utils); } _createClass(Utils, null, [{ key: 'clickIntent', value: function clickIntent(driver, el, cb) { var elCoords = undefined; var webViewXPath = '//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.widget.FrameLayout[1]/android.webkit.WebView[1]/android.view.View[1]'; var pressAction = function pressAction(driver, coords) { var action = new _wd2['default'].TouchAction(driver); action.press({ x: coords.x, y: coords.y }).wait(10).release(); return action; }; // get element location driver.getLocation(el, function (err, coords) { if (err) return cb(err); elCoords = coords; driver.context('NATIVE_APP', function (err) { if (err) return cb(err); driver.elementByXPath(webViewXPath, function (err, el) { if (err) return cb(err); driver.getLocation(el, function (err, coords) { if (err) return cb(err); var action = pressAction(driver, { x: elCoords.x, y: coords.y + elCoords.y }); action.perform(function (err) { // error clicking on the intent if (err) return cb(err); // success cb(null); }); }); }); }); }); } }]); return Utils; })(); exports['default'] = Utils; module.exports = exports['default'];