allow getting screen size through selenium /window/size

This commit is contained in:
Jonathan Lipps
2013-02-12 11:52:11 -08:00
parent b67988d662
commit 31f14c81eb
6 changed files with 48 additions and 3 deletions
+5
View File
@@ -295,6 +295,11 @@ exports.getSize = function(req, res) {
req.device.getSize(elementId, getResponseHandler(req, res));
};
exports.getWindowSize = function(req, res) {
var windowHandle = req.params.windowhandle;
req.device.getWindowSize(windowHandle, getResponseHandler(req, res));
};
exports.getPageIndex = function(req, res) {
var elementId = req.params.elementId;
req.device.getPageIndex(elementId, getResponseHandler(req, res));
+15
View File
@@ -445,6 +445,21 @@ IOS.prototype.getSize = function(elementId, cb) {
}
};
IOS.prototype.getWindowSize = function(windowHandle, cb) {
if (this.curWindowHandle) {
cb(new NotImplementedError(), null);
} else {
if(windowHandle !== "current") {
cb(null, {
status: status.codes.NoSuchWindow.code
, value: "Can only get the status of the current window"
});
} else {
this.proxy("au.getWindowSize()", cb);
}
}
};
IOS.prototype.getPageIndex = function(elementId, cb) {
var command = ["au.getElement('", elementId, "').pageIndex()"].join('');
this.proxy(command, cb);
+1 -1
View File
@@ -53,6 +53,7 @@ module.exports = function(appium) {
rest.get('/wd/hub/session/:sessionId?/window_handle', controller.getWindowHandle);
rest.get('/wd/hub/session/:sessionId?/window_handles', controller.getWindowHandles);
rest.post('/wd/hub/session/:sessionId?/window', controller.setWindow);
rest.get('/wd/hub/session/:sessionId?/window/:windowhandle?/size', controller.getWindowSize);
rest.post('/wd/hub/session/:sessionId?/execute', controller.execute);
rest.get('/wd/hub/session/:sessionId?/title', controller.title);
@@ -94,7 +95,6 @@ var routeNotYetImplemented = function(rest) {
rest.post('/wd/hub/session/:sessionId?/ime/activate', controller.notYetImplemented);
rest.delete('/wd/hub/session/:sessionId?/window', controller.notYetImplemented);
rest.post('/wd/hub/session/:sessionId?/window/:windowhandle/size', controller.notYetImplemented);
rest.get('/wd/hub/session/:sessionId?/window/:windowhandle/size', controller.notYetImplemented);
rest.post('/wd/hub/session/:sessionId?/window/:windowhandle/position', controller.notYetImplemented);
rest.get('/wd/hub/session/:sessionId?/window/:windowhandle/position', controller.notYetImplemented);
rest.post('/wd/hub/session/:sessionId?/window/:windowhandle/maximize', controller.notYetImplemented);
+9 -1
View File
@@ -14,7 +14,7 @@ $.extend(au, {
, mainApp: UIATarget.localTarget().frontMostApp()
, keyboard: function() { return UIATarget.localTarget().frontMostApp().keyboard(); }
// Screen orientation functions
// Screen-related functions
, getScreenOrientation: function () {
var orientation = $.orientation()
@@ -70,6 +70,14 @@ $.extend(au, {
}
}
, getWindowSize: function() {
var size = this.target.rect().size;
return {
status: codes.Success.code
, value: size
};
}
// Element lookup functions
, lookup: function(selector, ctx) {
+6
View File
@@ -96,4 +96,10 @@ describe "Computation" do
alerts.should be_empty
end
it "should get window size" do
size = @driver.manage.window.size
size.width.should eq(320)
size.height.should eq(480)
end
end
+12 -1
View File
@@ -4,7 +4,7 @@
var describeWd = require('../../helpers/driverblock.js').describeForApp('TestApp')
, should = require('should');
describeWd('check size', function(h) {
describeWd('element size', function(h) {
return it('should return the right width and height', function(done) {
h.driver.elementByTagName('button', function(err, element) {
should.not.exist(err);
@@ -18,3 +18,14 @@ describeWd('check size', function(h) {
});
});
});
describeWd('window size', function(h) {
return it('should return the right width and height', function(done) {
h.driver.getWindowSize(function(err, size) {
should.not.exist(err);
size.width.should.equal(320);
size.height.should.equal(480);
done();
});
});
});