刚接触 iOS 自动化测试,参考网上的经验一步步摸索,目前在尝试用 Python 编写自动化测试脚本测试 APP UI 相关功能。现在想进行删除设备的操作,其操作步骤和 QQ 中删除和某一对象会话的步骤一样:选中对象,向左滑一小步,然后点击滑动后出现的删除按钮,即可删除。对于左滑操作,我用的是 swipe,代码如下:
def choice_TheDevice(driver):
if driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]').is_displayed():
el = driver.find_element_by_xpath('//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[1]')
el.swipe(150,108,90,108)
sleep(3)
报错为:
AttributeError: 'WebElement' object has no attribute 'swipe'
在执行这个函数前,已经 Sleep 了足够的时间,swipe 中的坐标都是绝对坐标,且没有超出对应控件滑动范围。在 testcase 里也进行了 webdriver 的导入:
from selenium import webdriver
from appium import webdriver
Appium log 如下:
[debug] [UIAuto] Socket data received (6359 bytes)
[debug] [UIAuto] Got result from instruments: {"status":0,"value":{"UIAApplication":{"@":{"name":"campus","label":"campus","value":null,"dom":null,"enabled":true,"valid":true,"visible":true,"hint":null,"path":"/0","x":0,"y":0,"width":375,"height":667},">":[{"UIAWindow":{"@":{"name":null,"label":null,"value":null,"dom":null,"enabled":true,"valid
[debug] [UIAuto] Sending command to instruments: au.getElementByIndexPath('/0/0/3/0')
[debug] [Instruments] [INST] 2016-09-18 05:17:17 +0000 Debug: Got new command 63 from instruments: au.getElementByIndexPath('/0/0/3/0')
[debug] [Instruments] [INST] 2016-09-18 05:17:17 +0000 Debug: evaluating au.getElementByIndexPath('/0/0/3/0')
2016-09-18 05:17:17 +0000 Debug: evaluation finished
[debug] [Instruments] [INST] 2016-09-18 05:17:17 +0000 Debug: Lookup returned [object UIATableCell] with the name "我的设备" (id: 16).
[debug] [Instruments] [INST] 2016-09-18 05:17:17 +0000 Debug: responding with:
[debug] [Instruments] [INST] 2016-09-18 05:17:17 +0000 Debug: Running system command #64: /Volumes/Appium/Appium.app/Contents/Resources/node/bin/node /Volumes/Appium/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-ios-driver/node_modules/appium-uiauto/build/lib/bin/command-proxy-client.js /var/folders/tf/89068tvn199bhwpk5r3hg03h0000gn/T/instruments_sock 2,{"status":...
[debug] [UIAuto] Socket data received (39 bytes)
[debug] [UIAuto] Got result from instruments: {"status":0,"value":{"ELEMENT":"16"}}
[MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"16"}
[HTTP] <-- POST /wd/hub/session/4af2e2fb-8c7a-4cd0-bfcd-72764252b2db/element 200 2185 ms - 88
[HTTP] --> POST /wd/hub/session/4af2e2fb-8c7a-4cd0-bfcd-72764252b2db/appium/app/close {"sessionId":"4af2e2fb-8c7a-4cd0-bfcd-72764252b2db"}
[MJSONWP] Calling AppiumDriver.closeApp() with args: ["4af2e2fb-8c7a-4cd0-bfcd-7...
[debug] [iOS] Executing iOS command 'closeApp'
[debug] [UIAuto] Destroying instruments client socket.
[debug] [UIAuto] Closing socket server.
[debug] [UIAuto] Instruments socket server was closed
[debug] [Instruments] Starting shutdown.
[debug] [Instruments] Sending sigterm to instruments
[debug] [Instruments] [INST] 2016-09-18 05:17:17 +0000 Stopped: Script was stopped by the user
[debug] [Instruments] [INST STDERR] 2016-09-17 22:17:17.661 instruments[4896:58240] Attempting to change event horizon while disengage
[debug] [Instruments] [INST] Instruments Trace Complete (Duration : 132.406662s; Output : /var/folders/tf/89068tvn199bhwpk5r3hg03h0000gn/T/appium-instruments/instrumentscli0.trace)
[debug] [Instruments] Instruments exited with code 0
[debug] [iOSLog] Stopping iOS log capture
[iOS] Successfully closed the [/Users/wanqingyao/Desktop/campus.app] app.
[MJSONWP] Responding to client with driver.closeApp() result: null
[HTTP] <-- POST /wd/hub/session/4af2e2fb-8c7a-4cd0-bfcd-72764252b2db/appium/app/close 200 1922 ms - 76
[HTTP] --> DELETE /wd/hub/session/4af2e2fb-8c7a-4cd0-bfcd-72764252b2db {}
[MJSONWP] Calling AppiumDriver.deleteSession() with args: ["4af2e2fb-8c7a-4cd0-bfcd-7...
[debug] [iOS] Deleting ios session
[debug] [iOS] Running ios sim reset flow
[debug] [iOS] Killing the simulator
[debug] [iOSSim] Killing all iOS Simulators
我在想出现这个报错是不是因为测试框架版本的原因(之前通过 find_element_by_name 查找元素各种报错,后来才知道新版本的 Appium 已经取消了通过 name 查找元素这个方法),现把版本信息贴出如下:
version:
VMware12.1.1
os x 10.11.6
xcode 7.1 beta
appium 1.5.3
python2.7
node-v4.4.7
看了各种类似问题的帖子,上面的解决办法都尝试过了也无法解决问题。求各位大神指导,感激不尽!