keylogger
keylogger

Reputation: 872

TestNG Selenium Java -- java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property

If I don't use TestNG and just plain Java Selenium, all good. But if I use TestNG with Java Selenium , I get this error.

java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html

I already put the path to the driver executeable and the compiler still complains. Any suggestion? Thanks.

package testSuite;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Driver;
import java.util.Properties;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
//import org.junit.Test;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class testNG 
{
	
	@Test
	public void login() throws IOException {
		System.setProperty("WebDriver.Chrome.Driver", "C:\\Users\\Desktop\\chromedriver_win32\\chromedriver.exe");
		WebDriver driver = null; 
		Properties prop = new Properties(); 
		FileInputStream file = new FileInputStream("C:\\Users\\workspace\\Selenium\\src\\testSuite\\config.properties");
		prop.load(file);
		
		System.out.println(prop.getProperty("username"));
		
		if(prop.getProperty("browser").equals("chrome")) {
			System.out.println("OKOK");
			driver = new ChromeDriver(); 
			
		}
		driver.get(prop.getProperty("url"));
		
	}
  }

This is my properties file

username = 56987
password = 1234
url = www.google.com
browser = chrome

Upvotes: 0

Views: 2229

Answers (3)

Kenil Fadia
Kenil Fadia

Reputation: 234

If you are running the testng script from command line, you might need to add the following switch-

-Dwebdriver.chrome.driver=<path to chromedriver.exe>\chromedriver.exe

Upvotes: 1

Anuj Teotia
Anuj Teotia

Reputation: 1323

Try not to hardcode the path.

You can directly use System.getProperty("user.dir") to go to your working directory.

And Yes use webdriver.chrome.driver in lower case.

System.setProperty("webdriver.chrome.driver",
                System.getProperty("user.dir")+ "/chromedriver.exe");

Upvotes: 1

keylogger
keylogger

Reputation: 872

I found the issue. Just a tiny small mistake.

It should be lower case webdriver.chrome.driver

System.setProperty("webdriver.chrome.driver", "C:\\Users\\Desktop\\chromedriver_win32\\chromedriver.exe");

instead of

System.setProperty("WebDriver.Chrome.Driver", "C:\\Users\\Desktop\\chromedriver_win32\\chromedriver.exe");

Need to be careful with the lower or upper case. Thanks.

Upvotes: 2

Related Questions