【移动测试ios】编写和运行自动化脚本
准备工作
1.使用Xcode打开要运行的程序 2.选择将要运行的程序和模拟器设备 3.command+r运行 4.打开并启动appium 5.appium session 元素定位
编写和运行自动化脚本
import time
from appium import webdriver
desired_caps = dict()
desired_caps[platformName] = iOS
desired_caps[platformVersion] = 12.1
desired_caps[deviceName] = iPhone 8
desired_caps[app] = com.itcast.HMiOSTest
driver = webdriver.Remote(http://localhost:4723/wd/hub, desired_caps)
# 真机需要使用的参数
desired_caps[udid] = 00008030-*
# 点击进入列表
driver.find_element_by_id("进入列表").click()
# 在控制台输出所有的文字内容
# 在Android中只会查找到屏幕上所显示的控件,ios中都会找到控件,但如果进行操作,也同样需要展示在屏幕上
# text_views = driver.find_elements_by_class_name("XCUIElementTypeStaticText")
# for text_view in text_views:
# print(text_view.text)
# 滑动一次
# driver.swipe(100,500,100,200)
driver.execute_script("mobile:swipe", {
"direction": "up"})
# 点击20
driver.find_element_by_xpath("//*[@name=20]").click()
# 清空文本框
text_field = driver.find_element_by_class_name("XCUIElementTypeTextField")
text_field.clear()
# 输入hello
text_field.send_keys("hello!!!")
# 点击返回
driver.find_element_by_xpath("//*[@name=Back]").click()
time.sleep(5)
driver.quit()
上一篇:
5款热门的远程控制软件,让你事半功倍
下一篇:
计算机测试新机,检测电脑是否是新机的方法
