【问题标题】:chromedriver azuredops pipeline failurechromedriver azuredops 管道故障
【发布时间】:2020-08-14 07:34:07
【问题描述】:

我正在尝试在 azure 管道中运行 selenium 测试,该测试在我的本地机器上运行良好:

options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
chrome_exe= ChromeDriverManager()
driver = webdriver.Chrome(executable_path=chrome_exe.install(), options=options)

但是当我在管道中运行相同时,它会失败并出现以下错误。

E       selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
E         (unknown error: DevToolsActivePort file doesn't exist)
E         (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
/opt/hostedtoolcache/Python/3.6.11/x64/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py:242: WebDriverException
---------------------------- Captured stdout setup -----------------------------
 
---------------------------- Captured stderr setup -----------------------------
[WDM] - Current google-chrome version is 84.0.4147
[WDM] - Get LATEST driver version for 84.0.4147
[WDM] - There is no [linux64] chromedriver for browser 84.0.4147 in cache
[WDM] - Get LATEST driver version for 84.0.4147
[WDM] - Trying to download new driver from http://chromedriver.storage.googleapis.com/84.0.4147.30/chromedriver_linux64.zip
[WDM] - Driver has been saved in cache [/home/vsts/.wdm/drivers/chromedriver/linux64/84.0.4147.30]

我手动转到它说的那条路径:没有这样的对象:chromedriver/84.0.4147.30 但如果我使用link 查询 它给出了相同的版本号

【问题讨论】:

    标签: selenium-webdriver azure-devops selenium-chromedriver azure-pipelines


    【解决方案1】:

    chromedriver azuredops 管道故障

    根据错误信息,Chrome 浏览器似乎没有安装在系统内的默认位置。

    对于 Linux 系统,ChromeDriver 期望 /usr/bin/google-chrome 是实际 Chrome 二进制文件的符号链接。

    如果您在非标准位置使用 Chrome 可执行文件,您可以尝试覆盖 Chrome 二进制位置,如下所示:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    options = Options()
    options.binary_location = "C:\\path\\to\\chrome.exe"    #chrome binary location specified here
    options.add_argument("--start-maximized") #open Browser in maximized mode
    options.add_argument("--no-sandbox") #bypass OS security model
    options.add_argument("--disable-dev-shm-usage") #overcome limited resource problems
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_experimental_option('useAutomationExtension', False)
    driver = webdriver.Chrome(options=options, executable_path=r'C:\path\to\chromedriver.exe')
    driver.get('http://google.com/')
    

    您可以查看this thread了解一些详细信息。

    【讨论】:

    • 好吧,因为这是一个 .exe 我如何为 chrome 设置 linux 二进制文件的路径,并在它在 Linux 管道中运行时获取它,并且仅当它在本地机器?