如何获取Appium中iOS设备显示的最大宽度和高度坐标?

我正在使用appium python-client库在iOS和Android设备上运行[py.]test.我注意到许多iOS测试都因点击点崩溃而不在屏幕范围内.由于提供的坐标似乎在设备显示的报告范围内,因此对测试进行调查似乎很奇怪.

以下代码段说明了我的问题:

from appium.webdriver.common.touch_action import TouchAction

def test_max_screen_size(appium_driver):

    driver = appium_driver

    window_size = driver.get_window_size()
    max_width = window_size["width"] - 1
    max_height = window_size["height"] - 1 

    action = TouchAction(driver)
    action.tap(None, max_width, max_height).perform()

在这里,我尝试点击显示的最极端.

此测试在Android设备上通过,但在iOS模拟器设备上未通过(我尚未测试真正的iOS设备-但我敢肯定它也会崩溃).

这是一个Appium错误还是我做错了什么?

我的环境:
鸦片1.3.4
iOS 8.1
current Appium Python client
Python 2.7.6

更新资料

我在这个问题上花了更多时间.

首先,我通过Instruments运行了这个简单的UIAutomation脚本:

var target = UIATarget.localTarget();
var max_width = target.rect().size.width;
var max_height = target.rect().size.height

UIALogger.logMessage("width: " + max_width + " height:" + max_height);

target.tap({x:max_width, y:max_height});

当您在iPhone 4s上运行此程序时,您将获得max_width = 320和max_height = 480,因为它是2x retina display-正是Appium告诉我们的以及期望的结果.

如果您增加了两个变量,则脚本将按预期方式失败,并出现以下情况:脚本引发了未捕获的JavaScript错误:点击点不在“新脚本”第8行的屏幕范围内.

这意味着Appium必须发送乐器不喜欢的东西.

因此,下一个故障点可能是appium python客户端.我使用pdb转到客户端与appium服务器对话的位置:

../remote_connection.py(349)execute()
-> return self._request(command_info[0], url, body=data)
(Pdb) l
344             command_info = self._commands[command]
345             assert command_info is not None, 'Unrecognised command %s' % command
346             data = utils.dump_json(params)
347             path = string.Template(command_info[1]).substitute(params)
348             url = '%s%s' % (self._url, path)
349  ->         return self._request(command_info[0], url, body=data)
350
351         def _request(self, method, url, body=None):
352             """
353             Send an HTTP request to the remote server.
354
(Pdb) url
u'http://127.0.0.1:4723/wd/hub/session/c9e49cb0-d291-4fb5-8aef-d89b9ceaa759/touch/perform'
(Pdb) data
'{"sessionId": "c9e49cb0-d291-4fb5-8aef-d89b9ceaa759", 
  "actions": [{"action": "tap", "options": {"y": 479, "x": 319, "count": 1}}]}'

这表明appium python客户端似乎也正在按照您的期望进行操作.

这使Appium服务器成为下一故障点…

解决方法:

好吧,经过一会儿的挖掘,我终于找到了答案.与可以在屏幕上进行相对于全屏的任意点击的Instruments不同,Appium选择将您限制在应用程序的范围之内.这意味着,如果显示菜单栏,它将通过菜单栏的高度减小您的可点击区域.

您可以在appium服务器日志中看到以下内容:

1  info: [debug] Got result from instruments: {"status":0,"value":{"width":320,"height":480}}
2  info: [debug] Responding to client with success: {"status":0,"value":{"width":320,"height":480},"sessionId":"b363bc3f-969b-4d7c-94e9-a504ffa08661"}
3  info: <-- GET /wd/hub/session/b363bc3f-969b-4d7c-94e9-a504ffa08661/window/current/size 200 90.756 ms - 98 {"status":0,"value":{"width":320,"height":480},"sessionId":"b363bc3f-969b-4d7c-94e9-a504ffa08661"}
4  info: --> POST /wd/hub/session/b363bc3f-969b-4d7c-94e9-a504ffa08661/touch/perform {"sessionId":"b363bc3f-969b-4d7c-94e9-a504ffa08661","actions":[{"action":"tap","options":{"y":479,"x":319,"count":1}}]}
5  info: [debug] Pushing command to appium work queue: "UIATarget.localTarget().frontMostApp().rect()"
6  info: [debug] Sending command to instruments: UIATarget.localTarget().frontMostApp().rect()
7  info: [debug] [INST] 2015-01-29 00:27:53 +0000 Debug: Got new command 8 from instruments: UIATarget.localTarget().frontMostApp().rect()
8  info: [debug] [INST] 2015-01-29 00:27:53 +0000 Debug: evaluating UIATarget.localTarget().frontMostApp().rect()
9  info: [debug] [INST] 2015-01-29 00:27:53 +0000 Debug: evaluation finished
10 info: [debug] [INST] 2015-01-29 00:27:53 +0000 Debug: responding with:
11 info: [debug] [INST] 2015-01-29 00:27:53 +0000 Debug: Running system command #9: /usr/local/Cellar/node/0.10.35_2/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":{"origin":{"x":0,"y":20},"size":{"width":320,"height":460}}}...
12 info: [debug] Socket data received (82 bytes)
13 info: [debug] Socket data being routed.
14 info: [debug] Got result from instruments: {"status":0,"value":{"origin":{"x":0,"y":20},"size":{"width":320,"height":460}}}
15 info: [debug] Pushing command to appium work queue: "UIATarget.localTarget().frontMostApp().tapWithOptions({\"tapOffset\":{\"x\":0.996875,\"y\":1.041304347826087},\"tapCount\":1,\"touchCount\":1})"
16 info: [debug] Sending command to instruments: UIATarget.localTarget().frontMostApp().tapWithOptions({"tapOffset":{"x":0.996875,"y":1.041304347826087},"tapCount":1,"touchCount":1})

在第2行中,您可以看到服务器如何响应设备分辨率.
在第14行中,您可以看到应用程序分辨率:320×460,在下面的行中,您可以看到我(现在是相对的)单击的实际位置:{“ x”:0.996875,“ y”:1.041304347826087}.

这是意外的,我希望API说明能够指出这一点-Appium中的选项卡是相对于应用程序窗口(而不是整个显示窗口)执行的.

长话短说

我现在必须使用< driver> .find_element_by_xpath(‘// UIAApplication [1]’).size替换iOS的< driver> .get_window_size().

上一篇:xcrun instruments -s devices


下一篇:康泰克采样器便携版-Native Instruments Kontakt 6.5.2 Portable WiN