Selenium ChromeDriver System properties NullPointerException



我用硒写了一个maven程序,它工作正常,现在我正在尝试外部化属性,突然我无法启动chromedriver。我得到这个空指针异常,似乎驱动程序正在尝试在系统属性文件中查找某些属性。

这是我的代码

Properties properties = new Properties();
properties.load(AmazonVendor.class.getClassLoader().getResourceAsStream("application.properties"));
System.setProperties(properties);
ChromeDriverService chromeDriverService = new ChromeDriverService.Builder()
.usingDriverExecutable(new File(System.getProperty("webdriver.chrome.driver")))
.usingAnyFreePort()
.withEnvironment(ImmutableMap.of("DISPLAY",":99"))
.build();
try {
chromeDriverService.start();
} catch (IOException e) {
LOGGERR.error(e);
}

WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);

这是我的应用程序属性

webdriver.chrome.driver=/home/cheng/chromedriver
files.download.dir=/home/cheng/Downloads/
emails.create.dir=/home/cheng/amazon_automation/emails/
java.home=/api/java/jdk1.8.0_131/jre/

这是我的错误

[WARNING] 
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ExceptionInInitializerError
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:326)
at com.apioutsourcing.websiteautomation.AmazonVendor.newDriver(AmazonVendor.java:222)
at com.apioutsourcing.websiteautomation.AmazonVendor.startAutomation(AmazonVendor.java:250)
at com.apioutsourcing.websiteautomation.AmazonVendor.main(AmazonVendor.java:285)
... 6 more
Caused by: java.lang.NullPointerException
at org.openqa.selenium.Platform.extractFromSysProperty(Platform.java:245)
at org.openqa.selenium.Platform.extractFromSysProperty(Platform.java:232)
at org.openqa.selenium.Platform.getCurrent(Platform.java:200)
at org.openqa.selenium.net.PortProber.<clinit>(PortProber.java:41)
... 10 more

任何帮助不胜感激!

我已经弄清楚了,似乎System.setProperties(properties)会让java忽略所有默认属性,只在application.properties文件中查找属性,所以我只是使用System.setProperty单独设置它们,所以java仍然会知道环境的属性

相关内容

  • 没有找到相关文章

最新更新