Wednesday, September 10, 2014

Using the Internet Explorer WebDriver Implementation from Microsoft

Microsoft recently delivered an implementation of an Internet Explorer driver. This is great news, and should be a real help to users of the Selenium project. Concurrent with that release, the IEDriverServer.exe has been updated to take advantage of this new implementation.

The integration with IEDriverServer has been implemented as a new command-line switch on IEDriverServer.exe. By launching IEDriverServer.exe using the --implementation=<value> switch, you can force the executable to use a specific driver implementation. Valid values for the switch are:
  • LEGACY - Uses the existing open-source driver implementation
  • VENDOR - Forces the driver to use the Microsoft implementation, regardless of whether prerequisites are met, or whether the installed version of Internet Explorer is the proper version (will throw an exception when creating a new session if the prerequisites are not installed and configured properly)
  • AUTODETECT - Uses the Microsoft implementation for IE 11, if the prerequisites are installed, falling back to the open-source implementation if the components are not present (still under development in the IEDriverServer.exe code)
If no value is specified, or if the value passed in is not one of those listed above, IEDriverServer.exe will use the existing open-source implementation. This is only a temporary default; the intent is for the default to shift to be the Microsoft implementation as the specification on which it is based matures.

Prerequisites

In order to use the Microsoft implementation, you'll need a few prerequisites.

Caveats and Provisos

This integration with IEDriverServer.exe should be considered experimental at the time of this writing. First, please realize that the Microsoft implementation only supports IE11. There are no announced plans for Microsoft to support other versions of Internet Explorer with this WebDriver implementation.

Also, the Microsoft implementation strictly follows the W3C WebDriver Specification. Since the spec is currently an editors' draft, it does not completely describe the WebDriver API. In other words, there are some features that are implemented in the open-source implementation that are not documented yet in the spec, which in turn means that they are not implemented in the Microsoft implementation.

Additionally, there are some small differences in the objects sent back and forth across the JSON Wire Protocol between the spec and the open-source implementation. The implications are that there may need to be changes made to the individual language bindings to pass the proper JSON payload across to the Microsoft implementation. There is considerable pressure not to update the language bindings, since, again, the spec is currently an editors' draft, and there have been bugs filed against it to have it's protocol more closely match the existing open-source language bindings' implementations.

In the interest of allowing users to be able to experiment with the Microsoft implementation, the .NET bindings have had all of the necessary protocol changes grafted in, with explicit comments in the source code to have the changes removed when the spec is finalized and all implementations are consistent. The Java bindings have a partial implementation, and can launch IEDriverServer.exe with the proper command-line parameters to enable use of the Microsoft implementation, but the protocol changes have not yet been implemented. Unfortunately, there is no timetable for this work for other language bindings.

Example

So here's an example of what the code looks like to enable and use the Microsoft implementation of the IE driver, using C# code. It's pretty straightforward.

public static void DriveIEUsingMicrosoftImplementation()
{
    InternetExplorerDriverService service =
        InternetExplorerDriverService.CreateDefaultService();
    service.Implementation = InternetExplorerDriverEngine.Vendor;
    IWebDriver driver = new InternetExplorerDriver(service);
} 

Conversely, one could launch IEDriverServer.exe with the appropriate command-line switch and use RemoteWebDriver to talk to that running instance.

