如果我不使用 TestNG 而只使用普通的 Java Selenium,那一切都很好。 但是如果我将 TestNG 与 Java Selenium 一起使用,则会收到此错误。
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
我已经将驱动程序的路径设置为可执行文件,但编译器仍然提示。有什么建议吗?谢谢。
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"));
}
}
这是我的属性文件
username = 56987
password = 1234
url = www.google.com
browser = chrome
最佳答案
我发现了这个问题。 只是一个小小的错误。
它应该是小写webdriver.chrome.driver
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Desktop\\chromedriver_win32\\chromedriver.exe");
而不是
System.setProperty("WebDriver.Chrome.Driver", "C:\\Users\\Desktop\\chromedriver_win32\\chromedriver.exe");
需要注意小写或大写。谢谢。
关于java - TestNG Selenium Java -- java.lang.IllegalStateException : The path to the driver executable must be set by the webdriver. chrome.driver 系统属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43013783/