测开学习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. 两数之和

相关推荐
滕州市燕猫虎计算机科技工作室个体工商户4 小时前
《Rust程序设计》学习笔记八:结构体
笔记·学习·rust·rust程序设计
别动我齐刘海5 小时前
Linux 系统调试学习1
linux·运维·服务器·c++·学习·机器学习·机器人
xier_ran6 小时前
【infra之路】AI 编译器学习笔记(二):重拾 C++——移动语义与 LLVM 风格的类型转换
人工智能·笔记·学习
li星野8 小时前
5 TYPES OF ADVERBS — One-Page Notes
学习
星恒随风9 小时前
Linux库的底层原理:ELF文件格式、静态链接、程序加载、虚拟地址空间与GOT/PLT详解
linux·运维·笔记·学习·状态模式
罗西的思考9 小时前
[Agent Memory / 强化学习] MemPO源码学习笔记 — (7)— 混合机制
笔记·学习
starsky762389 小时前
Agent学习——上下文工程(三)
学习
xier_ran11 小时前
【infra之路】AI 编译器学习笔记(四):PatternRewriter 与贪心 driver
人工智能·笔记·学习
小弥儿11 小时前
GitHub今日热榜 | 2026-10-12:pytorch 上升四位
人工智能·pytorch·学习·开源·github
AOI小白新手上路11 小时前
DeepLens 的课程学习自动设计与同源仿真论文综述
学习