Thursday, January 9, 2014

Internet Explorer Configuration With Selenium WebDriver


Previously we execute all test on firefox but here we try to do something with Internet Explorer(IE).

IE driver does not come with Selenium webdriver package so we need to download separately and configure it to run the script properly.Now we learn how to configure IE driver :

Step1

Download IE Driver Server from here.We can download 32 bit 64 bit driver as per our test environment.



 Step 2

 Extract file from downloaded zip file.


Step 3

 Open the extracted folder and get "IEDriverServer.exe" file.

Step 4

Copy the directory path where IEDriverServer.exe file exists and put it into the environment variable under user variable.To open Environment variable path we just need to right click on My Computer -> Properties ->Advanced then click on Environment Variables.



 Step 5

If we use vista onwards machine then we check "Enable Protected Mode" from Security tab for all zone of IE settings.



If enable this option is not possible then put this code on our test script

DesiredCapabilities capabilitiesIE = DesiredCapabilities.internetExplorer();
            capabilitiesIE.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);


WebDriver driver = new InternetExplorerDriver(capabilitiesIE);

Step 6

Set the IE zoom 100% from view option.

After opening the IE it give an Warning in output view of our JAVA IDE like

Started InternetExplorerDriver server (32-bit)
2.39.0.0
Listening on port 54001
Jan 9, 2014 4:39:20 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
Jan 9, 2014 4:39:21 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request 

We can ignore this,actually this shows because IE driver is slow so it cannot communicate quickly with port 54001.

In below a sample code is there

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package seleniumwebdriver;

import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

/**
 *
 * @author Administrator
 */
public class IEDriverSetUp {

    public static void main(String args[]) {
        try {
            File ieExecutable = new File("C:/IEDriverServer_Win32_2.39.0/IEDriverServer.exe");
            System.setProperty("webdriver.ie.driver", ieExecutable.getAbsolutePath());
            DesiredCapabilities capabilitiesIE = DesiredCapabilities.internetExplorer();
            capabilitiesIE.setCapability(
                    InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
            WebDriver driver = new InternetExplorerDriver(capabilitiesIE);

            driver.navigate().to("http://www.google.com");
        } catch (Exception ex) {
            Logger.getLogger(IEDriverSetUp.class.getName()).logp(Level.SEVERE, IEDriverSetUp.class.getName(), null, null, ex);
        }
    }
}

 




2 comments:

  1. How to set desired capabilities for IE to download any file?

    ReplyDelete
    Replies
    1. Sorry for late reply I don't have any idea on this. I am also finding this,if you get any information then please share with me it will be very helpful for me also. I know how to set this on firefox profile to download a file and discussed on FileDownload Using Firefox Profile(http://startingwithseleniumwebdriver.blogspot.com/2015/08/filedownload-using-firefox-profile.html).

      So please share this if you found anything.

      Delete