为什么在Azure Pipelines中,驱动程序路径不正确,并且像Linux一样执行而不是Win

发布于 2025-02-09 18:25:22 字数 1943 浏览 1 评论 0 原文

我想在Azure管道中执行自动测试,但我收到以下错误:

selenium.common.exceptions.webdriverexception:消息:消息:未知错误:c chrome biary at C:\ program files \ google \ chrome \ chrome \ chrome \ chrome \ chrome \ chrome

bu bu bu bu bu bu bu bu bu bu bu bu bu bu bu bu Chrome.exe位于此路径上,不应该有任何问题。因此,根据我的初步调查,问题与以下事实有关:在Azure管道中,它试图通过以下路径获得Chromedriver:

WDM:logger.py:16 Current google-chrome version is 102.0.5005
INFO     WDM:logger.py:16 Get LATEST chromedriver version for 102.0.5005 google-chrome
INFO     WDM:logger.py:16 Driver [/home/vsts/.wdm/drivers/chromedriver/linux64/102.0.5005.61/chromedriver] found in cache

如您所见,有指示的Linux64,但请从我本地的计算机上查找以下日志。

在本地,如果我试图运行相同的测试用例,我会看到不同的路径,并且一切都在运行和正确传递。由于有Win32,而不是Linux64。

[WDM] - Current google-chrome version is 102.0.5005
[WDM] - Get LATEST chromedriver version for 102.0.5005 google-chrome
[WDM] - Driver [C:\Users\AYTAN\.wdm\drivers\chromedriver\win32\102.0.5005.61\chromedriver.exe] found in cache

因此,我不明白为什么在本地机器上,Chromedriver的路径是正确的,但是在Azur管道中,这是不正确的。我如何解决?也许我可以在代码中直接指示它?我的Python代码如下:

@pytest.fixture
def get_chrome_options():
    options = chrome_options()
    options.add_argument('chrome')
    options.binary_location = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
    options.chrome_driver_binary = r"C:\Users\USER\.wdm\drivers\chromedriver\win32\102.0.5005.61\chromedriver.exe"
    options.add_argument("--start-maximized")
    options.add_argument("--no-sandbox")
    options.add_argument("--disable-dev-shm-usage")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    return options

@pytest.fixture
def get_webdriver(get_chrome_options):
    options = get_chrome_options
    driver = webdriver.Chrome(options=options, service=Service(ChromeDriverManager().install()))
    return driver

I want to execute my auto tests in Azure pipeline but I got the following error:

selenium.common.exceptions.WebDriverException: Message: unknown error: no chrome binary at C:\Program Files\Google\Chrome\Application\chrome.exe

Bu chrome.exe is located by this path and there is should not be any issue. So, as per my initial investigation the issue related to the fact that in Azure pipelines it is trying to get chromedriver by following path:

WDM:logger.py:16 Current google-chrome version is 102.0.5005
INFO     WDM:logger.py:16 Get LATEST chromedriver version for 102.0.5005 google-chrome
INFO     WDM:logger.py:16 Driver [/home/vsts/.wdm/drivers/chromedriver/linux64/102.0.5005.61/chromedriver] found in cache

As you can see there is indicated linux64, but look up the below logs from my local machine.

Locally if I am trying to run the same test cases I see the different path and everything is running and passed correctly. Since there is win32, not linux64.

[WDM] - Current google-chrome version is 102.0.5005
[WDM] - Get LATEST chromedriver version for 102.0.5005 google-chrome
[WDM] - Driver [C:\Users\AYTAN\.wdm\drivers\chromedriver\win32\102.0.5005.61\chromedriver.exe] found in cache

So I can't understand why on my local machine the path to chromedriver is correct but in Azur pipelines it is not correct. How I can fix it? Maybe I can indicate it directly in my code? My Python code is below:

@pytest.fixture
def get_chrome_options():
    options = chrome_options()
    options.add_argument('chrome')
    options.binary_location = r"C:\Program Files\Google\Chrome\Application\chrome.exe"
    options.chrome_driver_binary = r"C:\Users\USER\.wdm\drivers\chromedriver\win32\102.0.5005.61\chromedriver.exe"
    options.add_argument("--start-maximized")
    options.add_argument("--no-sandbox")
    options.add_argument("--disable-dev-shm-usage")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    return options

@pytest.fixture
def get_webdriver(get_chrome_options):
    options = get_chrome_options
    driver = webdriver.Chrome(options=options, service=Service(ChromeDriverManager().install()))
    return driver

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伤痕我心 2025-02-16 18:25:24
  • 提供相对路径,而不是可能会有所帮助的整个路径。

例如:

./testapp/console-app/chrome.exe
  • 您也可以给出绝对的路径,但是这里的根目录
    更改它成为 build.sourcesDirectory 。是在这个目录
    下载源代码的位置。

例如:

$(Build.SourcesDirectory)/testapp/console-app/chrome.exe

参考:

azure devops中的目录

  • Give relative path instead the entire path that might help.

for eg:

./testapp/console-app/chrome.exe
  • You can also give absolute path too but here the root directory
    changes it becomes Build.SourcesDirectory . It is at this directory
    where the source code is downloaded.

for eg:

$(Build.SourcesDirectory)/testapp/console-app/chrome.exe

Reference:

Directories in azure devops

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文