Appium新版本引发的一个问题
Appium新版本引发的一个问题
准备工作
测试代码
from appium import webdriver
des_cap = {'platformName': 'android'}
driver = webdriver.Remote(command_executor='http://127.0.0.1:4723/wd/hub',
desired_capabilities=des_cap)
测试环境
- python 3.10,虚拟环境
- pycharm 2018 community
- 测试时间 2023-7-20
场景一: 默认安装 PASS
在pycharm中安装appium-python-client,版本不指定,此时是2.11.1
对应依赖selenium4.10.0
执行示例代码
测试
通过
??? 所以博主你要表达啥
继续看下去
场景二:appium-python-client2.6.0+selenium4.10 FAIL
你根据指定版本安装appium-python-client为2.6,自动安装selenium4.10
执行示例代码
测试
失败
提示如下
D:\Appium01\venv\Scripts\python.exe D:/Appium01/demo1.py
Traceback (most recent call last):
File "D:\Appium01\demo1.py", line 9, in <module>
driver = webdriver.Remote(command_executor='http://127.0.0.1:4723/wd/hub',
File "D:\Appium01\venv\lib\site-packages\appium\webdriver\webdriver.py", line 230, in __init__
super().__init__(
TypeError: WebDriver.__init__() got an unexpected keyword argument 'desired_capabilities'
场景3:appium-python-client2.6.0+selenium4.3.0 PASS
- 你应该是先安装selenium4.3.0
- 然后再安装appium-python-client2.6.0
- 都是指定版本安装
- 有同学会说,谁会这样安装呢
- 会的,因为你可能是先学selenium(我课程要求是4.3,最新的版本4.10的改进对我们没有太大意义,但底层确实改变了很多)
- 测试
通过
问题说明
TypeError 分析
先看报错
TypeError: WebDriver.__init__() got an unexpected keyword argument 'desired_capabilities'
主要版本信息:
- appium-python-client2.6.0
- selenium4.10
报错行
driver = webdriver.Remote
Remote是个别名
from .webdriver import WebDriver as Remote
看WebDriver源码
class WebDriver(
webdriver.Remote,
ActionHelpers,
Activities,
Applications,
Clipboard,
Context,
Common,
DeviceTime,
Display,
ExecuteDriver,
ExecuteMobileCommand,
Gsm,
HardwareActions,
ImagesComparison,
IME,
Keyboard,
Location,
LogEvent,
Network,
Performance,
Power,
RemoteFS,
ScreenRecord,
Session,
Settings,
Sms,
SystemBars,
):
def __init__(
self,
command_executor: str = 'http://127.0.0.1:4444/wd/hub',
desired_capabilities: Optional[Dict] = None,
browser_profile: str = None,
proxy: str = None,
keep_alive: bool = True,
direct_connection: bool = True,
extensions: Optional[List['WebDriver']] = None,
strict_ssl: bool = True,
options: Union[AppiumOptions, List[AppiumOptions]] = None,
):
__init__
中传递了desired_capabilities没有问题继续分析堆栈
File "D:\Appium01\venv\lib\site-packages\appium\webdriver\webdriver.py", line 230, in __init__
super().__init__(
继续看WebDriver此处源码
super().__init__(
command_executor=AppiumConnection(command_executor, keep_alive=keep_alive),
desired_capabilities=desired_capabilities,
browser_profile=browser_profile,
proxy=proxy,
options=options,
)
这里也有desired_capabilities,为何报错了呢
请看WebDriver的继承webdriver.Remote
class WebDriver(BaseWebDriver):
_web_element_cls = WebElement
_shadowroot_cls = ShadowRoot
def __init__(
self,
command_executor="http://127.0.0.1:4444",
keep_alive=True,
file_detector=None,
options: Union[BaseOptions, List[BaseOptions]] = None,
) -> None:
到这里你发现了,这个
__init__
里面没有desired_capabilities注意webdriver.Remote是隶属于selenium的,你此时的selenium是4.10,升级了,可能导致它remove了一些参数
appium-python-client2.11.1+selenium4.10
这是默认组合,要知道selenium也是4.10了,为何没有报错呢?
其调用关系简单分析下
在
Remote
的__init__
中,也支持desired_capabilities,但有如下信息# TODO: Remove the deprecated arg
desired_capabilities: Optional[Dict] = None,
if desired_capabilities is not None:
warnings.warn(
'desired_capabilities argument is deprecated and will be removed in future versions. '
'Use options instead.',
DeprecationWarning,
)
- 后续要移除desired_capabilities
- 用options替代(模仿selenium)
关键的问题是在于,appium-python-client2.11.1中对父类
__init__
的调用是不携带desired_capabilities的super().__init__(
command_executor=command_executor,
options=dst_options,
)
完整代码片段如下
class WebDriver(
webdriver.Remote,
ActionHelpers,
Activities,
Applications,
Clipboard,
Context,
Common,
DeviceTime,
Display,
ExecuteDriver,
ExecuteMobileCommand,
Gsm,
HardwareActions,
ImagesComparison,
IME,
Keyboard,
Location,
LogEvent,
Network,
Performance,
Power,
RemoteFS,
ScreenRecord,
Session,
Settings,
Sms,
SystemBars,
):
def __init__(
self,
command_executor: Union[str, AppiumConnection] = 'http://127.0.0.1:4444/wd/hub',
# TODO: Remove the deprecated arg
desired_capabilities: Optional[Dict] = None,
# TODO: Remove the deprecated arg
browser_profile: Union[str, None] = None,
# TODO: Remove the deprecated arg
proxy: Union[str, None] = None,
keep_alive: bool = True,
direct_connection: bool = True,
extensions: Optional[List['WebDriver']] = None,
strict_ssl: bool = True,
options: Union[AppiumOptions, List[AppiumOptions], None] = None,
):
if strict_ssl is False:
# pylint: disable=E1101
# noinspection PyPackageRequirements
import urllib3
# pylint: disable=E1101
# noinspection PyPackageRequirements
import urllib3.exceptions
# noinspection PyUnresolvedReferences
AppiumConnection.set_certificate_bundle_path(None)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
if isinstance(command_executor, str):
command_executor = AppiumConnection(command_executor, keep_alive=keep_alive)
if browser_profile is not None:
warnings.warn('browser_profile argument is deprecated and has no effect', DeprecationWarning)
if proxy is not None:
warnings.warn('proxy argument is deprecated and has no effect', DeprecationWarning)
if desired_capabilities is not None:
warnings.warn(
'desired_capabilities argument is deprecated and will be removed in future versions. '
'Use options instead.',
DeprecationWarning,
)
# TODO: Remove the fallback after desired_capabilities removal
dst_options = (
AppiumOptions().load_capabilities(desired_capabilities)
if desired_capabilities is not None and options is None
else options
)
super().__init__(
command_executor=command_executor,
options=dst_options,
)
appium-python-client2.6.0+selenium4.3.0
想必分析到此处,你应该盲猜能知道为何这个也PASS了
是因为selenium的版本中webdriver.Remote中是有desired_capabilities的
class WebDriver(BaseWebDriver):
_web_element_cls = WebElement
_shadowroot_cls = ShadowRoot
def __init__(self, command_executor='http://127.0.0.1:4444',
desired_capabilities=None, browser_profile=None, proxy=None,
keep_alive=True, file_detector=None, options: Union[BaseOptions, List[BaseOptions]] = None):
总结
- 最新版本appium-python-client即将不提供desired_capabilities的传参,但目前能用
- 在selenium4.10中已经不支持desired_capabilities参数
- 错误的搭配可能会引发上述问题,要么用最新的版本(默认安装),要么2个都用较低的版本
- 留在最后的问题,那么在appium最新版中应该如何传递能力值呢?
Appium新版本引发的一个问题的更多相关文章
- appium新版本不支持findElementByName,切换到findElementByAndroidUIAutomator
appium 1.7.6 不支持findElementByName(locator) 不知道为什么? 脚本中许多这样的语句,麻烦事情多了 org.openqa.selenium.InvalidSel ...
- Appium新版本不再支持ByName定位了怎么办
appium版本在1.5以后就不再支持ByName的定位,本文章仅介绍在appium1.6.3/1.6.4/1.6.5版本下如何支持ByName定位,适用于安卓.在使用appium1.5之后的版本时, ...
- 新版appium绘制九宫格的一个注意点
在用appium-desktop-setup-1.6.2进行app手势密码设置时,发现move_to(x, y)相对偏移量的方法用不了,绘制的手势也是乱跑 还会抛一个错误 selenium.commo ...
- appium环境配置和一个例子
最近觉得appium挺火的,看了一些资料,本来想使用npm在线安装,遇见各种问题,先简单说一下: 在cmd窗口中使用命令:npm install -g appium安装,报无python的error, ...
- Appium新版本遇到的问题,不能通过 name 去定位元素抛 Message: Locator Strategy 'name' is not supported for this session
环境: 1.Appium: 1.15.1 2.Python: 3.7.0 3.Selenium: 3.141.0 4.IDE: Pycharm 5.PC:Windows 10 问题:在 Pycharm ...
- Appium之启动第一个App
搭建appium自动化环境真是各种问题呀. 如何启动在真机上启动App? 执行操作:操作Android真机上打开手机淘宝app,并搜索“熊猫”. 脚本源码如下: from appium import ...
- “static”引发的一个错误
昨天晚上,舍友发来一个程序,先把代码贴上: #include<stdio.h>#define N 20short bufferA[N]={1,2,3,4,5,6,7,8,9,10,11, ...
- js json 与字符串 转换过程由于书写不统一规范引发的一个问题
对于两个字符串: 字符串1:{title:{},tooltip:{trigger:"axis"},legend:{data:["新关注人数"]},calcula ...
- 【转】NO.2、Appium之IOS第一个demo
接第一篇:Appium之iOS环境搭建 http://blog.csdn.net/clean_water/article/details/52946191 这个实例继承了unittest,重写了它的s ...
- Dubbo配置引发的一个问题--- Duplicate spring bean id
1.原因 因项目业务需要,要调用RPC框架,项目原本已经依赖了很多RPC接口需要启动时加载,所以准备做成启动时不预加载. 就是在配置的时候加上check=false. 官方文档解释的作用,就是Dubb ...
随机推荐
- Go/Python gRPC实践
gRPC框架 & ProtoBuf 安装相关工具: pip3 install grpcio pip3 install grpcio-tools protobuf3有自己专门的定义的格式,基于此 ...
- 当 Amazon Lambda 遇上 Apache APISIX 可以擦出什么火花?
本文首先介绍了什么是 Serverless,以及为什么需要 Serverless:其次,讲述了一个好的网关在 Serverless 架构下的重要性,而 APISIX 就是这样的一个网关:最后,本文重点 ...
- 你还弄不清xxxForCausalLM和xxxForConditionalGeneration吗?
Part1基本介绍 大语言模型目前一发不可收拾,在使用的时候经常会看到transformers库的踪影,其中xxxCausalLM和xxxForConditionalGeneration会经常出现在我 ...
- Locust 界面简介(非使用级)
一.认识Locust 1.简介 Locust是一款易于使用的分布式负载测试工具,完全基于事件,即一个locust节点也可以在一个进程中支持数千并发用户,不使用回调,通过gevent使用轻量级过程(即在 ...
- ABC267G Increasing K Times 题解
做这道题,很有感悟,发篇文. 先给数列从小到大排个序. 接下来设 \(f_{i,j}\) 表示前 \(i\) 个数的排列形成 \(j\) 个上坡的方案数. 接下来考虑转移,分为插入第 \(i\) 个数 ...
- 自动化运维工具-Ansible PlayBook
自动化运维工具-Ansible PlayBook PlayBook基本概念 PlayBook的组成 PlayBook即"剧本","兵书"之意,PlayBook是 ...
- 2022-03-05:不相交的线。 在两条独立的水平线上按给定的顺序写下 nums1 和 nums2 中的整数。 现在,可以绘制一些连接两个数字 nums1[i] 和 nums2[j] 的直线,这些直
2022-03-05:不相交的线. 在两条独立的水平线上按给定的顺序写下 nums1 和 nums2 中的整数. 现在,可以绘制一些连接两个数字 nums1[i] 和 nums2[j] 的直线,这些直 ...
- 2021-05-26:给定一个char[][] matrix
2021-05-26:给定一个char[][] matrix,也就是char类型的二维数组,再给定一个字符串word,可以从任何一个某个位置出发,可以走上下左右,能不能找到word?char[][] ...
- 2021-09-29:不同路径。一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为 “Start” )。机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角(在下图中标记为
2021-09-29:不同路径.一个机器人位于一个 m x n 网格的左上角 (起始点在下图中标记为 "Start" ).机器人每次只能向下或者向右移动一步.机器人试图达到网格的右 ...
- 【故障公告】博客站点一台阿里云负载均衡被DDoS攻击
13:06 收到阿里云的电话与邮件通知,博客站点的一台阿里云负载均衡因被 DDoS 攻击被关进黑洞(所有访问被屏蔽),部分用户的访问受影响,由此给您带来麻烦,请您谅解. 您的IP:x.x.x.x 实例 ...