【问题标题】:unknown error: Chrome failed to start: exited abnormally (Driver info: chromedriver=2.9未知错误:Chrome 无法启动:异常退出(驱动程序信息:chromedriver=2.9
【发布时间】:2014-04-28 18:43:21
【问题描述】:

我正在尝试在 Debian 7 上运行 Selenium 测试,但没有成功。

错误是:

unknown error: Chrome failed to start: exited abnormally   (Driver info: chromedriver=2.9.248316,platform=Linux 3.2.0-4-686-pae x86) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 60.55 seconds Build info: version: '2.33.0', revision: '4ecaf82108b2a6cc6f006aae81961236eba93358', time: '2013-05-22 12:00:17' System info: os.name: 'Linux', os.arch: 'i386', os.version: '3.2.0-4-686-pae', java.version: '1.7.0_25' Driver info: org.openqa.selenium.chrome.ChromeDriver

我有 chromedriver 29chrome 34.0.1847.76 betaDebian 7 32 位 上运行。我正在使用 selenium-java 2.33.0

按照linkchromedriver 29chrome 34 的正确版本。而且无论如何,由于 glibc 版本,以前的版本不能在 Debian 7 上运行……

----------ChromeDriver v2.9 (2014-01-31)---------- 支持 Chrome v31-34

[更新 1]

我尝试了 java 7java 6,仍然是同样的问题。 也许我应该尝试使用 java 8 ^^

[更新 2]

我正在使用这个命令来测试 chrome 驱动程序,以确保这不是 jenkins 的问题:

curl -X POST -H "Content-Type: application/json; charset=utf-8" -d "{\"desiredCapabilities\":{\"platform\":\"ANY\",\"browserName\": \"chrome\",\"chromeOptions\":{\"args\":[],\"extensions\":[]},\"version\":\"\",\"chrome.switches\" :[]}}" 本地主机:12495/会话

我收到同样的错误信息:

{"sessionId":"210f3f837a798ee68cd91f089976d0c2","status":13,"value":{"message":"unknown error: Chrome 无法启动: 异常退出\n (驱动信息: chromedriver=2.9.248316,platform=Linux 3.2.0-4-686-pae x86)"}}

任何帮助了解正在发生的事情将不胜感激。

谢谢

【问题讨论】:

  • 任何能够从詹金斯以非无头模式运行的人

标签: selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

我终于设法在我的笔记本电脑(服务器)上启动 Chrome 驱动程序进行 Selenium 测试。

重要的是使用Xvfb。不要问我为什么,但一旦你接受这个事实,请按照以下步骤操作(比@Anon 回答更详细)

  • 在你的 Jenkins 设置中添加一个全局属性

    key : DISPLAY
    value:0:0
    
  • 在您的服务器上在后台启动Xvfb

     Xvfb :0 -ac -screen 0 1024x768x24 &
    

【讨论】:

  • 添加 export DISPLAY=:XX where XX is number of display 为我解决了问题
  • 感谢您的帮助!另外,一条对我有帮助的注释:设置全局变量是通过“管理 Jenkins -> 配置系统 -> 全局属性”完成的
  • 应该是value:0:0 还是value: :0
  • Xvfb 提供了一个虚拟显示器来呈现浏览器。可能在无头模式下运行测试也可以减少渲染浏览器的需要,否则硒会在虚拟显示器上产生。
  • 所以这最接近我的错误。我通过 ssh localhost 取消了我的 X11 会话以更新我的组,而无需重新启动 X-Session。 Firefox 和 chrome 以类似的方式持续失败。
【解决方案2】:

您是否将 DISPLAY 参数传递给您的 Jenkins 作业?

我假设您也在尝试以无头模式执行测试。因此,设置一些 x 服务(即 Xvfb)并将 DISPLAY 编号传递给您的工作。为我工作。

【讨论】:

  • 我没有尝试在无头模式下执行测试,因为我使用的是笔记本电脑,并且我已将屏幕设置为即使在合上盖子时也保持打开状态。但也许我应该尝试无头模式?
  • 在无头服务器上遇到了这个问题,确保正确设置了 DISPLAY 解决了我的问题!谢谢!
【解决方案3】:

我试图在 Jenkins 上使用 wdio 使用 Mocha 框架运行 selenium。因此,以下是解决此问题的步骤:-

安装谷歌浏览器

sudo apt-get update 

sudo apt-get install google-chrome-stable

安装 chrome-driver

wget http://chromedriver.storage.googleapis.com/2.23/chromedriver_linux64.zip
unzip chromedriver_linux64.zip

运行以下命令启动 selenium 网络服务器

nohup sudo Xvfb :10 -ac
export DISPLAY=:10
java -jar vendor/se/selenium-server-standalone/bin/selenium-server-standalone.jar -Dwebdriver.chrome.bin="/usr/bin/google-chrome" -Dwebdriver.chrome.driver="vendor/bin/chromedriver"

在此开始之后,您使用 wdio 命令进行测试

wdio wdio.conf.js

【讨论】:

    【解决方案4】:
    1. 检查您是否使用ChromeDriver version that corresponds to your Chrome version
    2. 如果你在Linux without graphical interface "headless" mode must be used

    WebDriverSettings.java 示例:

    ...
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", chromePrefs);
    options.addArguments("--no-sandbox");
    options.addArguments("--headless"); //!!!should be enabled for Jenkins
    options.addArguments("--disable-dev-shm-usage"); //!!!should be enabled for Jenkins
    options.addArguments("--window-size=1920x1080"); //!!!should be enabled for Jenkins
    driver = new ChromeDriver(options);
    ...
    

    【讨论】:

      【解决方案5】:

      Mike R 的解决方案对我有用。这是完整的命令集:

      Xvfb :99 -ac -screen 0 1280x1024x24 &
      export DISPLAY=:99
      nice -n 10 x11vnc 2>&1 &
      

      稍后你可以运行 google-chrome:

      google-chrome --no-sandbox &
      

      或者通过 selenium 驱动启动谷歌浏览器(例如):

      ng e2e --serve true --port 4200 --watch true
      

      Protractor.conf 文件:

      capabilities: {
          'browserName': 'chrome',
          'chromeOptions': {
              'args': ['no-sandbox']
          }
      },
      

      【讨论】:

      • xvfb 是一个虚拟屏幕,如果您只使用终端,它会有所帮助:en.wikipedia.org/wiki/Xvfb
      • “不知何故”是因为浏览器是一个图形应用程序,需要一个显示器来呈现任何东西
      【解决方案6】:

      将无沙盒传递给 exec 对 jenkins 在前台或作为服务的窗口上似乎很重要。这是我的解决方案

      chromedriver fails on windows jenkins slave running in foreground

      【讨论】:

      • 我在 docker 容器中以无头模式(selenium-webdriver 3 和 Ruby on Rails)使用 chrome 时使用了 no-sandbox
      • 除非您使用--no-sandbox 并且许多 Docker 容器以 root 身份运行,否则以 root 身份运行它是行不通的,并且一些(配置严重的)Jenkins 节点也可能使用 root。您可以添加的另一个选项是--headless,这有助于完全避免对 Xvfb 的需求。您可能还需要专门在 Docker 中使用 --disable-dev-shm-usage,或者您需要在运行中使用 --mount type=bind,source=/dev/shm,target=/dev/shm 绑定挂载该设备。
      【解决方案7】:

      我们在尝试从 Jenkins 启动 Selenium 测试时遇到了同样的问题。我选择了“在构建之前启动 Xvfb,并在之后关闭它”框并传递了必要的屏幕选项,但我仍然收到此错误。

      当我们在 Execute Shell 框中传入以下命令时,它终于起作用了。

      Xvfb :99 -ac -screen 0 1280x1024x24 & nice -n 10 x11vnc 2>&1 & ... killall Xvfb

      【讨论】:

      • 你能在非无头模式下运行吗
      • 谢谢,第一行为我修复了 chrome 驱动脚本 :)
      【解决方案8】:

      在 Linux 中,将这些行添加到我的代码中对我有帮助。

      from selenium import webdriver
      from selenium.webdriver.chrome.options import Options
      
      
      chrome_options = Options()
      chrome_options.add_argument("--disable-extensions")
      chrome_options.add_argument("--disable-gpu")
      chrome_options.add_argument("--no-sandbox")
      driver = webdriver.Chrome(options=chrome_options)
      
      driver.get("www.counterviews.online")
      

      【讨论】:

      • 没有沙箱是问题,因为 chromedriver 不允许在没有该命令的情况下在 linux 中的 sudo 中运行
      【解决方案9】:

      我正在运行类似的设置:Selenium 3.40、Chrome 61、chromedriver 2.33 在 ubuntu 16.04 上运行 xvfb。

      我间歇性地收到相同的 Chrome 错误。似乎有时,chromedriver 无法清理与 Chrome 配置文件关联的临时文件。

      我的一个解决方法是在运行测试之前清理临时文件:

      rm -rf /tmp/.org.chromium.Chromium*
      

      我希望这将在未来版本的 chromedriver 中得到解决,但现在这解决了我的问题。

      【讨论】:

        【解决方案10】:

        我一直在与这个问题作斗争很长时间,就在今天我想出了如何让它消失,今天我可以运行一个调用 selenium 的 50 个线程进程而不再看到这个问题,并且也停止了我的崩溃机器出现内存不足问题,打开的 chromedriver 进程过多。

        1. 我正在使用 selenium 3.7.1、chromedrive 2.33、java.version: '1.8.0'、redhat ver '3.10.0-693.5.2.el7.x86_64'、chrome 浏览器版本:60.0.3112.90;李>
        2. 在屏幕上运行一个打开的会话,以确保我的会话永远不会结束,
        3. 运行 Xvfb : nohup Xvfb -ac :15 -screen 0 1280x1024x16 &
        4. 从 .bashsh/.profile 导出 DISPLAY:15

        这 4 项是每个人都已经知道的基本设置,现在是代码,所有这些都为取得成功做出了很大的改变:

        public class HttpWebClient {
            public static ChromeDriverService service;
            public ThreadLocal<WebDriver> threadWebDriver = new ThreadLocal<WebDriver>(){
            @Override
            protected WebDriver initialValue() {
                FirefoxProfile profile = new FirefoxProfile();
                profile.setPreference("permissions.default.stylesheet", 2);
                profile.setPreference("permissions.default.image", 2);
                profile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", "false");
                profile.setPreference(FirefoxProfile.ALLOWED_HOSTS_PREFERENCE, "localhost");
                WebDriver driver = new FirefoxDriver(profile);
                return driver;
            };
        };
        
        public HttpWebClient(){
            // fix for headless systems:
            // start service first, this will create an instance at system and every time you call the 
            // browser will be used
            // be sure you start the service only if there are no alive instances, that will prevent you to have 
            // multiples chromedrive instances causing it to crash
            try{
                if (service==null){
                    service = new ChromeDriverService.Builder()
                    .usingDriverExecutable(new File(conf.get("webdriver.chrome.driver"))) // set the chromedriver path at your system
                    .usingAnyFreePort()
                    .withEnvironment(ImmutableMap.of("DISPLAY", ":15"))
                    .withSilent(true)
                    .build();
                    service.start();
                }
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        
        // my Configuration class is for good and easy setting, you can replace it by using values instead.
        public WebDriver getDriverForPage(String url, Configuration conf) {
            WebDriver driver = null;
            DesiredCapabilities capabilities = null;
            long pageLoadWait = conf.getLong("page.load.delay", 60);
        
            try {
                    System.setProperty("webdriver.chrome.driver", conf.get("webdriver.chrome.driver"));
                    String driverType = conf.get("selenium.driver", "chrome");
        
                capabilities = DesiredCapabilities.chrome();
                String[] options = new String[] { "--start-maximized", "--headless" };
                capabilities.setCapability("chrome.switches", options);
        
                            // here is where your chromedriver will call the browser
                            // I used to call the class ChromeDriver directly, which was causing too much problems 
                            // when you have multiple calls
                driver = new RemoteWebDriver(service.getUrl(), capabilities);
        
                driver.manage().timeouts().pageLoadTimeout(pageLoadWait, TimeUnit.SECONDS);
                driver.get(url);
        
                            // never look back
        
            } catch (Exception e) {
                if (e instanceof TimeoutException) {
                    LOG.debug("Crawling URL : "+url);
                    LOG.debug("Selenium WebDriver: Timeout Exception: Capturing whatever loaded so far...");
                    return driver;
                }
                cleanUpDriver(driver);
                throw new RuntimeException(e);
            }
            return driver;
        }
        
        public void cleanUpDriver(WebDriver driver) {
            if (driver != null) {
                try {
                                    // be sure to close every driver you opened
                    driver.close();
                    driver.quit();
                    //service.stop(); do not stop the service, bcz it is needed
                    TemporaryFilesystem.getDefaultTmpFS().deleteTemporaryFiles();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
        

        }

        祝你好运,我希望你不会再看到崩溃问题

        请评论你的成功

        最好的问候,

        【讨论】:

          【解决方案11】:

          导出DISPLAY 变量绝对是解决方案,但根据您的设置,您可能需要以稍微不同的方式执行此操作。

          就我而言,我有两个不同的进程:第一个启动 Xvfb,另一个启动测试。所以我的 shell 脚本知识有点生疏,但我发现从第一个进程中导出 DISPLAY 变量并不能使其在第二个进程中可用。

          幸运的是,Selenium WebDriver 允许您“重新定义”您的环境。 这是我在 JS 中为 Chrome 创建驱动程序的功能。很确定您的编程语言存在等价物:

          const caps = require('selenium-webdriver/lib/capabilities');
          const chrome = require('selenium-webdriver/chrome');
          const chromedriver = require('chromedriver');
          
          module.exports = function (cfg) {
              let serviceBuilder = new chrome.ServiceBuilder(chromedriver.path);
              let options = chrome.Options.fromCapabilities(caps.Capabilities.chrome());
              let service;
              let myENV = new Map();
          
              // 're-export' the `DISPLAY` variable
              myENV.set('DISPLAY', ':1');
              serviceBuilder.setEnvironment(myENV);
          
              service = serviceBuilder.build();
          
              options.addArguments('disable-setuid-sandbox');
              options.addArguments('no-sandbox');
              options.addArguments('allow-insecure-localhost');
              options.excludeSwitches('test-type');
          
              return chrome.Driver.createSession(options, service);
          };
          

          【讨论】:

          【解决方案12】:

          我在终端中使用的 x86 linux 上的 maven 测试有类似的问题。 我通过 ssh 登录到 linux。 我通过

          开始了我的 java selenium 测试
          mvn -DargLine="-Dbaseurl=http://http://127.0.0.1:8080/web/" install
          

          除了我的应用,运行这些测试后,我在日志中收到错误:

          unknown error: Chrome failed to start: exited abnormally
          

          我以 root 用户身份运行这些测试。 在此错误之前,我收到 ChromeDriver 也不存在。我通过安装 ChromeDriver 二进制文件并将其添加到 PATH 来推进这一点。但后来我不得不安装 google-chrome 浏览器——仅 ChromeDriver 不足以运行测试。 所以错误可能是终端窗口中的屏幕缓冲区有问题,但是您可以安装虚拟屏幕缓冲区 Xvfb。重要的是,您不应以 root 身份运行测试,因为您可能会收到另一个 Chrome 浏览器错误。 所以我不以 root 身份运行:

          export DISPLAY=:99
          Xvfb :99 -ac -screen 0 1280x1024x24 &
          

          这里重要的是,在我的例子中,与 DISPLAY 相关的数字应该与 Xvfb :NN 参数相同。在这种情况下为 99。 我遇到了另一个问题,因为我使用另一个 DISPLAY 值运行 Xvfb,我希望它停止。为了重新启动 Xvfb:

          ps -aux | grep Xvfb
          kill -9 PID
          sudo rm /tmp/.X11-unix/X99
          

          所以用 grep 找一个进程 PID。杀死 Xvfb 进程。然后 /tmp/.X11-unix/XNN 有锁,所以删除这个锁,你可以重新启动服务器。 如果您不是以 root 身份运行,设置类似的显示,安装 google-chrome,然后使用 maven,您可以开始 selenium 测试。我的测试在这些规则和操作上很顺利。

          【讨论】:

            【解决方案13】:

            不确定这是否会阻止其他人,但我通过升级 chromedriver 解决了这个问题,然后确保它位于我的用户可以读取的位置(似乎很多遇到此问题的人出于许可原因看到它像我一样)。

            在 Ubuntu 16.04 上: 1.下载chromedriver(我是2.37版) 2.解压文件 3. 安装在合适的地方(我选择了/usr/local/bin/chromedriver)

            甚至不需要归我的用户所有,只要它是全局可执行的 (sudo chmod +x /usr/local/bin/chromedriver)

            【讨论】:

              【解决方案14】:

              我增加最大内存以使用-Xmx3g 启动 node-chrome,这对我有用

              【讨论】:

                【解决方案15】:

                你不需要 Xvfb

                由于 chrome 版本和 chromedriver 版本不匹配,无法启动。下载并安装相同版本或最新版本即可解决此问题。

                【讨论】:

                  【解决方案16】:

                  在我的 Ubuntu 服务器中,以下解决问题

                  Xvfb :11 -ac -screen 0 1024x768x24 &
                  export DISPLAY=:11
                  
                  python selenium_test.py
                  
                  killall Xvfb 
                  

                  如果您有多个 Xvfb 进程同时运行,请不要使用最后一行。

                  【讨论】:

                    猜你喜欢
                    • 2014-05-03
                    • 2020-11-01
                    • 1970-01-01
                    • 2014-04-20
                    • 2017-09-07
                    • 1970-01-01
                    • 1970-01-01
                    • 2016-10-08
                    • 2017-06-17
                    相关资源
                    最近更新 更多