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
ChromeOptionsinstance, set the path on it, and set that instance into the driver instance, I don't remember if as an arg of the constructor or through a setter.