diff --git a/app/controller.js b/app/controller.js index ff75d91ed..984520a8c 100644 --- a/app/controller.js +++ b/app/controller.js @@ -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)); diff --git a/app/ios.js b/app/ios.js index 6b8ec1878..4ccc3625a 100644 --- a/app/ios.js +++ b/app/ios.js @@ -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); diff --git a/app/routing.js b/app/routing.js index f7baafd79..fb5d213bf 100644 --- a/app/routing.js +++ b/app/routing.js @@ -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); diff --git a/app/uiauto/appium/app.js b/app/uiauto/appium/app.js index 374b5f738..d771f764d 100644 --- a/app/uiauto/appium/app.js +++ b/app/uiauto/appium/app.js @@ -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) { diff --git a/sample-code/examples/ruby/simple_test.rb b/sample-code/examples/ruby/simple_test.rb index 1577c48ad..710fa2c9a 100644 --- a/sample-code/examples/ruby/simple_test.rb +++ b/sample-code/examples/ruby/simple_test.rb @@ -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 diff --git a/test/functional/testapp/size.js b/test/functional/testapp/size.js index 2cf7df0a2..97dff5cb8 100644 --- a/test/functional/testapp/size.js +++ b/test/functional/testapp/size.js @@ -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(); + }); + }); +});