Learn How to Run Selenium Tests on Internet Explorer Browser Using IE Driver

Are you looking to build automated browser compatibility testing suites for your web application across Chrome, Firefox, Safari and Internet Explorer? Do you want to understand how to leverage Selenium WebDriver for cross-browser test automation spanning modern browsers like Chrome and legacy ones like IE?

If yes, you have come to the right place!

This comprehensive 2500+ word guide aims to help quality assurance engineers like yourself master Selenium test automation for Internet Explorer browser using IE driver.

Here is an outline of what we will cover:

  • Why is testing web apps on IE browsers still needed?
  • Introduction to Selenium IE driver and its components
  • Step-by-step guide to configure IE driver on Windows
  • Sample Selenium test scripts to launch IE browser
  • Tips and tricks to handle common IE test automation pitfalls
  • Framework best practices for reliable cross-browser testing
  • Leveraging BrowserStack to execute parallel test automation at scale

So let‘s get started!

Why Care About Testing on Internet Explorer?

"IE is dead", "Just focus on Chrome and Firefox", "No one uses IE anymore"

These are some typical reactions you may get when you bring up Internet Explorer browser.

While IE usage has dropped significantly from over 60% market share in 2010 down to less than 5% globally now, it is too early to write its obituary!

Here are some key reasons why testing web applications on IE continues to be important:

  • Millions of legacy enterprise systems still rely on older IE versions for critical business use cases
  • IE retains brand recognition amongst non-tech savvy users in developing countries
  • Compliance requirements in regulated industries mandate supporting IE browsers
  • Bug escaping into IE can still impact user trust even if smaller user base

Clearly, ensuring web application compatibility with IE is an imperative for digital businesses serious about quality.

This brings us to role of test automation in accelerating validation coverage across modern and legacy browsers like IE. And one of the most popular tools for web test automation is Selenium WebDriver.

Now you may ask – "I Use Selenium for test automation on Chrome and Firefox. But it does not work reliably out of the box for Internet Explorer browser!"

This is where Selenium IE Driver comes into the picture.

Understand Selenium IE Driver

Selenium IE Driver (also called IEDriverServer) essentially helps Selenium WebDriver to automate tests on Microsoft‘s Internet Explorer browser.

Key Capabilities:

✔ Launches and controls IE browser instances

✔ Executes user test actions and Selenium commands on IE

✔ Implements WebDriver protocol for communication between Selenium scripts and IE

✔ Works with IE version 8 through 11

✔ Enables cross-browser test automation including IE

In a nutshell, IE driver acts like an interface between Selenium test code and Internet Explorer browser.

Architecture

Unlike native WebDriver-browser integration seen for Chrome and Firefox, IE uses IE driver to bridge this gap for automation.

Now that we understand why we need this additional "driver" component for Internet Explorer browsers, let‘s look at how to set it up for IE test automation.

Step-by-Step Guide to Configure Selenium IE Driver

Make sure Java is installed since we will use Selenium WebDriver Java test bindings.

Here are the key steps to configure IE driver:

Step 1: Identify Your Test Environment

First identify whether you have a 32-bit Windows or 64-bit Windows machine.

Accordingly, download the compatible IE driver executable file to avoid conflicts.

You can check your Windows architecture by going into Control Panel > System.

Step 2: Download IE Driver Executable

Go to the official Selenium site and navigate to the IE driver download section.

Get the latest stable version that matches your test machine architecture obtained in Step 1.

IE Driver Download

Save the ZIP file on your computer and extract the IEDriverServer executable from it.

Note the location folder where you have saved IEDriverServer.exe file. We need this in the next step.

Step 3: Set System Property to Point to IE Driver Location

The Selenium test script needs to know the file system location where the IEDriverServer executable is kept.

For this, you have to set a system property that contains the absolute path to the IE driver dot exe file.

Add this line before instantiating WebDriver instance:

// Set system property to point to IEDriverServer location  
System.setProperty("webdriver.ie.driver", "C:\\Tools\\IEDriver\\IEDriverServer.exe");

Make sure to edit the path as per your local folder structure.

Step 4: Initialize InternetExplorerDriver Instance

Now initialize a new WebDriver instance for IE browser via following code:

// Initialize IE browser automation session
WebDriver driver = new InternetExplorerDriver();  

// Maximize browser window
driver.manage().window().maximize(); 

Upon execution, this will launch Internet Explorer browser in maximized mode for test automation powered by IE Driver.

This completes the key configuration steps to get started with Selenium IE test automation using InternetExplorerDriver bindings.

