macaca-android
Advanced tools
Comparing version 1.1.34 to 2.0.0
@@ -40,3 +40,3 @@ 'use strict'; | ||
} else { | ||
this.proxy = null; | ||
this.proxy = this.uiautomator; | ||
} | ||
@@ -46,97 +46,2 @@ this.context = name; | ||
controllers.click = function *(elementId) { | ||
return yield this.send({ | ||
cmd: 'click', | ||
args: { | ||
elementId: elementId | ||
} | ||
}); | ||
}; | ||
controllers.getWindowSize = function *() { | ||
var size = yield this.send({ | ||
cmd: 'getWindowSize', | ||
args: {} | ||
}); | ||
return JSON.parse(size); | ||
}; | ||
controllers.setValue = function *(elementId, value) { | ||
return yield this.send({ | ||
cmd: 'setText', | ||
args: { | ||
elementId: elementId, | ||
text: value.join('') | ||
} | ||
}); | ||
}; | ||
controllers.keys = function *(value) { | ||
value = value.join(''); | ||
var arrText = []; | ||
for (var i = 0; i < value.length; i++) { | ||
var key = value.charAt(i); | ||
const keyEvent = keyMap[key]; | ||
if (keyEvent) { | ||
if (arrText.length) { | ||
yield this.setValue('', arrText); | ||
arrText = []; | ||
} | ||
yield this.adb.input(`keyevent ${keyEvent}`); | ||
} else { | ||
arrText.push(key); | ||
} | ||
} | ||
if (arrText.length) { | ||
yield this.setValue('', arrText); | ||
} | ||
return null; | ||
}; | ||
controllers.getText = function *(elementId) { | ||
var args = { | ||
elementId: elementId | ||
}; | ||
return yield this.send({ | ||
cmd: 'getText', | ||
args: args | ||
}); | ||
}; | ||
controllers.clearText = function *(elementId) { | ||
var args = { | ||
elementId: elementId | ||
}; | ||
return yield this.send({ | ||
cmd: 'clearText', | ||
args: args | ||
}); | ||
}; | ||
controllers.findElement = function *(strategy, selector) { | ||
var args = { | ||
strategy: strategy, | ||
selector: selector, | ||
multiple: false | ||
}; | ||
return yield this.send({ | ||
cmd: 'find', | ||
args: args | ||
}); | ||
}; | ||
controllers.findElements = function *(strategy, selector) { | ||
var args = { | ||
strategy: strategy, | ||
selector: selector, | ||
multiple: true | ||
}; | ||
return yield this.send({ | ||
cmd: 'find', | ||
args: args | ||
}); | ||
}; | ||
controllers.getScreenshot = function *() { | ||
@@ -148,3 +53,3 @@ const swapFilePath = temp.path({ | ||
const tmpDir = yield this.getTempDir(); | ||
const tmpDir = '/data/local/tmp'; | ||
const remoteFile = `${tmpDir}/screenshot.png`; | ||
@@ -180,78 +85,2 @@ const cmd = `/system/bin/rm ${remoteFile}; /system/bin/screencap -p ${remoteFile}`; | ||
controllers.getProperty = function *(elementId, name) { | ||
var res = yield this.send({ | ||
cmd: 'getProperties', | ||
args: { | ||
elementId: elementId | ||
} | ||
}); | ||
var properties = JSON.parse(res); | ||
var property = properties[name]; | ||
return property == null ? null: property; | ||
}; | ||
controllers.getRect = function *(elementId) { | ||
return yield this.send({ | ||
cmd: 'getRect', | ||
args: { | ||
elementId: elementId | ||
} | ||
}); | ||
}; | ||
controllers.getSource = function *() { | ||
yield this.send({ | ||
cmd: 'getSource', | ||
args: { | ||
} | ||
}); | ||
const tmpDir = yield this.getTempDir(); | ||
var xml = yield this.adb.shell(`cat ${tmpDir}/macaca-dump.xml`); | ||
return xml; | ||
}; | ||
controllers.getTempDir = function *(){ | ||
return yield this.send({ | ||
cmd: 'getTmpDir', | ||
args: { | ||
} | ||
}); | ||
}; | ||
controllers.isDisplayed = function *(elementId) { | ||
return yield this.send({ | ||
cmd: 'isDisplayed', | ||
args: { | ||
elementId: elementId | ||
} | ||
}); | ||
}; | ||
controllers.handleActions = function *(actions) { | ||
if (!actions) { | ||
throw new errors.UnknownError(`Missing 'actions' in parameters.`); | ||
} | ||
if (this.isWebContext()) { | ||
const futureActions = actions.map(action => { | ||
const actionDelegate = this[action.type]; | ||
if (actionDelegate) { | ||
return actionDelegate.bind(this, action); | ||
} else { | ||
return () => { | ||
throw new errors.NotImplementedError(`Action ${action.type} is not implemented yet.`); | ||
}; | ||
} | ||
}); | ||
return yield _.serialTasks.apply(null, futureActions); | ||
} else { | ||
return yield this.send({ | ||
cmd: 'actions', | ||
args: { | ||
actions: actions | ||
} | ||
}); | ||
} | ||
}; | ||
controllers.tap = function(action) { | ||
@@ -266,20 +95,2 @@ return this | ||
controllers.acceptAlert = function *() { | ||
return yield this.send({ | ||
cmd: 'alert', | ||
args: { | ||
action: 'accept' | ||
} | ||
}); | ||
}; | ||
controllers.dismissAlert = function *() { | ||
return yield this.send({ | ||
cmd: 'alert', | ||
args: { | ||
action: 'dismiss' | ||
} | ||
}); | ||
}; | ||
module.exports = controllers; |
@@ -9,4 +9,4 @@ 'use strict'; | ||
const DriverBase = require('driver-base'); | ||
const UIAutomatorWD = require('uiautomatorwd'); | ||
const UnicodeInput = require('android-unicode'); | ||
const UIAutomator = require('uiautomator-client'); | ||
const ChromeDriver = require('macaca-chromedriver'); | ||
@@ -21,2 +21,3 @@ const errors = require('webdriver-dfn-error-code').errors; | ||
const reuseStatus = {}; | ||
reuseStatus.noReuse = 0; | ||
@@ -55,5 +56,3 @@ reuseStatus.reuseEmu = 1; | ||
yield this.unlock(); | ||
yield this.setIME(); | ||
yield this.launchApk(); | ||
yield this.wake(); | ||
@@ -85,3 +84,9 @@ if (this.isChrome) { | ||
var basename = path.basename(context.url); | ||
const whiteList = ['context', 'contexts', 'screenshot', 'actions']; | ||
const whiteList = [ | ||
'context', | ||
'contexts', | ||
'screenshot', | ||
'back', | ||
'tap' | ||
]; | ||
return !!~whiteList.indexOf(basename); | ||
@@ -95,3 +100,2 @@ }; | ||
Android.prototype.waitActivityReady = function *() { | ||
@@ -115,4 +119,2 @@ | ||
yield _.sleep(1000); | ||
var isActivityReady = false; | ||
@@ -130,13 +132,2 @@ | ||
Android.prototype.wake = function *() { | ||
yield this.waitActivityReady(); | ||
yield this.send({ | ||
cmd: 'wake', | ||
args: {} | ||
}); | ||
yield _.sleep(3000); | ||
}; | ||
Android.prototype.initAdb = function() { | ||
@@ -155,3 +146,4 @@ this.adb = new ADB(); | ||
Android.prototype.initUiautomator = function *() { | ||
this.uiautomator = new UIAutomator(); | ||
this.uiautomator = new UIAutomatorWD(); | ||
this.proxy = this.uiautomator; | ||
yield this.uiautomator.init(this.adb); | ||
@@ -271,3 +263,2 @@ }; | ||
Android.prototype.setIME = function *() { | ||
const isInstalled = yield this.adb.isInstalled(UnicodeInput.package); | ||
@@ -329,12 +320,8 @@ | ||
} | ||
if (!this.proxy) { | ||
this.proxy = this.chromedriver; | ||
} | ||
this.proxy = this.chromedriver; | ||
var webviews = []; | ||
if (this.isProxy()) { | ||
const result = yield this.proxy.sendCommand('/wd/hub/session/temp/window_handles', 'GET', {}); | ||
webviews = _.parseWebDriverResult(result); | ||
} | ||
const result = yield this.proxy.sendCommand('/wd/hub/session/temp/window_handles', 'GET', {}); | ||
webviews = _.parseWebDriverResult(result); | ||
@@ -362,24 +349,4 @@ return webviews; | ||
Android.prototype.send = function *(data) { | ||
var result; | ||
try { | ||
result = yield this.uiautomator.send(data); | ||
} catch (err) { | ||
logger.debug(`UnknownError from uiautomator ${err}`); | ||
throw new errors.UnknownError(); | ||
} | ||
var statusCode = result.status; | ||
if (statusCode === 0) { | ||
return result.value; | ||
} else { | ||
var errName = getErrorByCode(statusCode); | ||
if (!errName) { | ||
throw new errors.UnknownError(); | ||
} | ||
throw new errors[errName](result.value); | ||
} | ||
}; | ||
_.extend(Android.prototype, controllers); | ||
module.exports = Android; |
{ | ||
"name": "macaca-android", | ||
"version": "1.1.34", | ||
"version": "2.0.0", | ||
"description": "Macaca Android driver", | ||
@@ -14,3 +14,3 @@ "keywords": [ | ||
"dependencies": { | ||
"android-unicode": "1.0.11", | ||
"android-unicode": "~1.1.0", | ||
"driver-base": "~0.1.0", | ||
@@ -22,4 +22,4 @@ "java-util": "~0.1.0", | ||
"temp": "~0.8.3", | ||
"uiautomator-client": "1.1.9", | ||
"unlock-apk": "~0.1.11", | ||
"uiautomatorwd": "~1.0.0", | ||
"unlock-apk": "~1.0.3", | ||
"webdriver-dfn-error-code": "~1.0.1", | ||
@@ -26,0 +26,0 @@ "xlogger": "~1.0.0" |
18757
505
+ Addeduiautomatorwd@~1.0.0
+ Addedajv@6.12.6(transitive)
+ Addedandroid-unicode@1.1.3(transitive)
+ Addedansi-styles@4.3.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcross-spawn@5.1.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgradle@1.2.4(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedlru-cache@4.1.5(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpseudomap@1.0.2(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedshebang-command@1.2.0(transitive)
+ Addedshebang-regex@1.0.0(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addeduiautomatorwd@1.0.61(transitive)
+ Addedunlock-apk@1.0.8(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedwhich@1.3.1(transitive)
+ Addedyallist@2.1.2(transitive)
- Removeduiautomator-client@1.1.9
- Removedandroid-unicode@1.0.11(transitive)
- Removedant-build@1.0.4(transitive)
- Removedant-lite@1.0.2(transitive)
- Removeduiautomator-client@1.1.9(transitive)
- Removedunlock-apk@0.1.16(transitive)
- Removedwin-spawn@2.0.0(transitive)
Updatedandroid-unicode@~1.1.0
Updatedunlock-apk@~1.0.3