TestNG Selenium Java--Java.lang.IllegalStateException:必须通过webdriver.chrome.driver系统属性设置驱动程序可执行文件的路径
如果我不使用TestNG,只使用普通的JavaSelenium,一切都很好。 但是如果我将TestNG与JavaSelenium一起使用,就会出现这个错误TestNG Selenium Java--Java.lang.IllegalStateException:必须通过webdriver.chrome.driver系统属性设置驱动程序可执行文件的路径,java,selenium,Java,Selenium,如果我不使用TestNG,只使用普通的JavaSelenium,一切都很好。 但是如果我将TestNG与JavaSelenium一起使用,就会出现这个错误 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/
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
我已经将驱动程序的路径设置为可执行的,编译器仍在抱怨。有什么建议吗?谢谢
包测试套件;
导入java.io.FileInputStream;
导入java.io.FileNotFoundException;
导入java.io.FileOutputStream;
导入java.io.IOException;
导入java.sql.Driver;
导入java.util.Properties;
导入org.openqa.selenium.WebDriver;
导入org.openqa.selenium.chrome.ChromeDriver;
//导入org.junit.Test;
导入org.testng.annotations.AfterMethod;
导入org.testng.annotations.postest;
导入org.testng.annotations.BeforeMethod;
导入org.testng.annotations.BeforeSuite;
导入org.testng.annotations.BeforeTest;
导入org.testng.annotations.Test;
公共类testNG
{
@试验
public void login()引发IOException{
System.setProperty(“WebDriver.Chrome.Driver”,“C:\\Users\\Desktop\\chromedriver\u win32\\chromedriver.exe”);
WebDriver=null;
Properties prop=新属性();
FileInputStream file=newfileinputstream(“C:\\Users\\workspace\\Selenium\\src\\testSuite\\config.properties”);
加载(文件);
System.out.println(prop.getProperty(“用户名”);
如果(prop.getProperty(“浏览器”)等于(“chrome”)){
System.out.println(“OKOK”);
驱动程序=新的ChromeDriver();
}
获取(prop.getProperty(“url”);
}
}
我发现了问题。
只是一个小小的错误
它应该是小写的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");
需要小心使用小写或大写字母。谢谢。我发现了问题。
只是一个小小的错误
它应该是小写的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");
需要小心使用小写或大写字母。谢谢。尽量不要硬编码路径 您可以直接使用System.getProperty(“user.dir”)转到您的工作目录 是的,请使用小写的webdriver.chrome.driver
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir")+ "/chromedriver.exe");
尽量不要硬编码路径 您可以直接使用System.getProperty(“user.dir”)转到您的工作目录 是的,请使用小写的webdriver.chrome.driver
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir")+ "/chromedriver.exe");
如果从命令行运行testng脚本,可能需要添加以下开关-
-Dwebdriver.chrome.driver=<path to chromedriver.exe>\chromedriver.exe
-Dwebdriver.chrome.driver=\chromedriver.exe
如果从命令行运行testng脚本,可能需要添加以下开关-
-Dwebdriver.chrome.driver=<path to chromedriver.exe>\chromedriver.exe
-Dwebdriver.chrome.driver=\chromedriver.exe
我现在无法检查,但从我的头顶上看,这不是您设置驾驶员路径的方式。不知道为什么没有TestNG,它会起作用。您必须创建一个ChromeOptions
实例,在其上设置路径,并将该实例设置到驱动程序实例中,我不记得是作为构造函数的参数还是通过setter。我现在无法检查,但我想这不是您设置驱动程序路径的方式。不知道为什么没有TestNG,它会起作用。您必须创建一个ChromeOptions
实例,在其上设置路径,并将该实例设置为驱动程序实例,我不记得是作为构造函数的参数还是通过setter。