Skip to main content

Crossbrowser Testing(Installation of Driver) - Safari/Chrome-v85/Firefox v86- Mac System


 

Hi,

Today we are focussing on Cross browser testing  via selenium using annotation of TestNG.

Let's go through it one by one

Safari Browser is the second most popular browser in the world occupying 16% of market share  its default browser for all apple devices

Earlier version of safari required installation on safari webdriver extension, however this extension is no longer supported for safari versions 10 and above, safari driver  comes bundled by default with the browser that's preinstalled in MacOS.

For testing via Safari browser we need to make changes in browser setting.

Go to Safari-> preferences -> Advanced

Tick mark the checkbox with label- Show develop menu in menu bar



Once this is done   Go to develop menu and click on "Allow Remote Automation" Option to enable it
 



Chrome Browser - 
As defined in previous blogs we need to download chrome driver extension. and give the path while running the script.
 
Firefox Browser

Check which versions of Firefox you are working on go to Preferences-> Firefox updates


You need to install GeckoDriver  from the link  



Unlike chrome which goes by similar version number for driver as well as browser in Firefox you will find this kind of Instruction

As working on Mac  you might have read this note


Read the instruction carefully in order to run it in Mac

Code to do the cross browser testing in Google homepage-

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.safari.SafariDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.testng.annotations.Test;

public class Crossbrowser {

WebDriver driver;

@Test 

    public void test()

    {

System.setProperty("Webdriver.chrome.driver", "chromedriver");

    WebDriver driver = new ChromeDriver();

    driver.get("https://www.google.com");

   

    String Pagetitle1 = driver.getTitle();

   

    if (Pagetitle1.equals("Google"))

    {

    System.out.println("Launching Google sucessful via chrome");

    }

    else{

    System.out.println("Launching Google failed via chrome");

    }

    driver.close();

    WebDriver driver = new SafariDriver();

    driver.get("https://www.google.com");

     

    String Pagetitle2= driver.getTitle();

     

    if (Pagetitle2.equals("Google"))

    {

    System.out.println("Launching Google sucessful via Safari"); 

    }

    else{

    System.out.println("Launching Google failed via Safari");

    }

  driver.close();

             

              WebDriver driver = new FirefoxDriver();

     driver.get("https://www.google.com");

     

     String Pagetitle3driver.getTitle();

     

     if (Pagetitle3.equals("Google"))

     {

     System.out.println("Launching Google sucessful via Firefox"); 

     }

     else{

      System.out.println("Launching Google failed via Firefox");

     }

  driver.close();

      } 
  }

    


Screenshot attached for the program run on macOS machine for reference





If you want to fail the test case you only need to change pagetitle.equals("Googla")


     WebDriver driver = new SafariDriver();

     driver.get("https://www.google.com");

     

     String Pagetitle2driver.getTitle();

     

     if (Pagetitle2.equals("Googla"))

     {

     System.out.println("Launching Google sucessful via Safari"); 

     }

     else{

      System.out.println("Launching Google failed via Safari");

     }

  driver.close();



To check the program run please click here




Comments

Popular posts from this blog

Cucumber - Execution of test cases and reporting

Before going through this blog please checkout blog on   Cucumber Fundamentals Cucumber is testing tool which implements BDD(behaviour driven development).It offers a way to write tests that  anybody can understand, regardless of there technical knowledge. It users Gherkin (business readable language) which helps to  describe behaviour without going into details of implementation It's helpful for  business stakeholders who can't easily read code ( Why cucumber tool,  is  called  cucumber , I have no idea if you ask me I could have named it "Potato"(goes well with everything and easy to understand 😂) Well, According to its founder..... My wife suggested I call it  Cucumber  (for no particular reason), so that's how it got its  name . I also decided to give the Given-When-Then syntax a  name , to separate it from the  tool . That's why it's  called  Gherkin ( small variety of a cucumber that's been pickled. I...

Cucumber Datatable testing without using scenario outline and Issues

  Before going through this blog please visit blog The issue you might encounter while running cucumber project- 1.  you have created the cucumber all file in src/test/java and you are trying to  move it in another folder transition might not be smooth, It will give error one fix will led to other.(depends on the setup) 2. If on running a feature file and successfully creating a stepdef file, If application still says that  few steps are still needs to be implemented or all of them(not detecting creation of step definition) then there is a high chance you have mistakenly wrote some other annotation in stepdef when compares to you feature file eg:- feature file @And ( "^user close browser$" ) public   void  user_close_browser()  throws  Throwable { Stepdef:-             @Then ( "^user close browser$" ) public   void  user_close_browser()  throws  Throwable { driver .quit(); 3. Duplicate S...

Automating Flipkart via selenium

                                            Hi Folks, we are automating a flipkart site where you will see how to search and filter the product you choose without logging in . import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.ui.Select; import org.testng.annotations.Test; public class flipkart { WebDriver driver ; @Test       public void test()       {   System.setProperty( "Webdriver.chrome.driver" , "chromedriver" );     WebDriver driver = new ChromeDriver();   driver .manage().timeouts().implicitlyWait(5, TimeUnit. SECONDS );   driver .manage().window().maximize();          driver .get( "https://www.flipkart.com" );   ...