首页 > 解决方案 > 带有 Python 问题的 WinAppDriver

问题描述

总的来说,我的问题是我正在尝试使用 WinnAppDriver 自动化 Windows 10 应用程序并用 Python 编写我的自动化。由于大多数 WinAppDriver 示例都是用 Java 编写的(可以理解...),因此关于如何执行此操作的信息似乎很少。但我几乎不知道 Python 的基础知识,而对 Java 一无所知。那么......有没有我错过的书或视频?具体来说,我安装了所有东西(通过 VS 代码安装了 Python),实际上运行了 Python 示例计算器测试......然后我不得不重新启动我的电脑,我收到以下错误:

作为一个新手,我深表歉意……我通过视频学习了 Python 的基础知识,因此我可以实现 Sikulix 自动化,这在我不得不在计算机之间切换之前效果很好……打破 Sikulix 非常容易分辨率依赖。所以......环顾四周后,我决定尝试通过 WinAppDriver 自动化......在 Python 中。哇......我找不到任何关于如何做到这一点的书籍或视频(因为我几乎没有学习 Python 并且知道零 Java)。任何帮助将不胜感激,我将证明我会花时间观看推荐的视频或研究推荐的书籍/文本。提前非常感谢...

[运行] python -u "c:\Users\bartc\Downloads\WinAppDriver-master\WinAppDriver-master\Samples\Python\CasaCharm 1.py" 错误

==================================================== =====================

错误:setUpClass(主要的.SimpleCalculatorTests)

Traceback(最近一次调用最后):文件“C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connection.py”,第 160 行,在 _new_conn (self._dns_host, self.port), self.timeout, **extra_kw) 文件“C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\util\connection.py”,第 80 行,在 create_connection 中引发错误文件“C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\util\connection.py”,第 70 行,在 create_connection sock.connect(sa) ConnectionRefusedError : [WinError 10061] 由于目标机器主动拒绝,无法建立连接

在处理上述异常的过程中,又出现了一个异常:

Traceback(最近一次调用最后一次):文件“C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py”,第 603 行,在 urlopen chunked=chunked)文件“C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py”,第 355 行,在 _make_request conn.request(method, url, **httplib_request_kw) 文件中“ C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\http\client.py",第 1229 行,在请求 self._send_request(method, url, body, headers, encode_chunked) 文件“C:\ Users\bartc\AppData\Local\Programs\Python\Python37\lib\http\client.py”,第 1275 行,在 _send_request self.endheaders(body, encode_chunked=encode_chunked) 文件“C:\Users\bartc\AppData\Local \Programs\Python\Python37\lib\http\client.py",第 1224 行,在 endheaders self._send_output(message_body, encode_chunked=encode_chunked) 文件“C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\http\client.py”,第 1016 行,在 _send_output self.send(msg ) 文件“C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\http\client.py”,第 956 行,发送 self.connect() 文件“C:\Users\bartc\AppData\ Local\Programs\Python\Python37\lib\site-packages\urllib3\connection.py”,第 183 行,在 connect conn = self._new_conn() 文件“C:\Users\bartc\AppData\Local\Programs\Python\ Python37\lib\site-packages\urllib3\connection.py”,第 169 行,在 _new_conn self 中,“无法建立新连接:%s”% e) urllib3.exceptions.NewConnectionError: : 无法建立新连接:[WinError 10061] 由于目标机器主动拒绝,无法建立连接

在处理上述异常的过程中,又出现了一个异常:

Traceback(最近一次调用最后一次):文件“c:\Users\bartc\Downloads\WinAppDriver-master\WinAppDriver-master\Samples\Python\CasaCharm 1.py”,第 31 行,在 setUpClass desired_capabilities=desired_caps)文件“C: \Users\bartc\AppData\Local\Programs\Python\Python37\lib\site-packages\appium\webdriver\webdriver.py”,第 144 行,在init 代理文件“C:\Users\bartc\AppData\Local\Programs \Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py",第 157 行,在init self.start_session(capabilities, browser_profile) 文件“C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\site-packages\appium\webdriver\webdriver.py”,第 219 行,在 start_session 响应 = self .execute(RemoteCommand.NEW_SESSION, parameters) 文件“C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py”,第 319 行,在执行中响应 = self.command_executor.execute(driver_command, params) 文件“C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\remote_connection.py”,第 374 行, 在执行 return self._request(command_info[0], url, body=data) File "C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\ remote_connection.py”,第 397 行,在 _request resp = self._conn.request(method, url, body=body, headers=headers) 文件“C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\request .py”,第 72 行,请求 **urlopen_kw) 文件“C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\request.py”,第 150 行,在 request_encode_body返回 self.urlopen(method, url, **extra_kw) 文件“C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\poolmanager.py”,第 326 行,在 urlopen response = conn.urlopen(method, u.request_uri, **kw) 文件“C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py”,第 670 行, 在 urlopen **response_kw) 文件“C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py”,第 670 行,在 urlopen **response_kw) 文件“C:\Users\bartc\AppData\Local\ Programs\Python\Python37\lib\site-packages\urllib3\connectionpool.py”,第 670 行,在 urlopen **response_kw) 文件“C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\site -packages\urllib3\connectionpool.py”,第 641 行,在 urlopen _stacktrace=sys.exc_info()[2]) 文件“C:\Users\bartc\AppData\Local\Programs\Python\Python37\lib\site-packages \urllib3\util\retry.py",第 399 行,增量提高 MaxRetryError(_pool, url, error 或 ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=4723): url 超出最大重试次数:/session(由 NewConnectionError(':无法建立新连接:[WinError 10061] 由于目标机器主动拒绝,无法建立连接'))


在 6.470 秒内运行 0 次测试

失败(错误=1)

[完成] 在 22.349 秒内以 code=0 退出

标签: python-3.xwinappdriver

解决方案


我的公司使用 RobotFramework 进行自动化测试,它建立在 python 之上,所以我理解你在寻找示例时的痛苦。我使用 winappdriver 为桌面自动化构建了一个测试库,并且看到它是基于 python 构建的,您可能会发现源代码很有用

该库为许多基本功能扩展了robotframework-appiumlibrary,因此它们的源代码也可能对您有用。

或者,如果您不精通 python,则可能值得研究robotsframework并使用我提供的 zoomba 库。Robotframework 很容易上手,无需任何 Python 知识。


推荐阅读