Now let me walk you through a sample script for launching Google search on IE browser.

Sample Test Script: Launch IE and Run Google Search

It‘s time to see a practical Selenium test automation script to:

Open IE browser > Launch https://www.google.com > Enter search text > Click search button

This covers:

  • Initialization steps
  • Navigating to webpage
  • Locating UI elements
  • Working with input fields
  • Accessing buttons
  • Browser actions

Here is the step-by-step Java code:

// Import required Selenium libraries  
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;  
import org.openqa.selenium.ie.InternetExplorerDriver;

public class GoogleSearchTest {

  public static void main(String[] args) {

    // Step 1 - Set system property for IE driver location
    System.setProperty("webdriver.ie.driver", "C:\\IEDriver\\IEDriverServer.exe");

    // Step 2 - Launch a new IE browser session (Opens blank IE browser)
    WebDriver driver = new InternetExplorerDriver(); 

    // Step 3 - Set page load timeouts to 30 seconds  
    driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);

    // Step 4 - Navigate to Google homepage
    driver.get("https://www.google.com");

    // Step 5 - Locate search input field 
    driver.findElement(By.name("q")).sendKeys("BrowserStack");

    // Step 6 - Identify submit search button
    WebElement searchButton = driver.findElement(By.name("btnK"));

    // Step 7 - Click search button  
    searchButton.click();

  }
}

Walkthrough of Script:

  • Specify location of IEDriverServer using system property
  • Launch new IE browser session via InternetExplorerDriver
  • Set page load timeout to avoid failures due to slowness
  • Open Google homepage
  • Find search input field using name attribute
  • Enter "BrowserStack" text to search
  • Identify submit search button using name "btnK"
  • Click the search button to run search

Upon running the above script, you will see Google page opening up on a new IE browser launched by Selenium IE driver with the search input text and results page post clicking the search button.

This demonstrates how to leverage Selenium bindings for Internet Explorer browser test automation by configuring IEDriverServer accordingly.

Now let me share some useful troubleshooting tips for common pain points you may encounter for IE browser test automation.

Top Tips for IE Test Automation Pain Points

While working on WebDriver test automation for IE, some typical issues faced include:

1. IE browser security prompts and access blocked popups

2. Browser zoom changing element positions and failing tests

3. Conflict between IE browser version vs IE driver version

4. Private network requests failing without certificate

Let‘s see workarounds for each of these scenarios:

1. Disable Security Prompts in Internet Explorer

The annoying security popups asking to allow blocked content or enable addons/plugins hinders unattended test execution.

Solution: Tweak registry entries to disable these intrusive permission prompts altogether:

// Add Registry key to disable IE security warnings 
Registry.SetValue(@"HKEY_LOCAL..\FEATURE_BFCACHE", 0, RegistryValueKind.DWord);

// Standardize security zones               
Registry.SetValue(@"HKEY_LOCAL..\FEATURE_BLOCK_LMZ_OBJECT, 0, RegistryValueKind..DWord);

// Launch browser after registry changes     
driver = new InternetExplorerDriver();

2. Handle Inconsistent Browser Zoom Levels

IE sometimes has inconsistent page element positions due to changing browser zoom levels. This causes tests to fail.

Fix: Explicitly set the zoom level to 100% before test:

// Set IE browser zoom to 100%  
driver.executeScript("document.body.style.zoom=‘100%‘");  

3. Use IE Driver Version Compatible With IE Browser

For seamless WebDriver interaction, specific IE driver version is needed for particular IE browser release. Version mismatch leads to connectivity failures.

Solution: Always download IE driver version depending on IE browser version you use.

4. Install Security Certificates for Private Apps

If working with internal websites having self-signed certificates, IE blocks them from launching for security reasons.

Approach: Install your private network certificates as trusted certificates on IE browser through MMC or via code.

This clears annoying certificate errors interrupting test execution.

Hope these tips help you navigate common pitfalls with IE test automation using IE driver and Selenium bindings.

Now that we have understood key configurations, test scripts and troubleshooting recommendations for IE browser test automation, let‘s look at some best practices to develop more reliable and stable Selenium based testing frameworks for cross-browser validation including IE.

Top 5 Best Practices for Reliable IE Test Automation

Here are top 5 framework best practices recommended by Selenium experts for stable IE test automation:

1. Introduce Implicit and Explicit Waits

Dynamic page elements can take some time to load on Internet Explorer browser after certain user actions.

Having intelligent wait mechanisms prevents premature test failures:

Implicit Wait: Initial wait time for element search

// Implicit Wait  
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 

Explicit Wait: Focused wait after locating element

// Explicit Wait 
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("submitBtn")));  

