测开学习DAY39

黑马程序员网课学习(Appium框架)

IOS

一、使用模拟器进行自动化测试

1. 运行 iOS 程序到模拟器

(1)使用 Xcode 打开要运行的程序

(2)选择将要运行的 程序 和 模拟器设备

(3)快捷键 command + r 运行

2. 查看 iOS 元素特征

(1)打开 appium

(2)启动 appium

(3)左上角菜单栏选择 appium - new session window

3. 编写和运行自动化脚本

python 复制代码
import time

from appium import webdriver

desired_caps = dict()
desired_caps['platformName'] = 'iOS'
desired_caps['platformVersion'] = '12.1.2'
desired_caps['deviceName'] = 'iPhone 6s Plus'
desired_caps['app'] = 'com.itcast.HMiOSTest'

# 真机需要使用的参数
desired_caps['udid'] = 'cda2396af94373603f21f071c322b957246cbd7f'

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

# 点击 进入列表
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, 2000, 100, 1000)
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()

二、使用真机进行自动化测试

1. 运行 iOS 程序到真机

(1)在 Xcode 中登录自己的 Apple ID

(2)配置开发者信息

(3)选择将要运行的 程序 和 设备

(4)快捷键 command + r 运行

(5)在手机中进入 设置 - 通用 - 设备管理 - 自己Apple ID - 信任程序

(6)重新 command + r 运行

2. 配置 WebDriverAgent

(1)进入到下载的 WebDriverAgent 项目下

(2)输入命令 ./Scripts/bootstrap.sh

(3)启动 WebDriverAgent.xcodeproj

(4)配置 WebDriverAgentLib 的开发者信息

(5)配置 WebDriverAgentRunner 的开发者信息

(6)配置 IntegrationApp 的开发者信息

(7)修改 WebDriverAgentRunner 的 Product Bundle Identifier

(8)修改 IntegrationApp 的 Product Bundle Identifier

(9)数据线连接真机

(10)选择将要运行的 WebDriverAgentRunner 和 真机设备

(11)使用 command + u 运行

  • 稍等之后会在log中出来一个 url 地址
  • 在浏览器中打开这个地址,如果显示一串 json 数据即为正确连接手机
  • 并且,真机会多一个程序

(12)将配置好的 WebDriverAgent 项目替换到 appium 的 WebDriverAgent 项目

  • 打开 finder
  • 快捷键 command + shift + g
  • 输入路径 /Applications/Appium.app/Contents/Resources/app/node_modules/appiumxcuitest-driver
  • 回车
  • 将旧项目换个名字,当做备份
  • 将配置好的项目放在这个目录下

3. 运行自动化脚本

(1)修改对应的 platformVersion、deviceName

(2)查看 udid 并增加为启动参数

(3)运行即可

刷题记录:

1. 两数之和

相关推荐
叼烟扛炮9 小时前
[LangChain] 学习笔记(026):模型根本没有记忆——「多轮对话」是你每次把历史重发一遍
笔记·学习·langchain
MSTcheng.14 小时前
【LinuxIO篇】Linux学习第二十三弹——fopen和open有什么区别?从 FILE* 到 fd,讲透 Linux 文件 IO
linux·运维·学习·io·系统调用·fd
Z21-X16 小时前
云原生运维学习笔记:Kubernetes Service 发现、类型与 kube-proxy 实战
运维·笔记·学习·云原生·kubernetes
sealaugh3216 小时前
powerbi学习笔记(day2)powerbi进阶
笔记·学习·powerbi
叼烟扛炮2 天前
[LangChain] 学习笔记(24):流式不改总耗时,只改「多久看到第一个字」——实测差 3 倍
笔记·学习·langchain
半扇排骨2 天前
特别篇:在线 XSS 靶场 haozi 分享与通关笔记
学习·安全·靶场·xss
艾莉丝努力练剑3 天前
【AI接入大模型SDK】解决接口连接异常问题
前端·c++·人工智能·学习·ai·架构
Severus_black3 天前
【C++初阶】模板进阶
c语言·c++·学习
紫金修道3 天前
【机械臂视觉】学习笔记一:相机成像模型与内参标定
笔记·数码相机·学习
旖旎夜光3 天前
【C 语言】(一)(下)指针进阶:const、二级指针、函数指针与指针题
c语言·开发语言·笔记·学习