【发布时间】:2015-03-27 18:12:41
【问题描述】:
我正在使用 appium python-client 库在 iOS 和 Android 设备上运行 [py.]test。我注意到许多 iOS 测试在使用 tap point is not within the bounds of the screen 时崩溃了。查看测试似乎很奇怪,因为提供的坐标似乎在设备显示的报告范围内。
下面的 sn-p 说明了我的问题:
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 错误还是我做错了什么?
我的环境:
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 告诉我们的内容和预期的内容。
如果您增加任一变量,脚本将按预期失败:Script threw an uncaught JavaScript error: tap point is not within the bounds of the screen on line 8 of New Script。
这意味着 Appium 必须发送 Instruments 不喜欢的东西。
因此,下一个故障点可能是 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 服务器成为下一个故障点...
【问题讨论】:
标签: python ios instruments appium pytest