Home » Posts tagged 'how to use geckodriver in selenium java'
Tag Archives: how to use geckodriver in selenium java
First Test case Firefox (GeckoDriver with selenium)
How to write First Test case Firefox (GeckoDriver with selenium)?
After completing the installation process in previous topic, its time to execute First Test case Firefox (GeckoDriver with selenium) script to understand how GeckoDriver with Selenium works.
Whats is Gecko Driver?
Gecko Driver:When we talk about Gecko it is coined to Gecko web browser which is developed by Mozilla foundation. Gecko driver provides a bridge between selenium and Firefox browser.Gecko acts as proxy between W3C webdriver compatible client and Gecko based web browser.
Mechanism if GeckoDriver with browser
Higher version of Selenium ex (selenium3) uses Marionette for launch Firefox instead of default(Where .exe is not been provided).
Marionette works as default for selenium 3. Selenium uses W3C protocol for send request to gecko driver.
Download Gecko Driver with below steps:
- To download Gecko driver click to Click Here , Click to the gecko driver link for the release compatible to you system config for ex(window, linux, IOS).
- Once the geckodriver zip file is downloaded, unzip the file on you specific folder
Now Create a New Java Project with below steps:
- Open the Eclipse and select File->New->Project->Java Project
- Enter your project name SeleniumTutorial(mention any name) and then click to finish button at the bottom
- Now create a new package Step->File->New->Package, A window will open enter package name (Selenium Architecture)(you can mention any name) and click to finish button.
- After creating package eclipse project will be displayed on left pane.
Create a Class in package for this Right Click to you package(SeleniumArchitecture) ->New->Class button.
- Once you click to class , Class window will appear enter any name for class as(FirstTestScript) and check the check box for public static void main (as shown in picture).
Add Selenium Webdriver Jar (follow below steps)
- Right click on the project Selenium Tutorial ->Build path->Configure build path.
- Under Java Build path window->Click on libraries(Menu on top)->click on Add external jars (on right side) a window will open , go to the folder where selenium jar is kept and all the files from lib and outside the lib folder. Now click to apply and close
- Jars will be saved on your project.
Setup gecko driver to environmental variable setting with below steps:
- Go to My computer from your local, right click->select properties menu
- Click to Advanced system settings.
- Click to Environment variable.
- Under Environment variable window-> System setting-> select Path and click to edit button at bottom and add the location where the Gecko driver is placed after semi colon (we are using window 10 so add the location of gecko driver) and click to OK button as per screenshot.
Now move to scrip and write below code:
- Code2test be sharing you code for copy to your eclipse below.
package SeleniumArchitecture;
public class FirstTestScript {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Users\\Tutorial\\Desktop\\Eclipse_Installer\\GeckoDriver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.facebook.com");
Thread.sleep(5000);
driver.quit();
}}
- To remove error from line on FirefoxDriver(); just mouse over to it and click to import FirefoxDriver link . Do same with Webdriver and on Thread.sleep(add exception to it)
Now right click to you class file and click to Run as ->Java Project, Firefox browser will open and launch the facebook page.