Running tests in IE Explorer is quite easy. Internet Explorer cannot be launched directly, we have to communicate with the Internet explorer via Internet explorer driver. So what is an Internet Explorer driver and how do we get it. Let’s learn about it throughout these 3 chapters here.
Internet Explorer Driver server
Internet explorer driver server is the link between your tests in Selenium and the Internet Explorer browser. As selenium WebDriver has no native implementation of IE, we have to direct all the driver commands through IE driver server. IE driver server is an executable file that you need to have in one of the system path before starting your tests.
To download the server you can go here. Just choose the latest version and download it based on whether you are on the 32 bit or a 64-bit operating system.
Download the zip file and extract it in a known location on your computer.
Launching IE using Selenium WebDriver
Approach 1: Setting up the webdriver.ie.driver property
Selenium Webdriver has a class called InternetExplorerDriver that is used to launch and control IE browser. The code to launch IE Driver is exactly the same as if you were launching a ChromeDriver or a FirefoxDriver. All we need to do is specify the correct path to the IEDriver server and use the InternetExplorerDriver class. Like this
1 2 3 4 5 6 7 8 9 10 11 12 | public class LaunchingIE { public static void main(String[] args) { //Path to the folder where you have extracted the IEDriverServer executable String service = "C:\\Users\\abc\\Desktop\\Server\\IEDriverServer.exe"; System.setProperty("webdriver.ie.driver", service); InternetExplorerDriver driver = new InternetExplorerDriver(); driver.get("https://yahoo.com"); } } |
System.setProperty is used to set a webdriver.ie.driver property to the path of IE driver server executable. This helps Selenium to start the IE Driver server and then launch IE Browser.
Approach 2: Using the Service builder
Internet driver service is a class that helps you configure the IE driver server. Instead of specifying the executable path as a system property you can directly specify it in a Driver Service like this. In the below code we will be using InternetExplorerDriverService.Builder class. We can also specify the log file path, which will contain the IE driver logs. These logs can be helpful in debugging issues later on. Here is the full sample code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public class LaunchingIE { public static void main(String[] args) { String exePath = "C:\\Users\\abc\\Documents\\IEDriverServer\\IEDriverServer.exe"; InternetExplorerDriverService.Builder serviceBuilder = new InternetExplorerDriverService.Builder(); serviceBuilder.usingAnyFreePort(); // This specifies that sever can pick any available free port to start serviceBuilder.usingDriverExecutable(new File(exePath)); //Tell it where you server exe is serviceBuilder.withLogLevel(InternetExplorerDriverLogLevel.TRACE); //Specifies the log level of the server serviceBuilder.withLogFile(new File("C:\\Users\\abc\\Documents\\logFile.txt")); //Specify the log file. Change it based on your system InternetExplorerDriverService service = serviceBuilder.build(); //Create a driver service and pass it to Internet explorer driver instance InternetExplorerDriver driver = new InternetExplorerDriver(service); driver.get("https://toolsqa.com"); } } |
This is how you can start a simple IE browser and use it for your tests. In the coming chapters, we will talk more about the IEDriverServer and different control switches to the server.