初始化后是否可以设置Selenium :: Driver :: Proxy

时间:2018-07-05 12:02:10

标签: ruby-on-rails rspec capybara selenium-chromedriver

我目前正在使用Capybara和Chromedriver在我们的Rails应用程序中运行功能测试。目前,我可以看到在初始化驱动程序时可以通过args设置代理。

    Capybara.register_driver :selenium_chrome do |app|
      Capybara::Selenium::Driver.new(
        app,
        browser: :chrome,
        args: [
          '--window-size=1240,1400',
          "--proxy-server=#{s.url}",
          '--proxy-bypass-list=127.0.0.1'
        ]
      )
    end

但是,我只希望特定的测试来代理特定的端口,因为我还使用Capybara :: Discoball来启动Sinatra应用程序,因为我正在将该应用程序代理到外部请求。因此,在初始化到当前启动的Sinatra应用程序的端口后,我需要能够更改代理。初始化之后可以吗?

1 个答案:

答案 0 :(得分:0)

否,但是您可以使用其他名称注册另一个驱动程序,然后指定将其用于需要它的测试中。假设您正在使用默认的capybara rspec配置,例如

Capybara.register_driver :selenium_chrome do |app|
  # register the driver without proxy here
end

Capybara.register_driver :selenium_chrome_proxy do |app|
  # register the driver with proxy config here
end

Capybara.javascript_driver = :selenium_chrome # register default JS driver

it "does something that doesn't need proxy", js: true do
   # test that doesn't use the proxy config
end

it "does something that needs proxy", driver: :selenium_chrome_proxy do
  # test that uses proxy
end