Why do we need Cross Browser Testing?
Web based applications are totally different from windows applications. A web application can be opened in any browser by the end user. For example some people prefer to open http://itprofessionalacademy.in/in Firefox browser, while other’s can be using Chrome browser or IE.
Reason Cross Browser Issues
- Font size mismatch in different browsers.
- JavaScript implementation can be different.
- CSS,HTML validation difference can be there according to browsers.
- man browser still not supporting HTML5 and latest version of html.
- Page alignment and div and frames size.
- Image Size is different on browsers.
-
Browser compatibility issue with different OS. Etc.
Creating Single Webdriver object and running test on different browser :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
/* Browser class for creating webdriver object for different browsers*/ import org.openqa.selenium.WebDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.ie.InternetExplorerDriver; public class Browser { String Chromepath=System.getProperty("user.dir"); WebDriver driver; public WebDriver CreateBrowser(String BrowserType,String URL) { // TODO Auto-generated constructor stub String DriverPath=System.getProperty("user.dir"); System.out.println(DriverPath); if (BrowserType.equalsIgnoreCase("Chrome")) { System.setProperty("webdriver.chrome.driver", DriverPath+"\\Chrome\\chromedriver.exe"); ChromeDriver driver= new ChromeDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get(URL); System.out.println("Chrome Driver Created"); } else if(BrowserType.equalsIgnoreCase("IE")) { System.setProperty("webdriver.ie.driver", DriverPath+"\\IEDriver\\IEDriverServer.exe"); InternetExplorerDriver driver= new InternetExplorerDriver(); driver.get(URL); System.out.println("IE Driver Created"); } else if(BrowserType=="") { FirefoxDriver driver = new FirefoxDriver(); driver.get(URL); System.out.println("FireFox Driver Created"); } return driver; } } |
Use this above Class for creating Browser Object .
This below class will explain how you can create different browser object.
1 2 3 4 5 6 7 8 9 10 11 |
import org.openqa.selenium.WebDriver; public class firstclass { public static void main(String[] args) { // Creating object of browser class Browser BR= new Browser(); // Passing 'browser name' (Chrome, Firefox,IE) and 'URL' of the application to be tested BR.driver=BR.CreateBrowser("IE","http://www.google.com");// Here pass 'Chrome' for google chrome browser WebDriver driver1=BR.driver; ///////// Below you can use this driver1 object to perform further operation on browser } } |