主流的移动端自动化工具
- Robotium
1.支持语言:Java
2.仅支持Android系统
3.不支持跨应用
- Macaca
1.支持语言:Java,Python,Node.js
2.支持Android和iOS系统
3.支持跨应用
- Appium
1.支持语言:Java,C#,Python,php,perl,ruby,Node.js
2.支持Android和iOS系统
3.支持跨应用
- 自动化工具选择的关注点
1.是否支持native,webview
2.是否支持获取toast
3.是否支持跨应用
Appium环境搭建
-
2.2.1 Appium客户端安装
-
2.2.1.1 Appium背景介绍
1.官网:www.appium.io,由SauceLab公司开发 2.Appium是由nodejs的express框架写的Http Server,Appium使用WebDriver的json wire协议, 来驱动Apple系统的UIAutomation库、Android系统的UIAutomator框架
-
2.2.1.2 Appium桌面客户端安装方式
-
1. 运行appium-desktop-Setup-1.2.7.exe,默认安装即可 2. 启动客户端,按图片步骤 1 -> 2 -> 3 -> 4 设置
3. 启动成功展示如下图
-
# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python
from appium.webdriver.common.touch_action import TouchAction #需要导入 TouchAction
from appium import webdriver
import time
caps = {}
caps["deviceName"] = "127.0.0.1:62001"
caps["platformName"] = "Android"
caps["appPackage"] = "com.android.settings"
caps["appActivity"] = "com.android.settings.Settings"
driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
#脚本操作搜索
# e13=driver.find_element_by_xpath('//android.widget.TextView[@content-desc="搜索"]')
# # el3 = driver.find_element_by_accessibility_id("搜索")
# e13.click()
# time.sleep(2)
# el4 = driver.find_element_by_id("android:id/search_src_text")
# el4.send_keys("123123")
#swip滑动事件 duration毫秒 从一个坐标位置滑动到另一个坐标位置,只能是两个点之间的滑动
# driver.swipe(178,1155,178,329,duration=3000)
#scroll滑动事件 从一个元素滑动到另一个元素,直到页面自动停止
# cc=driver.find_element_by_xpath("//*[contains(@text,'存储')]")
# wlan=driver.find_element_by_xpath("//*[contains(@text,'WLAN')]")
# driver.scroll(cc,wlan,duration=3000)
# drag拖拽事件 从一个元素滑动到另一个元素,第二个元素替代第一个元素原本屏幕上的位置
# cc=driver.find_element_by_xpath("//*[contains(@text,'存储')]")
# wlan=driver.find_element_by_xpath("//*[contains(@text,'WLAN')]")
# driver.drag_and_drop(cc,wlan)
# driver.quit()
#APP模拟手势高级操作 手指轻敲操作
# wlan=driver.find_element_by_xpath("//*[contains(@text,'WLAN')]")
# TouchAction(driver).tap(wlan).perform()
# time.sleep(2)
# #长按操作
# ca=driver.find_element_by_id('android:id/title')
# #第一种方式
# # TouchAction(driver).press(ca).wait(4000).perform()
# #第二种
# TouchAction(driver).long_press(ca,duration=4000).perform()
# driver.quit()
#多元素操作
# lists=driver.find_elements_by_class_name('android.widget.TextView')
# # print(lists)
# for i in lists:
# print(i.text)
#点击屏幕锁定方式
#wlan
wlan=driver.find_element_by_xpath("//*[contains(@text,'WLAN')]")
#存储
cc=driver.find_element_by_xpath("//*[contains(@text,'存储')]")
driver.scroll(cc,wlan,duration=3000)
#安全
anquan=driver.find_element_by_xpath("//*[contains(@text,'安全')]")
anquan.click()
time.sleep(2)
#屏幕锁定方式
pmsd=driver.find_element_by_xpath("//*[contains(@text,'屏幕锁定方式')]")
#178,624 178,980 178 1340 537,1337
pmsd.click()
time.sleep(2)
TouchAction(driver).press(x=178,y=624).wait(1000).move_to(x=178,y=980).wait(1000).move_to(x=178,y=1340).wait(1000).move_to(x=537,y=1337).release().perform()
driver.quit()