Table of contents
1.
Introduction
2.
Getting Started
3.
Selenium SafariDriver
3.1.
Configuration
3.2.
Implementation
3.2.1.
Program
3.2.2.
Output
4.
Selenium IE Driver
4.1.
Configuration
4.2.
Implementation
4.2.1.
Program
5.
FAQs
6.
Key Takeaways
Last Updated: Mar 27, 2024
Easy

Selenium Tests with IE and Safari

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Web Testers and QAs need to test their web applications on different browsers and platforms to ensure performance consistency over browsers. Both Safari and Internet Explorer(IE) are significant browsers, with Safari having a 16% user base(second highest after chrome) and IE having 7% of the market share. Therefore, web developers worldwide need to ensure that their websites are thoroughly tested and optimized for all versions of IE and Safari.

We will explore the configuration and implementation of running Selenium tests on Safari and IE using Java with the help of examples through this article. 

Getting Started

Before going further with the examples, you must set up Selenium in your project to run the test examples. You can do this by adding the .jar file to your project directory or adding Selenium as a dependency on your Maven or Gradle build files. The latter is the recommended approach.

pom.xml(Maven)

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.3</version>
</dependency>

 

build.gradle(Gradle)

dependencies{
compile group: ‘org.seleniumhq.selenium’, name: ‘selenium-java’, version: 4.1.3
}

Selenium SafariDriver

The SafariDriver is the link between your Selenium tests and the Safari Browser. We use the SafariDriver to implement the WebDriver in the Safari Browser. The Safari Browser provides the implementation of the SafariDriver as a plugin. Here, SafariDriverServer acts as the server, and Selenium-Java/Language binding acts as the client providing a suitable match for the client and server machine.

Configuration

Setting up to run tests using the SafariDriver(v10 and above) is very simple on an Apple Mac system. You can find the Safari driver in the following path on your system: /usr/bin/safaridriver because Safari now provides native support for the WebDriver API. If you do not have a Mac machine, you can use cloud-based tools to access Safari in a local system.

Before performing automation testing on Safari, you must enable the Remote Automation feature from the developer menu. You can achieve that by using the Allow Remote Automation button in the Safari Develop menu.

Implementation

Now that you have configured SafariDriver for your system, you can write a test case and run it using the Safari browser.

We will use the Eclipse IDE to run our Java Selenium test case on Safari using the SafariDriver. Our test case should open Google Chrome, go to www.google.com, and enter Coding Ninjas in the search box. The test code looks something like this.

Program

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.safari.SafariDriver; 


public class SafariTest { 


public static void main(String[] args) { 


// Instantiate a SafariDriver class. 
WebDriver driver = new SafariDriver();
driver.manage().window().maximize();


// Launchs the Website 
driver.navigate().to("http://www.google.com/"); 


// Clicks on the search text box and sends value 
driver.findElement(By.name("q")).sendKeys("CodingNinjas"); 


// Click on the search button 
driver.findElement(By.name("btnK")).sendKeys(Keys.ENTER); 



}


}
You can also try this code with Online Java Compiler
Run Code

Output

Selenium IE Driver

The Selenium Internet Explorer Driver is a stand-alone server that acts as a link between Selenium tests and Internet Explorer. It is a stand-alone server implementing the WebDriver protocol on IE.

Configuration

Firstly you will need to download the InternetExplorerDriver executable file according to your system requirements. You can download InternetExplorerDriver for your respective operating system from here. After unzipping the downloaded file, you will get the executable file(IEDriverServer.exe). 

You will also need to add the executable file to your path for it to run correctly. You can check out how to add an executable to the path for both Windows and Mac by following the configuration steps from our article on Running Selenium Tests on Google Chrome(<--link to be added–>).

Implementation

Now that you have configured InternetExplorerDriver for your system, you can write a test case and run it using the IE browser.

We will use the Eclipse IDE to run our Java Selenium test case on Safari using the SafariDriver. Our test case should open Google Chrome, go to www.google.com, and enter Coding Ninjas in the search box. The test code looks something like this.

Program

package chromeselenium;


import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;



public class IETest {
@SuppressWarnings("deprecation")
public static void main(String[] args) {


//Setting system properties of InternetExplorerDriver
System.setProperty("webdriver.ie.driver", "D:IE Driver ServerIEDriverServer.exe"); 


//Creating an object of InternetExplorerDriver
WebDriver driver=new InternetExplorerDriver();
driver.manage().window().maximize();


//Deleting all the cookies
driver.manage().deleteAllCookies();


//Specifiying pageLoadTimeout and Implicit wait
driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);


//launching the specified URL
driver.get("https://www.google.com/");


//Locating the elements using name locator for the text box
driver.findElement(By.name("q")).sendKeys("CodingNinjas");


//Click on the search button 
driver.findElement(By.name("btnK")).sendKeys(Keys.ENTER); 
}
}

You can also try this code with Online Java Compiler
Run Code

Running this code on a Windows machine with the compatible IE browser should give the same output on the IE browser as the output on the Safari browser above.

FAQs

1. How do I install Safari drivers on my Mac?

Ans: Mac devices now provide native support for automation testing. You can not install the SafariDriver manually on your Mac device. If you can not find it in /usr/path/safaridriver, you should update your Safari browser to v10 or above. 

You may also need to run /usr/path/safaridriver – enable on your terminal if you update from older Mac OS to High Sierra or above.

 

2. What is WebDriverManager Selenium?

Ans: The WebDriverManager automates the browser set up in your Selenium test code. The WebDriverManager downloads the latest version of the browser driver binary and the binary for the appropriate platform by default.

 

3. What is WebDriver interface selenium?

Ans: WebDriver is a remote control interface that enables you to introspect and control user agents or browsers. The methods in the WebDriver interface fall into three types:

  • Control of the browser
  • Selection of the WebElements
  • Debugging aids

 

4. What is the driver get in Selenium?

Ans: You can use the driver. get() method to open an URL and load the whole page. The WebDriver waits until the page loads completely before returning control to your test or script.

Key Takeaways

This article extensively discussed the SafariDriver and IEDriver and their implementation in Selenium tests using Java. The Safari browser is a highly prominent web browser, making performing web tests vital for web developers and QAs. And even though IE does not have a large user base, as a web tester, you must not leave any potential customers. So knowing how to perform Selenium tests on both Safari and IE can be handy.

We hope that this blog has helped you enhance your knowledge regarding Selenium. If you would like to learn more, check out our articles on Selenium Interview QuestionsMethods in Selenium, and Basics of Java. Do upvote our blog to help other ninjas grow. Happy Coding!

Live masterclass