Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace deactivateApp and takeScreenshot with mechanic #45

Merged
merged 3 commits into from Jan 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/ios.js
Expand Up @@ -323,7 +323,7 @@ IOS.prototype.setOrientation = function(orientation, cb) {

IOS.prototype.getScreenshot = function(cb) {
var guid = uuid.create();
var command = ["takeScreenshot('screenshot", guid ,"')"].join('');
var command = ["au.capture('screenshot", guid ,"')"].join('');

var shotPath = ["/tmp/", this.instruments.guid, "/Run 1/screenshot", guid, ".png"].join("");
this.proxy(command, function(err, response) {
Expand Down
63 changes: 63 additions & 0 deletions app/uiauto/appium/app.js
@@ -0,0 +1,63 @@
/*global au:true $:true codes:true */
"use strict";
var au;

if (typeof au === "undefined") {
au = {};
}

$.extend(au, {
getScreenOrientation: function () {
var orientation = $.orientation()
, value = null;
switch (orientation) {
case UIA_DEVICE_ORIENTATION_UNKNOWN ||
UIA_DEVICE_ORIENTATION_FACEUP ||
UIA_DEVICE_ORIENTATION_FACEDOWN:
value = "UNKNOWN"; break;
case UIA_DEVICE_ORIENTATION_PORTRAIT ||
UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN:
value = "PORTRAIT"; break;
case UIA_DEVICE_ORIENTATION_LANDSCAPELEFT ||
UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT:
value = "LANDSCAPE"; break;
}
if (value !== null) {
return {
status: codes.Success.code,
value: value
};
} else {
return {
status: codes.UnknownError.code,
value: 'Unsupported Orientation: ' + orientation
};
}
}

, setScreenOrientation: function(orientation) {
if (orientation === "LANDSCAPE") {
$.orientation(UIA_DEVICE_ORIENTATION_LANDSCAPELEFT);
} else if (orientation === "PORTRAIT") {
$.orientation(UIA_DEVICE_ORIENTATION_PORTRAIT);
} else {
return {
status: codes.UnknownError.code,
value: 'Unsupported orientation: ' + orientation
};
}
var newOrientation = au.getScreenOrientation();
if (newOrientation == orientation) {
return {
status: codes.Success.code
, value: newOrientation
};
} else {
console.log("returning error");
return {
status: codes.UnknownError.code
, value: "Orientation change did not take effect"
};
}
}
});
66 changes: 2 additions & 64 deletions app/uiauto/appium/base.js
Expand Up @@ -22,18 +22,12 @@
#import "../lib/mechanic.js"
#import "../lib/status.js"
#import "utility.js"
#import "app.js"
#import "binding.js"
// TODO: rewrite this entire file using helper methods from mechanic?



// Misc utils

/* Deactivating the app for specified duration in Seconds.
Useful to test multi-taskig (moving app to background) */
function deactivateApp(timeInSeconds){
$.backgroundApp(timeInSeconds);
}

UIAElementNil.prototype.type = function() {
return "UIAElementNil";
}
Expand Down Expand Up @@ -281,63 +275,7 @@ UIAElement.prototype.getPageSource = function() {
};
}

// screenshot

function takeScreenshot(file) {
var screenshot = UIATarget.localTarget().captureScreenWithName(file);
return {
status: codes.Success.code,
value: screenshot
};
}

// screen orientation

function getScreenOrientation() {
var orientation = UIATarget.localTarget().deviceOrientation()
, value = null
switch (orientation) {
case UIA_DEVICE_ORIENTATION_UNKNOWN:
value = "UNKNOWN";
case UIA_DEVICE_ORIENTATION_PORTRAIT:
value = "PORTRAIT";
case UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN:
value = "PORTRAIT";
case UIA_DEVICE_ORIENTATION_LANDSCAPELEFT:
value = "LANDSCAPE";
case UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT:
value = "LANDSCAPE";
case UIA_DEVICE_ORIENTATION_FACEUP:
value = "UNKNOWN";
case UIA_DEVICE_ORIENTATION_FACEDOWN:
value = "UNKNOWN";
}
if (value !== null) {
return {
status: codes.Success.code,
value: value
};
} else {
return {
status: codes.UnknownError.code,
value: 'Unsupported Orientation: ' + orientation
};
}
}

function setScreenOrientation(orientation) {
var target = UIATarget.localTarget();
if (orientation === "LANDSCAPE")
target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_LANDSCAPELEFT);
else if (orientation === "PORTRAIT")
target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT);
else
return {
status: codes.UnknownError.code,
value: 'Unsupported orientation: ' + orientation
};
return getScreenOrientation();
}

// getText

Expand Down
9 changes: 9 additions & 0 deletions app/uiauto/appium/binding.js
@@ -0,0 +1,9 @@
/*global au:true $:true */
"use strict";
var au;

if (typeof au === "undefined") {
au = {};
}

$.extend(au, $);
2 changes: 1 addition & 1 deletion grunt.js
Expand Up @@ -15,7 +15,7 @@ module.exports = function(grunt) {

grunt.initConfig({
lint: {
all: ['*.js', 'app/*.js', 'app/test/unit/*.js', 'instruments/*.js', 'test/functional/*.js', 'test/unit/*.js', 'test/uicatalog/*.js', 'test/helpers/*.js']
all: ['*.js', 'app/*.js', 'app/test/unit/*.js', 'instruments/*.js', 'test/functional/*.js', 'test/unit/*.js', 'test/uicatalog/*.js', 'test/helpers/*.js', 'test/appiumutils/*.js']
}
, jshint: {
all: {
Expand Down
27 changes: 27 additions & 0 deletions test/appiumutils/appiumutils.js
Expand Up @@ -50,6 +50,7 @@ describe("appiumutils", function() {
it('should get device details', function(done) {
device.proxy("au.getDeviceDetail()", function(err, res) {
should.not.exist(err);
res.status.should.equal(0);
should.exist(res.value.deviceName);
should.exist(res.value.deviceModel);
should.exist(res.value.systemName);
Expand All @@ -58,4 +59,30 @@ describe("appiumutils", function() {
});
});

it('should background the app', function(done) {
device.proxy("au.backgroundApp(2)", function(err, res) {
should.not.exist(err);
res.status.should.equal(0);
done();
});
});

it('should get orientation', function(done) {
device.proxy("au.getScreenOrientation()", function(err, res) {
should.not.exist(err);
res.status.should.equal(0);
res.value.should.equal("PORTRAIT");
done();
});
});

// this seems to be broken!
//it('should set orientation', function(done) {
//device.proxy("au.setScreenOrientation('LANDSCAPE')", function(err, res) {
//should.not.exist(err);
//res.status.should.equal(0);
//done();
//});
//});

});