img

Selenium – Running Test on Mozilla Firefox

In the last section, we’ve successfully run our Java code for executing the Chrome browser, in this section we’re going to see how we can start the firefox browser. If in case you didn’t look how to run chrome browser, yo can follow below URL.

  • Open Eclipse IDE, and create a new Project, Package and Class for the automation. You can refer the below link to create the Class in Eclipse IDE.

NOTE: You can write code with me line by line or you can also download it from GitHub from the below URL.

Here, we are going to create one class with ExecuteOnFirefox.java file name. We have already created one class ExecuteOnChrome.java in the previous section.

Now just like chrome browser, here we also need the Firefox browser binary which is called geckodriver.exe.

Below tutorial will guide you for downloading browser binaries

  • Now once you downloaded the binaries and unzipped it, you’ll need to set those binaries in the system y System.setProperty() command. For the Mozilla Firefox, property set by webdriver.gecko.driver and with value as the path of the geckodriver.exe. as below
// Setting the Firefox(Gecko) Driver binaries
System.setProperty("webdriver.gecko.driver", "C:\\Users\\admin\\Desktop\\geckodriver.exe"); // You can set path wherever you have unzipped the binary file
  • Now just like again Chrome browser, we’ll need an instance of the WebDriver as the driver for working with automation. You might also notice we have created the driver instance with the ChromeDriver() which will create the instance for the Chrome browser with the WebDriver, we’ll create an instance as FirefoxDriver() for the running Firefox browser.
// Creating instance of the FirefoxDriver
WebDriver driver = new FirefoxDriver();
  • Now follow the similar steps as below to open the browser and enter the test URL, and getting the page title from the page and finally closing the browser session.
// Opening the Browser with URL
driver.get("http://www.step2qa.com");

// Get and print the page title of the loaded page
System.out.println(driver.getTitle());

// Wait for the 5000ms (5 seconds)
Thread.sleep(5000);

// Quit the browser session and close the current running browser
driver.quit();
  • That’s it, you just open the Mozilla Firefox with the Selenium, in next section we’ll see how we can open IE browser.
  • Facebook
  • Twitter
  • Google+
  • Linkedin
  • Pinterest

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

It is main inner container footer text