We have seen how to run selenium tests on chrome and Safari browsers, along with these browsers Firefox browser is one of the popular browsers in the market with large user base.
So we need to validate to make sure the functionalities are working fine for firefox browser as well.
To run selenium tests on firefox browser, we need geckodriver [provided by Mozilla]
Download latest geckodriver
You can download the latest version of geckodriver from below link [download, extract and keep the file in your local drive]
https://github.com/mozilla/geckodriver/releases
Note – makes ure you upgrade your firefox browser to latest
Upgrade firefox browser to latest
Firefox browser > help > about
on Mac – Firefox browser > Firefox menu > about
System.setproperty for firefox browser
System.setProperty(“webdriver.gecko.driver”, “/Users/userName/sel/geckodriver”);
Note – geckodriver is extracted under /Users/userName/sel/geckodriver
For windows, the path would be something C:\\Username\\sel\\geckodriver.exe
Code implementation
We need to create driver object of Selenium’s FirefoxDriver class
driver = new FirefoxDriver();
package browsers; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class FirefoxTest { public static void main(String []args) throws InterruptedException { System.setProperty("webdriver.gecko.driver", "/Users/userName/sel/geckodriver"); WebDriver driver; driver = new FirefoxDriver(); //launch browser driver.get("https://qavbox.github.io/demo/signup/"); //loads url Thread.sleep(3000); driver.findElement(By.id("username")).sendKeys("JTC INDIA"); Thread.sleep(2000); driver.quit(); } }
You can run the test, selenium will execute scripts on firefox browser.
Hope this helps!