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
Check which versions of Firefox you are working on go to Preferences-> Firefox updates
You need to install GeckoDriver from the link
As working on Mac you might have read this note
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 Pagetitle3= driver.getTitle();
if (Pagetitle3.equals("Google"))
{
System.out.println("Launching Google sucessful via Firefox");
}
else{
System.out.println("Launching Google failed via Firefox");
}
driver.close();
WebDriver driver = new SafariDriver();
driver.get("https://www.google.com");
String Pagetitle2= driver.getTitle();
if (Pagetitle2.equals("Googla"))
{
System.out.println("Launching Google sucessful via Safari");
}
else{
System.out.println("Launching Google failed via Safari");
}
driver.close();
Comments
Post a Comment