TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Selenium Webdriver Running test on Safari Browser

Selenium Webdriver Running test on Safari Browser with Introduction, features, selenium basic terminology, what is selenium, selenium limitations, selenium vs qtp, tool suite, selenium ide, ide-installation, ide-features, ide-first test case, ide-commands, ide-creating test cases manually, ide-login test etc.

<< Back to SELENIUM

Selenium WebDriver- Running test on Safari Browser

In this section, we will learn how to run our Selenium Test Scripts on Safari Browser.

Safari Browser implements the WebDriver protocol using SafariDriver. The SafariDriver is the link between your tests in Selenium and the Safari Browser. SafariDriver has been implemented as a plugin in safari browser and this provides a perfect match of client and server machine where SafariDriverServer acts as server and Selenium-Java/Language binding acts as client.

Note: Previously SafariDriver was supporting safari browser on Windows machine but recently Apple has decided to remove its support for windows and then execution on safari has become the job of Mac machine. So for the same, we need mac machine where safari browser should be installed.

Let us consider a test case in which we will try to automate the following scenarios in Safari browser.

  • Launch Safari browser.
  • Open URL: www.google.com
  • Type the value "TheDeveloperBlog tutorials"
  • Click on the Search button.
  • Close the browser

We will create our fifth test case in the same test suite (Demo_Test).

Step1. Right click on the "src" folder and create a new Class File from New > Class. Give your Class name as "Fifth" and click on "Finish" button.

Selenium WebDriver Running test on Safari Browser Selenium WebDriver Running test on Safari Browser

Step2. Open URL: https://www.seleniumhq.org/download/ in your Safari browser. It will direct you to the 'downloads' page of Selenium official website. Scroll down through the web page and locate SafariDriver.

Step3. Click on the "Latest Release" option to download the latest version of SafariDriver.

Selenium WebDriver Running test on Safari Browser

Step4. Double click on the downloaded file.

Selenium WebDriver Running test on Safari Browser

This will launch a pop-up box on your Safari browser extension window. Click on the "Trust" button to configure WebDriver in your Safari browser.

Selenium WebDriver Running test on Safari Browser
Selenium WebDriver Running test on Safari Browser

Step5. Restart your browser.

Before writing the test script, let us first understand how we can initialize SafariDriver in Selenium. Safari browser is represented by a class called SafariDriver in the org.openqa.selenium.safari package. All we have to do is to create an instance of SafariDriver class.

Here is a sample code to do that:

WebDriver driver = new SafariDriver();

Step6. Now, it is time to code. We have embedded comments for each block of code to explain the steps clearly.

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

public class Fifth {

	public static void main(String[] args) {
		
		  // Instantiate a SafariDriver class. 	
		WebDriver driver = new SafariDriver();

		  // Launch Website
		driver.navigate().to("http://www.google.com/");
			
		  // Click on the search text box and send value
		driver.findElement(By.id("lst-ib")).sendKeys("TheDeveloperBlog tutorials");
			
		  // Click on the search button
		driver.findElement(By.name("btnK")).click();
		
		  // Close the Browser
		driver.close();
		
	}

The Eclipse code window will look like this:

Selenium WebDriver Running test on Safari Browser

Step7. Right click on the Eclipse code and select Run As > Java Application.

Selenium WebDriver Running test on Safari Browser

Upon execution, the above test script will launch the Safari browser and automate all the test scenarios.






Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf