Use uiautomator screenshot

uiautomator has built in support for taking screenshots. There's no need for an
external jar.
This commit is contained in:
bootstraponline
2013-07-25 13:27:40 -04:00
parent 3435e4e8fe
commit 4efdac2ffb
3 changed files with 37 additions and 19 deletions
@@ -17,6 +17,7 @@ import io.appium.android.bootstrap.handler.PressKeyCode;
import io.appium.android.bootstrap.handler.ScrollTo;
import io.appium.android.bootstrap.handler.SetText;
import io.appium.android.bootstrap.handler.Swipe;
import io.appium.android.bootstrap.handler.TakeScreenshot;
import io.appium.android.bootstrap.handler.TouchLongClick;
import io.appium.android.bootstrap.handler.WaitForIdle;
import io.appium.android.bootstrap.handler.Wake;
@@ -54,6 +55,7 @@ class AndroidCommandExecutor {
map.put("pressBack", new PressBack());
map.put("dumpWindowHierarchy", new DumpWindowHierarchy());
map.put("pressKeyCode", new PressKeyCode());
map.put("takeScreenshot", new TakeScreenshot());
}
/**
@@ -0,0 +1,33 @@
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 java.io.File;
import com.android.uiautomator.core.UiDevice;
/**
* This handler is used to TakeScreenshot.
*
*/
public class TakeScreenshot 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) {
final boolean result = UiDevice.getInstance().takeScreenshot(
new File("/data/local/tmp/screenshot.png"));
return getSuccessResult(result);
}
}
+2 -19
View File
@@ -679,30 +679,13 @@ Android.prototype.getScreenshot = function(cb) {
me.adb.requireDeviceId();
var localfile = temp.path({prefix: 'appium', suffix: '.png'});
var b64data = "";
var jar = path.resolve(__dirname, '..', 'app', 'android', 'ScreenShooter.jar');
var jarpath = path.resolve(process.env.ANDROID_HOME, "tools", "lib");
var classpath = "";
async.series([
function(cb) {
if (isWindows) {
classpath = path.resolve(jarpath, "ddmlib.jar") + ";" + path.resolve(jarpath, "x86", "swt.jar") + ";" + jar;
cb(null);
} else {
exec('uname -m', { maxBuffer: 524288 }, function (error, stdout, stderr) {
if (error) {
cb(error);
} else {
classpath = path.resolve(jarpath, "ddmlib.jar") + ":" + path.resolve(jarpath, stdout.trim(), "swt.jar") + ":" + jar;
cb(null);
}
});
}
me.proxy(["takeScreenshot"], cb);
},
function(cb) {
var javaCmd = 'java -classpath "' + classpath + '" io.appium.android.screenshooter.ScreenShooter ';
var cmd = javaCmd + me.adb.curDeviceId + ' "' + localfile + '"';
var cmd = me.adb.adbCmd + ' pull /data/local/tmp/screenshot.png "' + localfile + '"';
logger.debug("screenshot cmd: " + cmd);
exec(cmd, { maxBuffer: 524288 }, function(err, stdout, stderr) {
if (err) {