How to instantiate different versions of InternetExplorerDriver - Selenium 2?

拥有回忆 提交于 2019-11-29 17:57:09

问题


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,


回答1:


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.




回答2:


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



回答3:


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.




回答4:


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?



来源:https://stackoverflow.com/questions/5710809/how-to-instantiate-different-versions-of-internetexplorerdriver-selenium-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!