setProperty webdriver.chrome.driver, “…./../..” in a jar but in unix environment?

huangapple 未分类评论45阅读模式
英文:

How setProperty webdriver.chrome.driver,"\..\..\..\") in a jar but in unix environment?

问题

我正在使用Selenium在我的Windows个人电脑上进行测试:

System.setProperty("webdriver.chrome.driver", "src\\test\\java\\resources\\chromedriver.exe");

如果我在Eclipse项目中运行测试,它可以正常工作。但是当我将项目打包成jar文件,并且将test\java\resources\chromedriver.exe包含在此jar文件中,然后在我的项目中加载这个jar文件,它无法加载驱动程序:

java.lang.IllegalStateException: 驱动程序可执行文件的路径必须通过webdriver.chrome.driver系统属性设置有关更多信息请参见https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver。最新版本可以从http://chromedriver.storage.googleapis.com/index.html下载。
	at com.google.common.base.Preconditions.checkState(Preconditions.java:847) ~[na:na]
    等等...

我应该如何在Selenium项目中设置路径以加载驱动程序?

更新:
我必须在Unix机器上进行测试。
谢谢
祝好。

英文:

i'm doing a test with Selenium on my PC with windows:

System.setProperty("webdriver.chrome.driver", "src\\test\\java\\resources\\chromedriver.exe");

it work correctly if i run test inside project with eclipse.
But when i package into jar my project include also test\java\resources\chromedriver.exe and put this jar and load jar in my project it dont load driver:

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
at com.google.common.base.Preconditions.checkState(Preconditions.java:847) ~[na:na]
etc....

How i must set path in project Selenium for load driver?

UPDATE:
i must test it on Unix Machine
Thanks
Regards

答案1

得分: -1

可以例如在运行时从您的JAR文件中提取chromedriver.exechromedriver(取决于主机操作系统),然后通过以下方式传递已提取的chromedriver文件路径:

System.setProperty("webdriver.chrome.driver", "...");

参考这个问题。

英文:

You can e.g. extract the chromedriver.exe or chromedriver (depending on the host OS) from your JAR on runtime and then pass the extracted chromedriver's file path via

System.setProperty("webdriver.chrome.driver", "...");

See this question.

huangapple
  • 本文由 发表于 2020年4月9日 18:26:14
  • 转载请务必保留本文链接:https://java.coder-hub.com/61119056.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定