断言在硒 Web 测试中失败



当我尝试执行新的单元测试用例时,它会显示以下错误。

注意:我没有权限设置路径,因为我已将chrome Web驱动程序放置在D驱动器中。

测试于14:56开始... C:\Users\xxx.xxxx\PycharmProjects\Automation\venv\Scripts\python.exe "C:\Users\xx.xxx\AppData\Local\JetBrains\PyCharm Community Edition 2019.2\helpers\pycharm_jb_unittest_runner.py" --path C:/Users/xx.xxx/PycharmProjects/Automation/UnitTest_1.py 使用参数 python -m unittest C:/Users/xx.xx/PycharmProjects/Automation/UnitTest_1.py 在 C:\Users\xx.xxx\PycharmProjects\Automation

错误回溯(上次最近调用(:文件 "C:\xxxx\xxxxx\PycharmProjects\Automation\venv\lib\site-

软件包\硒\网络驱动程序\通用\service.py", 第 76 行,在开始 标准=管道( 文件 "C:\Programs\Python\Python37-32\lib\subprocess.py",第 775 行,在initrestore_signals 中,start_new_session( 文件 "C:\Programs\Python\Python37-32\lib\subprocess.py",第 1178 行,_execute_child 启动信息( 文件未找到错误: [WinError 2] 系统找不到指定的文件

当我处理上述异常时,我得到了另一个异常 下面。

回溯(最近一次调用(:文件 "C:\Programs\Python\Python37-32\lib\unittest\case.py",第 59 行,在 testPartExecutor yield 文件 "C:\Programs\Python\Python37-32\lib\unittest\case.py",第 615 行,在 跑 testMethod(( 文件 "C:\xxxx\xxxxx\PycharmProjects\Automation\UnitTest_1.py",第 17 行,在 test_Bing self.driver = webdriver。Chrome(executable_path="D:\test\chromedriver.exe"( 文件 "C:\xxxx\xxxx\PycharmProjects\Automation\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", 第 73 行,在initself.service.start(( 文件中 "C:\xxxx\xxxxx\PycharmProjects\Automation\venv\lib\site-packages\selenium\webdriver\common\service.py", 第 83 行,在开始 os.path.basename(self.path(, self.start_error_message( selenium.common.exceptions.WebDriverException: 消息: "chromedriver.exe"可执行文件需要位于 PATH 中。请看

https://sites.google.com/a/chromium.org/chromedriver/home

在 2 秒内运行了 2.374 次测试

失败(错误 = 2( 错误回溯(上次最近调用(:文件 "C:\Programs\Python\Python37-32\lib\unittest\case.py",第 59 行,在 testPartExecutor yield 文件 "C:\Programs\Python\Python37-32\lib\unittest\case.py",第 615 行,在 跑 testMethod(( 文件 "C:\Users\xxx.xxxx\PycharmProjects\Automation\UnitTest_1.py",第 10 行, 在test_Google self.driver.get("www.google.com"( 文件 "C:\Users\xx.xxxx\PycharmProjects\Automation\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", 第 333 行,在 GET 中 self.execute(Command.GET, {'url': url}( File "C:\Users\xx.xxxx\PycharmProjects\Automation\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", 第 321 行,执行中 self.error_handler.check_response(response( 文件 "C:\Users\xx.xxxxx\PycharmProjects\Automation\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", 242号线,check_response 引发exception_class(消息、屏幕、堆栈跟踪( selenium.common.exceptions.InvalidArgumentException: 消息: 无效 参数(会话信息:chrome=77.0.3865.90(

断言失败

进程已完成,退出代码为 1

断言失败

断言失败

import os
os.environ["PATH"] += os.pathsep +r"D:testchromedriver.exe"
import unittest
from selenium import webdriver
class SearchEnginesTest(unittest.TestCase):
def test_Google(self):
self.driver = webdriver.Chrome(executable_path=r"D:testchromedriver.exe")
self.driver.get("www.google.com")
self.driver.maximize_window()
# self.driver.save_screenshot("D:\test\one.jpg")
print("Title of the page :  " + self.driver.title)
self.driver.close()
def test_Bing(self):
self.driver = webdriver.Chrome(executable_path="D:testchromedriver.exe")
self.driver.get("www.bing.com")
self.driver.maximize_window()
# self.driver.save_screenshot("D:\test\two.jpg")
print("Title of the page:    " + self.driver.title)
self.driver.close()
if __name__ == "__main__":
unittest.main()

检查代码中的所有路径是否可以访问 python 中的 os sys.path。 另外,请检查 *.py 脚本是否位于 python 路径列表文件"python._pth"中列出的目录中。 检查有关路径更新的操作系统说明,在大多数"锁定"计算机中,您仍然可以编辑"用户路径"。 另一种选择是创建一个"运行器"脚本 - 在Windows上为*.bat的操作系统脚本或为shell的*.sh。 在运行器脚本中设置/添加操作系统 sys.path 并将文件动态添加到 python 路径以及脚本完成时 "添加"将消失回仅锁定路径。提交有关您的脚本的 ITIL 票证,以获得系统管理员的批准。

最新更新