Add custom header in Selenium and Sauce Labs?

时光怂恿深爱的人放手 提交于 2019-12-08 00:52:12

问题


I use Selenium and Sauce Labs for testing.

Is there a Selenium property to add a custom header or append a string to the user agent (like "using Sauce Labs")?

I want to selectively not load some content for Selenium, because it is causing the units tests to be too finicky. I have some widgets on the page, and sometimes the page doesn't complete loading... so I want to selectively not display them for Selenium.


回答1:


I'm not familiar with Sauce Labs, but you can certainly do this on some Selenium setups, by changing the general.useragent.override, as follows (which may be adaptable):

Using the FirefoxDriver you can:

FirefoxProfile profile = new FirefoxProfile();
profile.addAdditionalPreference("general.useragent.override", "some UA string");
WebDriver driver = new FirefoxDriver(profile);

with Cabybara you can:

Capybara.register_driver :iphone do |app|
  require 'selenium/webdriver'
  profile = Selenium::WebDriver::Firefox::Profile.new
  profile['general.useragent.override'] = "iPhone"

  Capybara::Driver::Selenium.new(app, :profile => profile)
end


来源:https://stackoverflow.com/questions/6525852/add-custom-header-in-selenium-and-sauce-labs

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