Fix Android page source

This commit is contained in:
bootstraponline
2014-02-27 09:37:56 -05:00
parent 8022031199
commit 591c0dbc4e
5 changed files with 61 additions and 5 deletions

View File

@@ -252,14 +252,14 @@ androidController.getPageSource = function (cb) {
var xmlFile = temp.path({suffix: '.xml'});
var jsonFile = xmlFile + '.json';
var json = '';
var onDeviceXmlPath = this.dataDir + '/local/tmp/dump.xml';
async.series(
[
function (cb) {
// /data/local/tmp/dump.xml
this.proxy(["dumpWindowHierarchy"], cb);
}.bind(this),
function (cb) {
var cmd = this.adb.adbCmd + ' pull /data/local/tmp/dump.xml "' + xmlFile + '"';
var cmd = this.adb.adbCmd + ' pull ' + onDeviceXmlPath + ' "' + xmlFile + '"';
logger.debug('transferPageSource command: ' + cmd);
exec(cmd, { maxBuffer: 524288 }, function (err, stdout, stderr) {
if (err) {

View File

@@ -81,6 +81,7 @@ Android.prototype.initialize = function (opts) {
, javascriptEnabled: true
, databaseEnabled: false
};
this.dataDir = null;
_.extend(this.capabilities, opts.desiredCapabilities);
};
@@ -111,6 +112,7 @@ Android.prototype.start = function (cb, onDie) {
this.uiautomator.start.bind(this.uiautomator),
this.wakeUp.bind(this),
this.unlockScreen.bind(this),
this.getDataDir.bind(this),
this.startApp.bind(this)
], function (err) {
if (err) {
@@ -489,6 +491,15 @@ Android.prototype.wakeUp = function (cb) {
this.proxy(["wake", {}], cb);
};
Android.prototype.getDataDir = function (cb) {
this.proxy(["getDataDir", {}], function (err, res) {
if (err) return cb(err);
this.dataDir = res.value;
logger.debug("dataDir set to: " + this.dataDir);
cb();
}.bind(this));
};
Android.prototype.waitForActivityToStop = function (cb) {
this.adb.waitForNotActivity(this.appWaitPackage, this.appWaitActivity, cb);
};

View File

@@ -9,6 +9,7 @@ import io.appium.android.bootstrap.handler.EnableCompressedLayoutHeirarchy;
import io.appium.android.bootstrap.handler.Find;
import io.appium.android.bootstrap.handler.Flick;
import io.appium.android.bootstrap.handler.GetAttribute;
import io.appium.android.bootstrap.handler.GetDataDir;
import io.appium.android.bootstrap.handler.GetDeviceSize;
import io.appium.android.bootstrap.handler.GetLocation;
import io.appium.android.bootstrap.handler.GetName;
@@ -67,6 +68,7 @@ class AndroidCommandExecutor {
map.put("enableCompressedLayoutHeirarchy",
new EnableCompressedLayoutHeirarchy());
map.put("getStrings", new GetStrings());
map.put("getDataDir", new GetDataDir());
}
/**

View File

@@ -4,11 +4,17 @@ import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import java.io.File;
import android.os.Environment;
import com.android.uiautomator.core.UiDevice;
/**
* This handler is used to dumpWindowHierarchy.
*
* https://android.googlesource.com/
* platform/frameworks/testing/+/master/uiautomator
* /library/core-src/com/android/uiautomator/core/UiDevice.java
*/
public class DumpWindowHierarchy extends CommandHandler {
@@ -24,8 +30,17 @@ public class DumpWindowHierarchy extends CommandHandler {
*/
@Override
public AndroidCommandResult execute(final AndroidCommand command) {
// root is /data/local/tmp/
UiDevice.getInstance().dumpWindowHierarchy("dump.xml");
final String dumpXml = "dump.xml";
final File dump = new File(new File(Environment.getDataDirectory(),
"local/tmp"), dumpXml);
dump.mkdirs();
if (dump.exists()) {
dump.delete();
}
UiDevice.getInstance().dumpWindowHierarchy(dumpXml);
return getSuccessResult(true);
}
}

View File

@@ -0,0 +1,28 @@
package io.appium.android.bootstrap.handler;
import io.appium.android.bootstrap.AndroidCommand;
import io.appium.android.bootstrap.AndroidCommandResult;
import io.appium.android.bootstrap.CommandHandler;
import android.os.Environment;
/**
* This handler is used to get the data dir.
*
*/
public class GetDataDir extends CommandHandler {
/*
* @param command The {@link AndroidCommand} used for this handler.
*
* @return {@link AndroidCommandResult}
*
* @throws JSONException
*
* @see io.appium.android.bootstrap.CommandHandler#execute(io.appium.android.
* bootstrap.AndroidCommand)
*/
@Override
public AndroidCommandResult execute(final AndroidCommand command) {
return getSuccessResult(Environment.getDataDirectory());
}
}