我们正在尝试以无头模式在Linux服务器上运行Robot框架测试。运行机器人测试时,我们将收到错误:WebDriverException:消息:未知错误:Devtools端口号文件内容<35674>的格式意外。
在robot测试中正确设置了chromedriver路径。此Linux服务器上的chromedriver 2.30和chrome 60.0版本的curl命令成功执行。因此,可能是由于我们在Robot配置中缺少了导致此问题的原因。
经过两种组合测试,结果相同:
Robot Framework-Selenium2Library v3.0,Chrome版本:60.0.3112.90,Chromer驱动程序版本:2.30.477691
Robot Framework-Selenium2Library v3.0,Chrome版本:73.0.3683.20,Chromer驱动程序版本:2.46
*** Settings ***
Library Selenium2Library
Library OperatingSystem
*** Variables ***
${url} https://www.google.com/
*** Test Cases ***
Simple UI Login
Log Creating WebDriver WARN
${chrome_options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys,selenium.webdriver
${ws}= Set Variable window-size=1920,1080
Call Method ${chrome_options} add_argument test-type
Call Method ${chrome_options} add_argument --no-sandbox
Call Method ${chrome_options} add_argument --disable-setuid-sandbox
Call Method ${chrome_options} add_argument --headless
Call Method ${chrome_options} add_argument ${ws}
Call Method ${chrome_options} add_argument --disable-gpu
${options}= Call Method ${chrome_options} to_capabilities
Create WebDriver Chrome executable_path=/opt/chromedriver/2.30/chromedriver
desired_capabilities=${options}
Go To ${url}
预期:测试可以在无头模式下成功运行。
实际值:OTC [001]:简单的UI登录::演示简单的测试用例示例|失败| WebDriverException:消息:未知错误:Chrome无法启动:异常退出 (驱动程序信息:chromedriver = 2.30.477691(6ee44a7247c639c0703f291d320bdf05c1531b57),platform = Linux 3.10.0-862.14.4.el7.x86_64 x86_64)
答案 0 :(得分:0)
我不确定您对SeleniumLibrary 3.3.1所做的尝试,所以这是我用来在无头模式下在Linux服务器上运行测试的内容。这些是我安装的不同版本:
从SeleniumLibrary 3.1.0开始,在Selenium 3.8.0或更高版本中,Open Browser
支持Headless Firefox和Headless Chrome。这意味着您可以在没有任何其他webdriver配置的情况下使用无头模式。
*** Settings ***
Library SeleniumLibrary
*** Test Cases ***
Headless Browser Test
[Setup] Open Browser https://stackoverflow.com Headless Chrome
Maximize Browser Window
Title Should Be Stack Overflow - Where Developers Learn, Share, & Build Careers
[Teardown] Close Browser
答案 1 :(得分:0)
我有一个工作示例,可以用来检查google.com的标题。
*** Settings ***
Documentation
... Basic Test for Google.com in headless mode
Library Collections
Library DateTime
Library Dialogs
Library OperatingSystem
Library SeleniumLibrary
Library String
Library RequestsLibrary
Suite Setup Setup Environment and Open Browser
Suite Teardown Close All Browsers
*** Variables ***
${BROWSER} HeadlessChrome
${SITE_URL} https://www.google.com
*** Test Cases ***
Title Test
Title Should Be Google
*** Keywords ***
Open Chrome Browser To URL
[Documentation] Open Chrome browser and navigate to URL with browser options set
[Tags] open_chrome_browser
${browserOptions} Run Keyword If 'Headless' in '${BROWSER}' Set Headless Chrome Options
Create Webdriver Chrome chrome_options=${browserOptions}
Go To ${SITE_URL}
Maximize Browser Window
Browser timeout and speed
[Documentation]
... Set browser timeout and speed
Set Selenium Timeout 30s
Set Selenium Speed 0s
Set Headless Chrome Options
[Documentation]
... Set the Chrome options for running in headless mode. Restrictions do not apply to headless mode.
[Tags] headless_chrome_options
${chromeOptions} Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys
Call Method ${chromeOptions} add_argument test-type
Call Method ${chromeOptions} add_argument --headless
Call Method ${chromeOptions} add_argument --disable-extensions
Call Method ${chromeOptions} add_argument --disable-gpu
Call Method ${chromeOptions} add_argument --disable-dev-shm-usage
Call Method ${chromeOptions} add_argument --no-sandbox
[Return] ${chromeOptions}
Setup Environment and Open Browser
[Documentation]
... This keyword will establish the environment variables and open a browser
[Tags] simple_test
Open Chrome Browser To URL
Browser timeout and speed
'''