In this Selenium tutorial, you will learn how to launch the Safari browser using Selenium in Java. We provide real-time coding examples to guide you step-by-step through the process, ensuring a comprehensive understanding of browser automation with Safari.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.safari.SafariDriver;

import io.github.bonigarcia.wdm.WebDriverManager;

public class LaunchSafariBrowser {
	public static void main(String[] args) {
        // Set the path to the ChromeDriver executable
       WebDriverManager.safaridriver().setup();

        // Create an instance of the ChromeDriver
        WebDriver driver = new SafariDriver();
        
        //Delete all cookies.
        driver.manage().deleteAllCookies();
        
        //Maximize the browser.
        driver.manage().window().maximize();

        // Navigate to a website
        driver.get("https://opensource-demo.orangehrmlive.com/web/index.php/auth/login");

        // Perform further actions or tests...
       // Verify that the title of the page
        String expTitle = "OrangeHRM";
        String actTitle = driver.getTitle();
        
        if(actTitle.equalsIgnoreCase(expTitle)) {
        	System.out.println("Test Case Pass");
        }else {
        	System.out.println("Testcase failed");
        }
        

        // Close the browser
        driver.quit();
    }

}

By Avinash

Leave a Reply

Your email address will not be published. Required fields are marked *