GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||
GeezerVison is showing www.softwaretestingclass.com — Cross Browser Testing Using Selenium | Software Testing Class
Skip to content
Cross Browser Testing Using SeleniumIn this chapter, we are going to discuss Cross browser testing using Selenium Webdriver. It is a kind of functional testing that tests whether the application under test is working as expected across available web browsers.
Many times we might have observed that for the same web URL, a website running on Google Chrome looks different from that the other running on MozillaFirefox or Microsoft IE. Here, is the following example. In the following screenshot, we have browsed Facebook URL on Microsoft IE. In the following screenshot, we have browsed Facebook URL on Google Chrome. In the following screenshot, we have browsed Facebook URL on Mozilla Firefox. Following is the comparison of above three screenshots on a different web browser.
Above comparison proves that the same website URL behaves differently on different web browsers. There could be other reasons that demands cross browser testing as follows.
Because of these variations, the cross browser testing is a challenge and such an application should be tested separately on these browsers by using appropriate Selenium web driver. Cross Browser Testing using Selenium Webdriver Selenium Web driver has support for different web browsers and for each web browser following are the WebDriver classes.
Let’s understand these WebDrivers with the following examples.
Following is the program that uses Firefox driver to fetch the heading on the Facebook page.
package seleniumpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class CrossBrowserTesting {
public static void main(String[] args) {
//declaration and instantiation of objects/variable
WebDriver driverFF = new FirefoxDriver();
String baseWebUrl = "https://www.facebook.com/";
driverFF.get(baseWebUrl);
//String heading = driverFF.findElement(By.tagName("h2")).getText();
String heading = driverFF.findElement(By.xpath("//*[@id='content']/div/div/div/div[2]/div[1]/div[1]"))
.getText();
System.out.println("Heading on the Web Page is: "+ heading);
//closing Firefox Browser
driverFF.close();
//Exiting the System
System.exit(0);
}
}
Explanation of code
In the above test, only Mozilla Firefox browser will be used throughout the testing as we are invoking Firefox web driver.
Following is the program that uses InternetExplorer driver to fetch the heading on the Facebook page. InternetExplorerDriver requires an additional driver file known as ‘IEDriverServer.exe’ that can be downloaded from the Selenium website (http://www.seleniumhq.org/download/) and this exe file is required to be placed in the project directory and need to be configured accordingly as shown below.
package seleniumpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class UsingIEWebDriver {
public static void main(String[] args) {
//declaration and instantiation of objects/variables
WebDriver driverIE = new InternetExplorerDriver();
String baseWebUrl = "https://www.facebook.com/";
driverIE.get(baseWebUrl);
String heading = driverIE.findElement(By.xpath("//*[@id='content']/div/div/div/div[2]/div[1]/div[1]"))
.getText();
System.out.println("Heading on the Web Page is: "+ heading);
//closing IE Browser
driverIE.close();
//Exiting the System
System.exit(0);
}
}
Explanation of code
In the above test, only Microsoft IE browser will be used throughout the testing as we are invoking InternetExplorer web driver.
Following is the program that uses Chrome driver to fetch the heading on the Facebook page. ChromeDriver requires an additional driver file known as ‘chromedriver.exe’ that can be downloaded from the Selenium website (http://www.seleniumhq.org/download/) and this exe file is required to be placed in the project directory and need to be configured accordingly as shown below.
//declaration and instantiation of objects/variables
System.setProperty("webdriver.chrome.driver", ".//chromedriver.exe");
WebDriver driverGC = new ChromeDriver();
package seleniumpackage;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class UsingChromeWebDriver {
public static void main(String[] args) {
//declaration and instantiation of objects/variables
System.setProperty("webdriver.chrome.driver", ".//chromedriver.exe");
WebDriver driverGC = new ChromeDriver();
String baseWebUrl = "https://www.facebook.com/";
driverGC.get(baseWebUrl);
String heading = driverGC.findElement(By.xpath("//*[@id='content']/div/div/div/div[2]/div[1]/div[1]"))
.getText();
System.out.println("Heading on the Web Page is: "+ heading);
//closing Google Chrome Browser
driverGC.close();
//Exiting the System
System.exit(0);
}
}
Explanation of code
In the above test, only Google Chrome browser will be used throughout the testing as we are invoking Chrome web driver.
Following is the program that uses Safari driver to fetch the heading on the Facebook page. Before we can start testing any web application using Safari web browser, we need to manually install an extension known as ‘SafariDriver.safariextz’ after downloading it from Selenium website (http://www.seleniumhq.org/download/) at the following link. <br data-mce-bogus="1"> Explanation of code
In the above test, only Safari browser will be used throughout the testing as we are invoking Safari web driver. Output Console for Chrome, IE, and Safari. Conclusion In this chapter, we have discussed the need for cross browser testing and implemented the use of various Selenium web drivers for testing Facebook login page to understand the difference in the testing across different web browsers. Download all above source code from here: Download Code ⇓ Subscribe below ⇓If you are not a regular reader of this website then highly recommends you to Sign up for our free email newsletter!! Sign up just providing your email address below: Enter your email address:Check email in your inbox for confirmation to get latest updates Software Testing for free. Happy Testing!!! Related posts:
Leave a Comment Cancel reply
Share This PostDownload 200+ Software Testing Interview Questions and Answers PDF!! Popular Tutorial Series Recent Posts
About STC © 2023 All Rights Reserved Our mission is to help all testers from beginners to advanced on latest testing trends. We provide free technical articles and tutorials that will help you to get updated in industry. | ||||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |