Home >>Selenium Tutorial >Selenium WebDriver Running test on Safari Browser

Selenium WebDriver Running test on Safari Browser

Selenium WebDriver Running test on Safari Browser

We'll learn how to run our Selenium Test Scripts on a Safari Browser in this section.

Safari Browser allows use of SafariDriver to apply the WebDriver protocol. The SafariDriver connects your Selenium checks to the Safari Browser. SafariDriver has been introduced in the safari framework as a plugin and this offers a good balance between client and server system where SafariDriverServer acts as server and where Selenium-Java/Language Binding acts as client.

Let's call a test case in which we'll seek to simplify the Safari search scenarios that follow.

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

We must build our fifth test case (Demo_Test) in the same test suite.

Step 1. 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.

Step 2. 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.

Step 3. To access the new update of SafariDriver click on the "Latest Release" link.

Step 4. Double-click the file to open.

First let's understand how we should initialize SafariDriver in Selenium before writing the test file. The Safari browser is defined in the package org.openqa.selenium.safari by a module called SafariDriver. All that we have to do is build a SafariDriver class case.

It will open the Safari browser extension window into a pop-up box. To configure WebDriver within your Safari browser, click the "Trust" button.

Step 5. Make your browser restart.

WebDriver driver = new SafariDriver(); 

Step 6. 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("javatpoint tutorials");  
              
          // Click on the search button  
        driver.findElement(By.name("btnK")).click();  
          
          // Close the Browser  
        driver.close();  
          
    }  

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


No Sidebar ads