13 comments:

  1. Hi Jim,

    Thanks for writing this blog. I explored this new implementation developed by Microsoft and here are my few findings.

    1. I used the Java client bindings (2.43.1) but I could not find the method service.Implementation , I think it is not yet available in Java bindings.
    2. So I have used command line switch to point to VENDOR implementation.But using this I could only able to launch the browser and navigate to a URL. I could not find a element as it throws the error session does not exist. Also I could do little operations like maximizing the browser.

    I think it would take some time to get this more stable so that every body can adopt it.

    Please let me know if my observations are not correct.

    ReplyDelete
    Replies
    1. In the Java language bindings, the method is withEngineImplementation(). As the blog post clearly states, "[t]he Java bindings have a partial implementation, and can launch IEDriverServer.exe with the proper command-line parameters to enable use of the Microsoft implementation, but the protocol changes have not yet been implemented."

      Delete
    2. Thanks!! Sorry I missed that line in the blog.

      Delete
    3. Is possible that this is a reason why I get timeout exception for VENDOR on Java?

      Delete
    4. I'm certain that's why you'll have issues using the Java language bindings. Since the Microsoft implementation is incomplete, and since there are changes due to come in the Microsoft implementation to conform to the spec and open-source implementation of the protocol, there isn't any motivation to update the language bindings yet.

      Delete
  2. Hi,

    I am using batch file to run node:
    java -jar selenium-server-standalone-2.43.1.jar -role node -timeout=25 -nodeConfig nodeconfig.json -Dwebdriver.ie.driver=.\IEDriverServer.exe
    and json file:
    {
    "capabilities": [
    {
    "browserName": "internet explorer",
    "maxInstances": 5,
    "seleniumProtocol": "WebDriver",
    "version": "11"
    }],
    "configuration": {
    "maxSession": 5,
    "port": 5555,
    "register": true,
    "registerCycle": 5000,
    "hubPort": 4444,
    "hubHost": "myHubHost"
    }

    Can You tell me how to launch IEDriverServer.exe with the appropriate command-line switch and use RemoteWebDriver to talk to that running instance?
    I have problem to set command-line switch to turn on VENDOR mode

    ReplyDelete
    Replies
    1. i added:

      InternetExplorerDriverService.Builder b = new InternetExplorerDriverService.Builder();
      b.withEngineImplementation(InternetExplorerDriverEngine.VENDOR);

      WebDriver driver = new InternetExplorerDriver(b.build());

      Delete
    2. I am using .Net for test development.

      Please let me know if I understand configuration for RemoteWebDriver right:
      - install KB2990999 and turn on protected mode
      - Add switch --implementation=VENDOR:
      java -jar selenium-server-standalone-2.48.2.jar -role node -timeout=25 -nodeConfig nodeconfig.json -Dwebdriver.ie.driver=.\IEDriverServer.exe --implementation=VENDOR

      That is all, or do I have to make some implementation while creating RemoteWebDriver?

      Driver is used for multiple browser types so Driver for IE_11 is created by capabilities:
      capabilities = DesiredCapabilities.InternetExplorer();

      Right now in above configuration tests are passing, with or without KB2990999 installed, so vendor mode is not used.

      Delete
  3. Please, can you tell me how I can recognize that my tests were performed with legacy or vendor engine?

    ReplyDelete
    Replies
    1. I assume you can tell when IEDriver says:

      Driver implementation set to VENDOR

      Delete
  4. I can't seem to execute any useful commands against the VENDOR version of IEdriver.

    I just get back invalid JSON/unknown commands for simple things like findElement(By.Id).

    I'm using the java bindings.

    ReplyDelete
    Replies
    1. I am however able to spawn a browser window and use get.

      Delete
  5. Hi Jim,

    I tried to run a test with the following configuration:
    - Windows 7 SP1 x64
    - installed KB2976627 + KB2990999, but not KB3025390 on that machine
    - set the Options in IE
    - used C# language bindings V2.43 and IEDriverServer 2.44
    - run a test simple test with InternetExplorerDriverEngine.Legacy --> passed
    - run the same test with InternetExplorerDriverEngine.Vendor
    --> browser starts
    --> navigation to page succeeded
    --> access to a web element failed with OpenQA.Selenium.WebDriverException : Unexpected error. Session does not exist

    Any ideas what the problem could be? Is that a known issue?

    ....and I have a further question regarding automation of https pages. I tried to automate a https page with the same configuration as mentioned above by using InternetExplorerDriverEngine.Legacy.
    --> Browser starts
    --> page will be loaded, but then nothing happens and after some time an exception occurs: The HTTP request to the remote WebDriver server timed out after 60 seconds

    Is there a general issue regarding automation of https pages on IE?
    It would be great to get a feedback regarding that general issue also.

    MANY THANKS IN ADVANCE!

    ReplyDelete