开发者

Add custom header in Selenium and Sauce Labs?

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 w开发者_StackOverflow中文版ant to selectively not display them for Selenium.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