public enum htmlUnitEmulation {
NONE, FIREFOX, IE6, IE7, IE8
}
private DesiredCapabilities setHTMLUnitCapabilities(htmlUnitEmulation
browserVersion) {
DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
capabilities.setJavascriptEnabled(true);
switch (browserVersion) {
case FIREFOX:
capabilities.setBrowserName("firefox");
break;
case IE6:
capabilities.setBrowserName("internet explorer");
capabilities.setVersion("6");
break;
case IE7:
capabilities.setBrowserName("internet explorer");
capabilities.setVersion("7");
break;
case IE8:
capabilities.setBrowserName("internet explorer");
capabilities.setVersion("8");
break;
default:
break;
}
return capabilities;
}
driverObject = new
HtmlUnitDriver(setHTMLUnitCapabilities(htmlUnitEmulation.NONE));
This should be expandable in the future. I also use a properties file to
set the type of emulation, the value in the properties file is matched to
one of the values in the enum (or none if it can't be matched).
http://htmlunit.sourceforge.net/gettingStarted.html
Peter
--
You received this message because you are subscribed to the Google Groups
"Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to
selenium-user...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/selenium-users?hl=en.
--
This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.
If you have received this email in error please notify postm...@ardescosolutions.com
Jayesh,
I’ve obviously misunderstood your requirement, the code I supplied is setting HTMLUnit to simulate the browsers, not modify the user agent string (Although it will probably implicitly do that, but you are stuck with a limited selection that are currently supported by Selenium’s capabilities code).
capabilities.setCapability("UseragentName", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.13 (KHTML, like Gecko) Chrome/24.0.1290.1 Safari/537.13");
//capabilities.
capabilities.setBrowserName("Mozilla/5.0");
capabilities.setPlatform(Platform.MAC);
capabilities.setVersion("Chrome/24.0.1290.1 Safari/537.13");