LambdaTest Community

Find answers, support, and inspiration from other users

Questions
LambdaTest Community
Answered

I am looking to automate my cross browser tests? Is there any way to automate cross browser tests on all latest versions of Chrome and Firefox?

I am looking to automate my cross browser tests, can anyone please suggest me of some ways to automate cross browser tests on all latest versions of Chrome and Firefox.

Up Vote Down Vote 0 Votes
Posted 4 months ago

Answers


Selenium WebDriver is a popular tool that is specially designed for cross-browser automation testing. Selenium WebDriver supports different web browsers, and for each web browser, there are different WebDriver classes like FirefoxDriver, ChromeDriver, InternetExplorerDriver, etc. You have to download these drivers to perform cross-browser testing in different browsers.

Selenium comes with default Mozilla Firefox driver, so there is no setup required for Firefox driver. However, if you want to use other browsers, you will have to set up its system property. For better understanding, let’s take the example of opening Facebook on Chrome, Firefox, and Internet Explorer.

1. Google Chrome Driver

Every driver uses a program to fetch the heading on the Facebook page. ChromeDriver need an additional driver.exe file which can be downloaded from Seleniumhq, and this exe file needs to be placed in the project directory, and then configured accordingly:

[code language=”java”]
//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);
}
}

[/code]

2. FirefoxDriver

Firefox doesn’t require any additional exe file; selenium web drive already has it in a .jar file. So, you don’t need to download Firefox driver; you can use the following program to fetch the heading on the Facebook page:

[code language=”java”]
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);
}
}

[/code]

In this program, we instantiate FirefoxDriver class and then use that instance to load the Facebook login page. Using this instance, you will find that the heading on the webpage is “Facebook helps you connect and share with the people in your life.” In this program, we can use only Mozilla Firefox browser for testing, as we are invoking Firefox browser.

I think it should help.

Source: Dzone

Up Vote Down Vote 0 Votes
Posted 3 months ago