Reputation: 733
I am running some tests with Appium 1.3.2 on a game. I am trying to click on the bottom right corner on an element that I know the coordinates for and on many devices I run into the problem that Appium reports that the coordinates are invalid because they are outside the screen.
I checked the size that Appium reports using:
driver.manage().window().getSize()
and noticed that the reported window size is 886x540 on a device that really has a resolution of 960x540.
Also just trying to click on the bottom right corner produces the following in Appium logs:
[36minfo[39m: [debug] Pushing command to appium work queue ["element:touchDown",{"x":889,"y":473}]
[36minfo[39m: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:touchDown","params":{"x":889,"y":473}}
[36minfo[39m: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
[36minfo[39m: [debug] [BOOTSTRAP] [debug] Got command action: touchDown
[36minfo[39m: [debug] [BOOTSTRAP] [debug] Display bounds: [0,0][886,540]
[36minfo[39m: [debug] [BOOTSTRAP] [debug] Returning result: {"value":"Coordinate [x=889.0, y=473.0] is outside of element rect: [0,0][886,540]","status":29}
[36minfo[39m: [debug] Responding to client with error: {"status":29,"value":{"message":"The coordinates provided to an interactions operation are invalid.","origValue":"Coordinate [x=889.0, y=473.0] is outside of element rect: [0,0][886,540]"},"sessionId":"8d43efa4-931a-4886-8940-4bd96fea3d07"}
The game I am testing is running in full screen mode, and if I take a screenshot and check it, the screenshot size is 960x540, with the game taking up the whole screen, no menu items and no buttons anywhere.
I have seen the same problem with other resolutions as well, where Appium simply reports that the size of the screen is smaller than it actually is.
Has anyone else run into this? Is there a workaround?
Upvotes: 5
Views: 12670
Reputation: 86
If this can be useful to anybody, here is a piece of java code to retrieve Android status bar and navigation bar heights from Appium:
//get System bars height
JsonParser parser = new JsonParser();
JsonObject jsonObject = (JsonObject) parser.parse(driver.getSystemBars().toString());
JsonObject jsonObject2 = (JsonObject) parser.parse(jsonObject.getAsJsonObject("statusBar").toString());
JsonObject jsonObject3 = (JsonObject) parser.parse(jsonObject.getAsJsonObject("navigationBar").toString());
statusBarHeight = jsonObject2.get("height").getAsInt();
navigationBarHeight = jsonObject3.get("height").getAsInt();
Upvotes: 0
Reputation: 5134
Well I am testing in Android Chrome browser and there somehow driver.manage().window().getSize()
is not working.
So I took following approach:
JavascriptExecutor js = (JavascriptExecutor) driver;
int width = ((Long) js.executeScript("return window.innerWidth || document.body.clientWidth")).intValue();
LLLogs.getLogger().info("width value calculated is :" + width);
int height = ((Long) js.executeScript("return window.innerHeight || document.body.clientHeight")).intValue();
LLLogs.getLogger().info("height value calculated is :" + height);
Dimension dimension = new Dimension(width, height);
Upvotes: 2
Reputation: 31
I've looked into this fairly extensively and it seems as though the screen size obtained from driver.manage().window().getSize()
is the "useable" portion of the screen which excludes the region at the bottom where the back, home, and "show running apps" buttons are.
For example, my screen height is 1280. driver.manage().window().getSize()
returns 1184 in height. I measured the "button" region at the bottom of the screen and it came out to 96 pixels high, which is perfectly consistent with this explanation.
On the other hand, the status bar (for my device) is 48 pixels. This is no where near tall enough to explain the discrepancy.
Also, when you do the math for this example, you get that the status bar is 3.75% (exactly) of the full screen and the "button bar" is 7.5% (exactly). Using these percentages with your screen height of 960 returns a "button bar" height of 72 pixels with the remainder of the screen being 888 pixels. I hope this info helps you in some way!
Upvotes: 2
Reputation: 25673
It sounds like the screen size being reported to you excludes the Android status bar at the top of the screen.
If you combine this answer with this answer, it gets very close to explaining your missing 74 pixels:
HIGH_DPI_STATUS_BAR_HEIGHT = 38
). Upvotes: 0
Reputation: 1370
I did run with issues on different android devices. In my case, i just passed the different steps/test for that particular device by pulling the UDID of the device at run time.
Upvotes: 0