开发者

How to instantiate different versions of InternetExplorerDriver - Selenium 2?

just wondering how I can instantiate different versions of InternetExplorerDriver.

That's how I 开发者_C百科can create a IE driver:

WebDriver ieWebDriver = new InternetExplorerDriver();

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

Cheers,


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;
    }
}


Windows only supports installing a single IE version. Although some hacks exist to run multiple versions, I'm pretty sure you won't get them working with WebDriver (although I'd love to be proven wrong).

In your shoes, I would probably set up a Windows VM for each version you want to test and use RemoteWebDriver to talk to them.


To instantiate different versions, you can set the version using capability.setVersion to the required version number. At the same time, while starting the node, you need to add the following parameters in the command line:

-browser "browserName=internet explorer,maxInstances=5,platform=WINDOWS, version=8"

For supporting multiple versions at the same node, you can use "-browser" multiple times.


However, the latest IE supports "browser mode" - just press F12 and choose the browsing mode. AFAIK it works quite well - at least compared to IE8 and IE7. I'm curious if it can be accessed by javascript and changed automatically in Selenium?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