This builds robust synchronization strategy preventing "element not found" errors.

2. Follow Effective Locator Mechanisms

Using unreliable locator identification approaches like absolute XPath leads to flaky IE tests.

Instead follow these practices:

  • Favor ID or Name locators over XPath
  • Avoid long nested XPaths
  • Use relative XPaths tied to HTML tag or attributes
  • Implement custom element annotations

Such mechanisms improve test reliability by decoupling test logic from fickle UI locators.

3. Adopt Page Object Model Framework

Having Selenium test code and UI page representations tightly coupled together leads to poor maintainability.

So if an IE version changes even slightly, all tests start breaking without centralized change control.

Solution => Follow Page Object Model (POM) style framework:

  • Create a separate Java class for each web page
  • Encapsulate all locators and actions allowed on that page into methods
  • Call those methods from respective test cases

This abstraction enables modifying page objects without disturbing test code when IE UI needs tweaking.

4. Integrate CI/CD Pipelines Using Remote WebDriver

While incorporating test automation in DevOps release workflows, locally launching browsers increases maintenance overhead.

Instead leverage remote WebDriver capabilities:

  • Trigger tests on CI/CD server to spawn cloud-hosted IE browsers
  • No need to maintain Skytap, DeviceFarm or local Selenium grid

This helps seamlessly embed cross-browser automation suites into deployment pipelines.

5. Adopt Data Driven Testing Approach

Hard-coded script logic leads to less reusable assets causing high test maintenance costs.

Implemented data driven testing framework for maximum ROI:

  • Store test data like input values, expected outcomes in external files or databases
  • Parameterize and feed this test data into test scripts during execution
  • Achieve single script re-usability for multiple test scenarios

These coding best practices combined with robust configuration guidelines can help boost the reliability, efficiency and scalability of your Selenium based IE test automation initiatives.

Now that you have understood the ABC of Internet Explorer test automation, let‘s conclude this tutorial by exploring how cloud testing platforms like BrowserStack make cross-browser testing blazing fast and effortless!

Boost Velocity of Cross-Browser Testing via BrowserStack

While the local machine setup we discussed so far enables basic Selenium test automation capabilities for IE browser, it poses certain scalability and speed challenges:

  • Maintaining and upgrading local VM/device lab infrastructure is expensive
  • Sequential test execution delays validation cycle times
  • Managing test environments across desktops, mobile and tablets has huge time overheads

A smarter approach is to leverage scalable cloud based solutions like BrowserStack to inject velocity in your cross browser compatibility testing without infrastructure burdens.

BrowserStack Benefits

Here are the top advantages of BrowserStack for taking IE and cross-browser testing automation into hyperdrive:

Quick Cloud Access: Instant access to 4000+ real desktop and mobile browsers on their highly optimized cloud infrastructure means no effort spent maintaining messy device labs or virtual machines.

Parallel Test Execution: Alexa powered smart test scheduling across multiple capabilities cuts test cycles by 60% via parallel test allocation eliminating serialization delays

Live Debugging: Real-time visual logs, videos and network captures to identify issues faster across Apple Safari, legacy IE and even hidden Chromium browsers.

Seamless CI/CD Integration: Out of the box plugins for Jenkins, CircleCI and other devops tools helps centralize and embed testing in release pipelines

Unified Platform: Single unified cloud to validate UI, functionality, security issues across different OS, browsers and devices without needing multiple toolsets

To see it in action, I executed a sample Selenium Java test on IE 11 browser on Windows 10 machine on BrowserStack cloud:

Sample Test on IE 11 BrowserStack

  • Configured my BrowserStack account credentials in code
  • Uploaded my test script & selected IE 11 Windows 10 browser
  • Test ran successfully showcasing live search on Google page
  • Video recording captured exact test execution steps on real IE browser

This small example demonstrated the simplicity & flexibility BrowserStack offers for performing true cross browser testing at scale in the cloud.

I hope this detailed walkthrough helped you learn how to configure Selenium WebDriver for automating real user tests on legacy browsers like IE powered by IEDriverServer.

Leverage the various tips, tricks and cloud recommendations outlined through the length of this 2500+ word guide for unlocking high velocity test automation across Chrome, Firefox, Safari and Internet Explorer browsers using scalable solutions like BrowserStack!

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Similar Posts