【问题标题】:Run behat chrome headless (without selenium?)Run behat chrome headless(没有硒?)
【发布时间】:2017-09-18 03:21:18
【问题描述】:

我在 PhantomJS 上运行 Behat 测试没有问题。我是从这个开始的:

bin/phantomjs --webdriver=8643

它有效,但我想运行 Chrome 无头而不是 PhantomJS。为此,我尝试了以下操作:

google-chrome --headless --remote-debugging-port=8643

但是 Behat 似乎没有在这个 Chrome 上启动任何东西。我找到了很多带有 Selenium 的 Chrome 文档,但我想知道是否可以像使用 Selenium 驱动程序运行 PhantomJS 一样运行它,但没有 Selenium 服务器?

default:
  suites:
    default:
      contexts:
        - FeatureContext
        - Behat\MinkExtension\Context\MinkContext
  extensions:
    Behat\MinkExtension:
      base_url: 'http://myurl.com/'
      sessions:
        default:
          selenium2:
            wd_host: 'http://localhost:8643'

【问题讨论】:

    标签: google-chrome selenium phantomjs behat headless


    【解决方案1】:

    要在 Google Chrome 上运行测试,您需要 chromedriver
    然后您可以使用 chromedriver 正在侦听的端口(默认为 9515)而不是 PhantomJs 8643。那时您不再需要 Selenium。
    最后,您将--headless 标志传递给chrome,因此您不需要xfvb。

    一个配置示例:

    # behat.yml
    default:
        extensions:
            # ...
            Behat\MinkExtension:
                base_url: 'http://myurl.com/'
                sessions:
                    default:
                        selenium2:
                            browser: chrome
                            # Note: I'm not totally sure you still need the /wd/hub path
                            wd_host: http://localhost:9515/wd/hub
                            capabilities:
                                chrome:
                                    switches:
                                        - "--headless"
    

    更多文档:https://developers.google.com/web/updates/2017/04/headless-chrome

    【讨论】:

      【解决方案2】:

      这在 Ubuntu 16.04 LTS 上对我有用

      default:    
        extensions:
          Behat\MinkExtension:
            sessions:
              default_session:
                selenium2:
                  browser: chrome
                  wd_host: http://127.0.0.1:9515
                  capabilities:
                    chrome:
                      switches:
                        - "--headless"
                        - "--disable-gpu"
      

      【讨论】:

        猜你喜欢
        • 2023-01-14
        • 1970-01-01
        • 1970-01-01
        • 2018-06-09
        • 1970-01-01
        • 2022-01-13
        • 2018-08-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多