第一步:下载并安装wxPython
wxPython是RIDE需要的,注意的是必须安装unicode版本,点击下载列表,在列表中选择wxPython2.8-osx-unicode-2.8.12.1-universal-py2.7.dmg,下载后进行安装。
第二步:下载并安装RobotFramework
使用pip指令,具体为:pip install robotframework,当然前提条件是安装好了pip工具。
第三步:下载并安装RIDE
同样也采用pip install robotframework-ride
第四步:下载并安装Appium
http://appium.io/
安装依赖库
pip install robotframework-appiumlibrary
命令行执行ride.py开启ride程序,并打开Appium
创建一个项目,然后创建一个测试用例
编写测试用例,下面是我自己写的一个测试用例
*** Settings ***
Library AppiumLibrary
*** Variables ***
${REMOTE_URL} http://0.0.0.0:4723/wd/hub
${PLATFORM_NAME} iOS
${PLATFORM_VERSION} 10.3
${DEVICE_NAME} iPhone 7
${APP} /Users/XXX/Library/Developer/CoreSimulator/Devices/E0AEF040-37EB-45EA-A572-2AC010C73C3E/data/Containers/Bundle/Application/15390211-59E9-4966-B4AA-5A7082A7ACB0/DDApp.app
${User} 123@qq.com
${Password} 123456
*** Test Cases ***
Setup
Open Application remote_url=${REMOTE_URL} platformName=${PLATFORM_NAME} platformVersion=${PLATFORM_VERSION} deviceName=${DEVICE_NAME} app=${APP}
Swipe 500 200 100 200 500 #滑动
Swipe 500 200 100 200 500 #滑动
Sleep 2
Click Element xpath=//XCUIElementTypeApplication[@name="DDApp"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[1]/XCUIElementTypeOther[1] #点击立即体验
Sleep 2
Login
Input value //XCUIElementTypeApplication[@name="DDApp"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[1]/XCUIElementTypeTextField ${User}
Input Value //XCUIElementTypeApplication[@name="DDApp"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[1]/XCUIElementTypeSecureTextField ${Password}
Click Element name=登录
Click Element //XCUIElementTypeApplication[@name="DDApp"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[1]/XCUIElementTypeButton
sleep 5
SignOut
Click Element xpath=//XCUIElementTypeApplication[@name="DDApp"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther[1]/XCUIElementTypeOther[1]
Swipe 250 500 250 -200 500
Click Element //XCUIElementTypeApplication[@name="DDApp"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTable/XCUIElementTypeCell[14]
Click Element name=退出登录
Click Element name=确认
Click Element name=dd nav back nor
sleep 2
Teardown
Close All Applications
此时Appium作为桥梁会调起模拟器并安装App(可以在模拟器看到WebDriver程序,启动时自动安装,如果没有自动安装则无法调起程序)
接下来就按照测试用例跑,如果有些UI元素没有id,则需要用全路径获取,在Appium可以看到当前的UI,点击想要的元素就可以在右边的信息里看到全路径了