2

The gecko driver path that works in JAVA is causing an error in TestNG.

Environment:

  • Win 10
  • FF
  • selenium-java-3.0.1
  • geckodriver-v0.11.1-win64
  • eclipse-java-neon-2-win32-x86_64

I suspect I'm placing the GeckoDriver path in the:

1) wrong format and/or

2) wrong place in the TestNG script, but it might be something far more basic, as I'm a novice in this.

Working Code in JAVA :

package foo;
import java.util.List;
... (various 'import')

public class foo02 {    
    public static void main(String[] args) {

    System.setProperty("webdriver.gecko.driver", "C:\\Users\\TestTools\\geckodriver-v0.11.1-win64\\geckodriver.exe"); 

    WebDriver driver = new FirefoxDriver();
    ...

Non working code with TestNG:

package fooNGpackage;

import org.openqa.selenium.WebDriver;
... (various 'import')

public class newtestclss {
     WebDriver driver;

 @BeforeTest
 public void start(){
        System.setProperty("C:\\Users\\TestTools\\geckodriver-v0.11.1-win64\\geckodriver.exe", null); 

 driver = new FirefoxDriver();
 }

 @Test
 public void Test(){ 
  System.out.println("Loading Google search page");
  driver.get("http://google.com");
  System.out.println("Google search page loaded fine");
 }

 @AfterTest
 public void close(){
 driver.quit(); 
 }
 }

Error when run as TestNG:


[TestNG] Running:
C:\Users\\[my dir\]\AppData\Local\Temp\testng-eclipse--1726843281\testng-customsuite.xml

FAILED CONFIGURATION: @BeforeTest start

java.lang.NullPointerException

at java.util.Hashtable.put(Unknown Source)
...

SKIPPED CONFIGURATION: @AfterTest close

SKIPPED: Test

java.lang.NullPointerException

at java.util.Hashtable.put(Unknown Source)
...

___

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

Configuration Failures: 1, Skips: 1
___

Default suite
Total tests run: 1, Failures: 0, Skips: 1

Configuration Failures: 1, Skips: 1
___

\[TestNG\] Time taken by org.testng.reporters.XMLReporter@3a883ce7: 16 ms

\[TestNG\] Time taken by org.testng.reporters.EmailableReporter2@72b6cbcc: 17 ms

\[TestNG\] Time taken by org.testng.reporters.JUnitReportReporter@4bbfb90a: 13 ms

\[TestNG\] Time taken by org.testng.reporters.SuiteHTMLReporter@7d0587f1: 74 ms

\[TestNG\] Time taken by org.testng.reporters.jq.Main@34cd072c: 122 ms

\[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 16 ms
___

Your suggestion is greatly appreciated. HK

2

The syntax for setProperty() method is:

System.setProperty("<driver we want to use in the program>", 
                   "<path where the driver exists>");

As per the question,

In java you have mentioned correctly.

In TestNG, in place of 'driver to be used' you have mentioned 'driver path' and in place of 'driver path' you have pointed to null.

Correct way:

@BeforeTest
public void start(){
    System.setProperty("webdriver.gecko.driver", "C:\\Users\\TestTools\\geckodriver-v0.11.1-win64\\geckodriver.exe");
    driver = new FirefoxDriver();
}
  • This is right. Please follow above solution. Hopefully It would solve problem.! – Sagar007 Dec 28 '16 at 6:09
  • @the_coder Hurrah! I knew I was messing up something. Many thanks, I can progress with my training! – Hello Kittychan Dec 28 '16 at 19:05
  • @the_coder Oh sure, didn't even know it was possible! – Hello Kittychan Dec 30 '16 at 6:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.