5

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?

Ru Cindrea
  • 703
  • 2
  • 5
  • 16

5 Answers5

2

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);
Itai Bar-Haim
  • 1,686
  • 16
  • 40
san1deep2set3hi
  • 4,904
  • 1
  • 23
  • 23
  • `driver.manage().window().getSize()` only works in native view. Use `driver.context("NATIVE_APP")` to switch to native. This is a great approach to get the screensize in webview though! – Simon Baars Feb 13 '18 at 12:42
1

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!

Itai Bar-Haim
  • 1,686
  • 16
  • 40
Kevin Pick
  • 21
  • 4
0

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.

Gaurav
  • 1,332
  • 11
  • 22
  • I'm not sure I understand what you mean. How would the UDID help me? If you mean that I could use that to know the device size, it would still not help me because: 1. I still don't know the incorrect size that appium will report 2. I actually use a cloud service to run my tests, so I am running them on hundreds of devices and cannot have a special case for each... – Ru Cindrea Mar 20 '15 at 06:46
0

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 density screens have a 38dip height (HIGH_DPI_STATUS_BAR_HEIGHT = 38).
  • You can convert the "dip" value to pixels by multiplying by 2 (for xhdpi density screens). 76 pixels sounds pretty close!
Community
  • 1
  • 1
Dan J
  • 25,433
  • 17
  • 100
  • 173
0

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();