5

I was working on some mobile Web automation testing using Selenium Webdriver and Ruby. Now I need to pass user agent along with Remote Webdriver Capabilities i am already passing. Is there any way i can set user agent for Mobile Web ? I am setting the capabilities as iphone and using iPhone Simulator for running my tests.

Sunilkumar V
  • 912
  • 2
  • 8
  • 28
  • Because user_agent is part of request object, This post and replies may help you http://stackoverflow.com/questions/22850898/access-to-request-object-in-request-specs – MilesStanfield Jul 08 '15 at 23:01
  • That did not help me much. I am looking for a way to pass the user agent along with the Remote Webdriver API's. I know how to pass the user agent for Web browser testing, but not sure about mobile. – Sunilkumar V Jul 09 '15 at 15:11
  • 2
    Sorry if I am missing something, but user agent is for a browser (web or mobile) and not the device itself. Hence, if you are using a simulator, you shouldn't require overriding the user-agent. And if you do want to pass a user-agent, then you would pass it for the web browser you are using on the device, and not use a simulator. Also, are you using ios-driver or (deprecated) iPhone driver? – Sam Jul 13 '15 at 23:14
  • I am using both Android and IOS driver. But the problem here is my application require custom header to be set while accessing the URL. is there any way i can modify the header using these drivers? – Sunilkumar V Jul 14 '15 at 13:58
  • 2
    You can not do it. Here http://stackoverflow.com/questions/6478672/how-to-send-an-http-requestheader-using-selenium-2 you can find an naswer from one of selenium developers. – Stan E Jul 16 '15 at 18:31
  • It would be good if you could show us the code you are using. Other than that, I would set up a proxy and route all the traffic thru that proxy, so you could do any interception you need there. – Erki M. Jul 18 '15 at 14:36

2 Answers2

0

This is not possible because WebDriver currently lacks HTTP response header and status code methods.
Link to this issue: https://code.google.com/p/selenium/issues/detail?id=141

Sunilkumar V
  • 912
  • 2
  • 8
  • 28
-1

Try something like this

capabilities = Selenium::WebDriver::Remote::Capabilities.send(:firefox, :firefox_profile => build_mobile_profile)
profile = Selenium::WebDriver::Firefox::Profile.new
profile['general.useragent.override'] = "Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"

client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 30 # for example

browser = Watir::Browser.new(:remote,
  :url                  => "https://selenium.yourdomain.com:4445/wd/hub",
  :http_client          => client,
  :desired_capabilities => capabilities
)
Ivan Danci
  • 512
  • 5
  • 24