Passing Custom Headers to Selenium from Capybara

安稳与你 提交于 2019-12-08 04:19:31
wrtsprt

We are using an extra piece of rack middleware (for the test environment) before our application. There you can do anything to the env / request and its completely transparent for the application and all drivers.

you could try and create a new Selenium Driver, a new Profile and overriding the headers on this new profile. I had to do something similar to spoof different user agents.

Capybara.register_driver :mobile_browser do |app|
  require 'selenium-webdriver'

  profile = Selenium::WebDriver::Firefox::Profile.new
  profile['general.useragent.override'] = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7"

  Capybara::Driver::Selenium.new(app, {:browser => :firefox, :profile =>  profile})
end

I'm not sure if you can, though, modify the headers when the steps are running - I'm sure you can, using the Selenium API.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!