iOS App 测试环境升级,遇到的问题以及解决方法

iOS App 测试环境升级,遇到的问题以及解决方法

Mac 实体机升级到 Sonima 14.5

Xcode 升级到 15.3

问题1: Xcode 编译 WebDriverAgent 失败

尝试下载 最新版本的WDA 源码编译,可以编译成功。


问题2:具体坐标直接点击的代码都会报错。

向开源项目报了这个问题,过了10分钟就得到回复:https://github.com/appium/appium/issues/20218

Please use W3C Actions instead.

Also, we do not support Appium 1 anymore - please upgrade to Appium 2.

于是升级相关配置和修改所有涉及到的代码,使用 W3C Action 替换原来的 MultiAction、TouchAction。


问题3:升级 Appium 从 1.2.0 升级到 2.9,执行报错,unexpected keyword argument 'desired_capabilites'

排查,搜到一个解决方法 https://github.com/appium/python-client/issues/878

该问题已经在 2.10 以上版本修复,于是再更新 Appium 到 2.11.1


问题4:系统弹框元素无法被识别到

之前也有这个问题,但是可以通过 driver.page_source 来定位到,现在升级后不行。

解决:不直接点击元素,而是使用脚本语句处理

driver.execute_script('mobile: alert',{'action': 'accept', 'buttonLabel': "Continue"}


问题5:登录google页面元素无法获取

之前偶尔也会遇到这个问题,但是重启模拟器、在Xcode重新编译WDA、重启Appium后,就可以定位到登录页面元素,这次升级后却不行。

重新安装了 Appium Server GUI 1.22.1版本(之前用的是 Appium 1.21.0-1),发现只要启动了Appium Server GUI 客户端后,不需要再通过 Xcode 编译出 WDA 到模拟器中,直接运行代码启动webdriver,模拟器中会自动生成 WDA,此时 Editor app 也能启动起来。

虽然现在不用自己去编译WDA 了,但是进入 Appium Server GUI 1.22.1 安装路径下的 /Applications/Appium\ Server\ GUI.app/Contents/Resources/app/node_modules/appium/node_modules/appium-webdriveragent,打开 WebDriverAgent.xcodeproj 来编译 WDA 会报错,无法生成WDA,但用 github 上的 WebDriverAgent-8.7.2 包来编译,是没问题的。

所以,现在使用 Appium Server GUI 1.22.1版本时,要么不自己去编译WDA,要么要用最新的包来编译 WDA,才能正常运行代码。


部分修改代码

点击坐标的方式改变,使用 PointerInput 和 ActionBuilder,不再支持 TouchAction(self.driver).tap(x=x, y=y, count=1).perform()

python 复制代码
from selenium.webdriver import ActionChains
from selenium.webdriver.common.actions import interaction
from selenium.webdriver.common.actions.mouse_button import MouseButton
from selenium.webdriver.common.actions.action_builder import ActionBuilder
from selenium.webdriver.common.actions.pointer_input import PointerInput
python 复制代码
pointer = PointerInput(kind=interaction.POINTER_TOUCH, name='finger1')
actions = ActionBuilder(self.driver, mouse=pointer)
actions.pointer_action.move_to_location(x, y)
actions.pointer_action.pointer_down()
actions.pointer_action.pointer_up()
actions.perform()
python 复制代码
pointer = PointerInput(kind=interaction.POINTER_TOUCH, name='finger1')
actions = ActionBuilder(self.driver, mouse=pointer)
actions.pointer_action.move_to_location(start_x, start_y)
actions.pointer_action.pointer_down()
actions.pointer_action.pause(duration)
actions.pointer_action.move_to_location(end_x, end_y)
actions.pointer_action.pointer_up()
actions.perform()
python 复制代码
actions = ActionChains(self.driver)
actions.w3c_actions.devices = []
pointer_input0 = actions.w3c_actions.add_pointer_input('touch', 'finger0')
pointer_input0.create_pointer_move(x=x, y=y)
pointer_input0.create_pointer_down()
pointer_input0.create_pause(0.5)
pointer_input0.create_pointer_move(x=x1, y=y1)
pointer_input0.create_pointer_up(MouseButton.LEFT)
pointer_input1 = actions.w3c_actions.add_pointer_input('touch', 'finger1')
pointer_input1.create_pointer_move(x=x, y=y)
pointer_input1.create_pointer_down()
pointer_input1.create_pause(0.5)
pointer_input1.create_pointer_move(x=x2, y=y2)
pointer_input1.create_pointer_up(MouseButton.LEFT)
actions.perform()
python 复制代码
pointer = PointerInput(kind=interaction.POINTER_TOUCH, name='finger1')
actions = ActionBuilder(self.driver, mouse=pointer)
for index, point in enumerate(coordinate_list):
    x, y = point
    if index == 0:
        # Long press on the first point
        actions.pointer_action.move_to_location(x=x, y=y)
        actions.pointer_action.pointer_down().pause(0.5)
    else:
        # Move to subsequent points
        actions.pointer_action.move_to_location(x=x, y=y).pause(0.5)
actions.pointer_action.pointer_up()
actions.perform()

不再支持像 find_element_by_accessibility_id、find_element_by_name 这类的接口,而是使用 find_element(MobileBy.ACCESSIBILITY_ID, locator)find_element(By.NAME, locator)

python 复制代码
# WebDriverWait(self.driver, timeout=time_out, poll_frequency=0.5, ignored_exceptions=None).until(lambda x: x.find_element_by_accessibility_id(locator))

WebDriverWait(self.driver, timeout=time_out, poll_frequency=0.5, ignored_exceptions=None).until(lambda x: x.find_element(MobileBy.ACCESSIBILITY_ID, locator))

处理系统弹框

python 复制代码
def handle_system_alert(self, button='Continue'):
    try:
        WebDriverWait(self.driver, 10).until(ec.alert_is_present())
        self.driver.execute_script('mobile: alert', {'action': 'accept', 'buttonLabel': f'{button}'})
        return True
    except Exception as e:
        print(f"No alert present: {e}")
        return False
相关推荐
2501_9159090612 小时前
Flutter 应用怎么加固,多工具组合的工程化实战(Flutter 加固/Dart 混淆/IPA 成品加固/Ipa Guard + CI)
android·flutter·ios·ci/cd·小程序·uni-app·iphone
denggun1234513 小时前
ios-WebP
macos·php·cocoa
denggun1234514 小时前
ios包体积管理方案
ios·iphone
Digitally14 小时前
解决 iPhone 和 Mac 之间备忘录无法同步的9种方法
macos·ios·iphone
小妖同学学AI14 小时前
Mac远程控制新篇章:UU远程被控端深度测评
macos·远程控制·uu
denggun1234514 小时前
图片上传git时压缩
git·ios·objective-c·iphone·xcode
胎粉仔15 小时前
Swift 初阶 —— Sendable 协议 & data races
开发语言·ios·swift·sendable·并发域·data races
xiaaaa.z15 小时前
macos HbuildX 使用cli脚本创建uniapp 运行时报错“cli项目运行依赖本地的Nodejs环境,请先安装并配置到系统环境变量后重试。”
macos·uni-app
2501_9159090615 小时前
深入理解HTTPS和HTTP的区别、工作原理及安全重要性
安全·http·ios·小程序·https·uni-app·iphone
猪哥帅过吴彦祖15 小时前
Flutter 从入门到精通:状态管理入门 - setState 的局限性与 Provider 的优雅之道
android·flutter·ios