0

TestNG not working with firefox driver

Info

  • IDE: Eclipse IDE for Java Developers
  • Version: Neon.3 Release (4.6.3) Build id: 20170314-1500
  • OS- Windows 8.1 ,
  • Selenium Jars - 3.5.3 ,
  • TestNG jar-testng-6.10
  • jcommander-1.48

I created a new project and added the above items . When I run the below

Source Code

package com.testpackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class test {
    @Test
    public void verifyTitle() {
        WebDriver driver = new FirefoxDriver();    
        driver.get("https://www.gmail.com");
        String pageTitle = driver.getTitle();
        System.out.println(pageTitle);
        Assert.assertEquals(pageTitle, "Gmail");
    }
}  

I'm getting the below message .I'm a Newbie to TestNG If anyone can help me create TestNG project with required jars and solve this issue it'll be helpfull.

Console Message

[RemoteTestNG] detected TestNG version 6.10.0
[TestNG] Running:
  C:\Users\KRISHNAA\AppData\Local\Temp\testng-eclipse-1071289737\testng-customsuite.xml

FAILED: verifyTitle
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases
    at com.google.common.base.Preconditions.checkState(Preconditions.java:754)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
    at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41)
    at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:115)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:329)
    at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:207)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:103)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:99)
    at com.testpackage.test.verifyTitle(test.java:11)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:645)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:851)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1177)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:756)
    at org.testng.TestRunner.run(TestRunner.java:610)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
    at org.testng.SuiteRunner.run(SuiteRunner.java:289)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
    at org.testng.TestNG.runSuites(TestNG.java:1133)
    at org.testng.TestNG.run(TestNG.java:1104)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@4f51b3e0: 24 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@60438a68: 12 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@23bb8443: 64 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 8 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@5606c0b: 8 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@6a396c1e: 48 ms
jrtapsell
  • 6,719
  • 1
  • 26
  • 49
  • 3
    Possible duplicate of [Firefox browser is not opening with selenium webbrowser code](https://stackoverflow.com/questions/38751525/firefox-browser-is-not-opening-with-selenium-webbrowser-code) – Alessandro Da Rugna Oct 15 '17 at 17:20
  • Possible duplicate of [Selenium using Java - The path to the driver executable must be set by the webdriver.gecko.driver system property](https://stackoverflow.com/questions/38676719/selenium-using-java-the-path-to-the-driver-executable-must-be-set-by-the-webdr) – niharika_neo Oct 16 '17 at 04:48

3 Answers3

0

The problem is you are trying to open the browser instance by writing the code driver= new FirefoxDriver(); From selenium 3.X on wards we can't launch the browser directly. you just download the firefox driver from this link. (https://github.com/mozilla/geckodriver/). once you download the code change the code

WebDriver driver = new FirefoxDriver(); 

to

System.setProperty("webdriver.gecko.driver", "<your file path, which you are going to download");\\here is the example path C:\\GeckoDriver\\geckodriver.exe
WebDriver driver = new FirefoxDriver();

run your code by making this change. it will work fine

Auro Sarma
  • 441
  • 2
  • 12
0

Their are mandatory to use gecko drive with selenium if you are using selenium 3.0 and above. Gecko Driver for Mozilla:

Though completely independent of Selenium 3.0 release, Mozilla is making structural changes to the its Firefox driver. Firefox versions prior to version 48, had web driver integrated and you didn’t need to provide the path of the webdriver executable. However with Firefox 48 and beyond, this has changed. Just like Internet Explorer / Edge or Chrome browser, you need to now provide the path of Firefox gecko driver executable.

This is nothing to do with selenium 3 but with Mozilla. So even if you are using Selenium 2.0, you will need to invoke gecko driver with Firefox 48 and above. I think this link is more helpful for you :

https://seleniumhq.wordpress.com/2016/10/13/selenium-3-0-out-now/

Piyush Garg
  • 37
  • 2
  • 10
0

It's clearly saying that you're not set the driver path correctly.

Download gecko driven for firefox. https://github.com/mozilla/geckodriver/releases.

Follow the below steps to get the results

  1. You should download it depends on the you're system bit. If you 32 bit you have to download 32 bit driver, if you 64 bit you have download 64 bit.

  2. Save the driver file into your system.

  3. Set the path below

System.setProperty("webdriver.gecko.driver", "your driven path here");

WebDriver driver = new FirefoxDriver();

Srihari
  • 13
  • 7