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

set stage for rearchitecture of appiumutils.js #44

Merged
merged 1 commit 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
20 changes: 6 additions & 14 deletions app/uiauto/lib/appiumutils.js → app/uiauto/appium/base.js
Expand Up @@ -19,20 +19,12 @@
* under the License. * under the License.
*/ */


#import "mechanic.js" #import "../lib/mechanic.js"
#import "status.js" #import "../lib/status.js"
#import "utility.js"
// TODO: rewrite this entire file using helper methods from mechanic? // TODO: rewrite this entire file using helper methods from mechanic?


// Obtaining Device Property Information like Name, OS ver, Model etc


function getDeviceDetail() {
var deviceMap = new Object();
deviceMap['deviceName'] = UIATarget.localTarget().name();
deviceMap['deviceModel'] = UIATarget.localTarget().model();
deviceMap['systemName'] = UIATarget.localTarget().systemName();
deviceMap['systemVersion'] = UIATarget.localTarget().systemVersion();
return deviceMap;
}


// Misc utils // Misc utils


Expand Down Expand Up @@ -540,22 +532,22 @@ UIAElement.prototype.touchFlick = function(xoffset, yoffset) {


// alerts // alerts


getAlertText = function() { var getAlertText = function() {
return { return {
status: codes.Success.code, status: codes.Success.code,
value: target.frontMostApp().alert().name() value: target.frontMostApp().alert().name()
}; };
} }


acceptAlert = function() { var acceptAlert = function() {
target.frontMostApp().alert().defaultButton().tap() target.frontMostApp().alert().defaultButton().tap()
return { return {
status: codes.Success.code, status: codes.Success.code,
value: null value: null
}; };
} }


dismissAlert = function() { var dismissAlert = function() {
target.frontMostApp().alert().cancelButton().tap() target.frontMostApp().alert().cancelButton().tap()
return { return {
status: codes.Success.code, status: codes.Success.code,
Expand Down
19 changes: 19 additions & 0 deletions app/uiauto/appium/utility.js
@@ -0,0 +1,19 @@
/*global au:true $:true UIATarget:true */
"use strict";
var au;

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

$.extend(au, {
// Obtaining Device Property Information like Name, OS ver, Model etc
getDeviceDetail: function() {
return {
deviceName: UIATarget.localTarget().name()
, deviceModel: UIATarget.localTarget().model()
, systemName: UIATarget.localTarget().systemName()
, systemVersion: UIATarget.localTarget().systemVersion()
};
}
});
4 changes: 1 addition & 3 deletions app/uiauto/bootstrap.js
@@ -1,8 +1,6 @@
#import "lib/console.js" #import "lib/console.js"
#import "lib/instruments_client.js" #import "lib/instruments_client.js"
#import "lib/delay.js" #import "appium/base.js"
#import "lib/appiumutils.js"
#import "lib/status.js"


// automation globals // automation globals
var target = UIATarget.localTarget(); var target = UIATarget.localTarget();
Expand Down
5 changes: 4 additions & 1 deletion app/uiauto/lib/status.js
Expand Up @@ -100,4 +100,7 @@ var codes = {
summary: 'Target provided for a move action is out of bounds.' summary: 'Target provided for a move action is out of bounds.'
} }
}; };
module.exports.codes = codes;
if (typeof module !== "undefined") {
module.exports.codes = codes;
}
4 changes: 3 additions & 1 deletion grunt.js
Expand Up @@ -30,6 +30,7 @@ module.exports = function(grunt) {
} }
, mochaTest: { , mochaTest: {
unit: ['app/test/unit/*.js'] unit: ['app/test/unit/*.js']
, appiumutils: ['test/appiumutils/*.js']
} }
, mochaTestWithServer: { , mochaTestWithServer: {
TestApp: { TestApp: {
Expand All @@ -55,8 +56,9 @@ module.exports = function(grunt) {
grunt.registerTask('uicatalog', "Run UICatalog tests", function(log) { grunt.registerTask('uicatalog', "Run UICatalog tests", function(log) {
runTestsWithServer(grunt, 'UICatalog', 'uicatalog', log === "log", this.async()); runTestsWithServer(grunt, 'UICatalog', 'uicatalog', log === "log", this.async());
}); });
grunt.registerTask('test', 'lint buildApp:TestApp buildApp:UICatalog unit functional uicatalog'); grunt.registerTask('test', 'lint buildApp:TestApp buildApp:UICatalog unit appiumutils functional uicatalog');
grunt.registerTask('unit', 'mochaTest:unit'); grunt.registerTask('unit', 'mochaTest:unit');
grunt.registerTask('appiumutils', 'mochaTest:appiumutils');
grunt.registerTask('default', 'lint test'); grunt.registerTask('default', 'lint test');
grunt.registerTask('appium', "Start the Appium server", function(appName) { grunt.registerTask('appium', "Start the Appium server", function(appName) {
if (typeof appName === "undefined") { if (typeof appName === "undefined") {
Expand Down
61 changes: 61 additions & 0 deletions test/appiumutils/appiumutils.js
@@ -0,0 +1,61 @@
/*global it:true, describe:true, before:true, after:true, beforeEach:true */
/*global afterEach:true */
"use strict";

var runServer = require("../../server.js").run
, should = require("should")
, path = require("path");

describe("appiumutils", function() {

var appium = null;
var device = null;
var server = null;
var onServerClose = function() {};

before(function(done) {
server = runServer({
app: path.resolve(__dirname, "../../sample-code/apps/UICatalog/build/Release-iphonesimulator/UICatalog.app")
, verbose: false
, udid: null
, port: 4723
, address: '127.0.0.1'
, remove: true }
, function(appiumServer) {
appium = appiumServer;
done();
}
, function() {
onServerClose();
}
);
});

beforeEach(function(done) {
appium.start({}, function() {
device = appium.device;
done();
});
});

afterEach(function(done) {
appium.stop(done);
});

after(function(done) {
onServerClose = done;
server.close();
});

it('should get device details', function(done) {
device.proxy("au.getDeviceDetail()", function(err, res) {
should.not.exist(err);
should.exist(res.value.deviceName);
should.exist(res.value.deviceModel);
should.exist(res.value.systemName);
should.exist(res.value.systemVersion);
done();
});
});

});