0

I am using selenium server 2.28 on windows machine. I have set up the hub and node. I am using .net to write my test cases. I am using the following code to use custom FireFox (17.0.1) Profile with the user agent changed(to iPhone).

FirefoxProfileManager profileManager = new FirefoxProfileManager();
FirefoxProfile profile = profileManager.GetProfile(FireFox_Profile_Name);
profile.SetPreference("general.useragent.override", _sUserAgent);
DesiredCapabilities capability = DesiredCapabilities.Firefox();
capability.SetCapability(FirefoxDriver.ProfileCapabilityName, profile);

And I am instantiating a RemoteWebDriver instance like this:

driver = new RemoteWebDriver(new Uri("hub_uri"), capability);

When I check the about:config in the instance of firefox on the node machine, I don't see the general.useragent.override preference at all. If i use:

driver = new FirefoxDriver(profile); 

The preference is set correctly. Am I missing something?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
S.S
  • 3
  • 2
  • Did you also try looking at the useragent value at whatsmyuseragent.com from the browser instantiated by webdriver? Just to make sure..? – A.J Jan 08 '13 at 06:57
  • A.J, I just checked and the user agent hasn't changed. – S.S Jan 08 '13 at 16:38

2 Answers2

2

I am trying to do something very similar at the moment (setting Firefox to use Windows authentication).

In my (somewhat limited) experimentation to make this work, using just profile will work with a local driver instance, but not when talking to Selenium Server. I can get the profile to be passed to Selenium Server by using profile.ToBase64String() as hinted to here.

jheppinstall
  • 2,338
  • 4
  • 23
  • 27
  • Thanks @jheppinstall that worked (although not completely). When I use the existing profile and pass it using `ToBase64String()`, I get an error on the grid hub `java.util.zip.ZipException: invalid entry size (expected... but got...`. I created a new profile and then made changes to the profile's preferences before converting it using `ToBase64String()'. This way I was able to pass the profile to the node. – S.S Jan 15 '13 at 17:03
0

Here's how to pass the user agent in Grid 2 using Python. If you don't want the proxy, just remove it.

    myProxy = IP:PORT
    proxy = Proxy({
        'proxyType': ProxyType.MANUAL,
        'httpProxy': myProxy,
        'ftpProxy': myProxy,
        'sslProxy': myProxy,
        'noProxy': '' # set this value as desired
        })

    desired_capabilities = webdriver.DesiredCapabilities.FIREFOX.copy()   
    browser_profile = webdriver.FirefoxProfile()          
    browser_profile.set_preference("general.useragent.override", 'USERAGENT' )           
    desired_capabilities["firefox_profile"] = browser_profile.update_preferences() 
    driver = webdriver.Remote(   command_executor='http://IPADDRESS:4444/wd/hub',desired_capabilities=desired_capabilities, browser_profile=browser_profile, proxy = proxy) 

Hope that helps

slh
  • 21
  • 2