Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to instantiate different versions of InternetExplorerDriver - Selenium 2?

just wondering how I can instantiate different versions of InternetExplorerDriver.

That's how I can create a IE driver:

WebDriver ieWebDriver = new InternetExplorerDriver();

but I am not able to differentiate between IE6, IE7, IE8 and IE9.

Cheers,

like image 717
sebarmeli Avatar asked Apr 19 '11 02:04

sebarmeli


1 Answers

Yes, you can. DesiredCapabilities have a public method which you can use:

this.SetCapability(CapabilityType.BrowserName, "internet explorer");
this.SetCapability(CapabilityType.Version, "8");
this.SetCapability(CapabilityType.Platform, "WINDOWS");

I've written extension methods to make it easier to instantiate any version by this call:

DesiredCapabilities internetExplorer8 =
                          DesiredCapabilities.InternetExplorer().SetVersion("8");
IWebDriver webDriver = new RemoteWebDriver(seleniumHubUrl, internetExplorer8);

This really makes sense if you use RemoteWebDriver and have a Selenium2 Grid/Hub set up with multiple nodes, e.g. multiple virtual machines each having a different version of Internet Explorer and each being a node connected to the hub.

And the extension:

public static class DesiredCapabilitiesExtension
{
    public static DesiredCapabilities SetBrowserName(this DesiredCapabilities desiredCapabilities, string browserName)
    {
        // make sure the browser name is lowercase
        desiredCapabilities.SetCapability(CapabilityType.BrowserName, browserName.ToLowerInvariant());
        return desiredCapabilities;
    }

    public static DesiredCapabilities SetVersion(this DesiredCapabilities desiredCapabilities, string version)
    {
        desiredCapabilities.SetCapability(CapabilityType.Version, version);
        return desiredCapabilities;
    }

    public static DesiredCapabilities SetPlatform(this DesiredCapabilities desiredCapabilities, string platform)
    {
        // make sure the platform is case sensitive, uppercase to make it work
        desiredCapabilities.SetCapability(CapabilityType.Platform, platform.ToUpperInvariant());
        return desiredCapabilities;
    }
}
like image 133
Miro Avatar answered Oct 17 '22 10:10

Miro