System.setProperty - Set path to chromedriver

Asked

Viewed 787 times

1

I’m starting to mess with tests using Lenium and Junit. I need to set the chromedriver.exe path. I wonder if you can leave chromedriver.exe inside the project folder and set the path in a way that if someone else downloads the project, for example, Github does not need to reset the path.

1 answer

0


Oops, do it this way:

1º - Download the . exe driver and put it inside your test sources directory. Something like: src/test/Resources/chromedriver.exe. This directory will be fit to be commited.

2º - In your test class, where you are trying to register the Property, search the exe for this.getClass().getResource("chromedriver.exe").getPath();. It will fetch the executable from within the test source, where you stored the exe.

Enjoy!


4º - If you are using Arquillian + Maven, the arquilian.xml configuration file requires the extensions:

<extension qualifier="webdriver">
    <property name="browser">${browser}</property>
    <property name="chromeDriverBinary">${chromeDriverBinary}</property>
</extension>

and properties must be registered in Maven pom.xml.

<properties>
    <browser>chrome</browser>
    <chromeDriverBinary>src/test/resources/chromedriver.exe</chromeDriverBinary>
</properties>
  • I tested it as suggested and was giving Nullpointerexception. But it worked when using this.getClass(). getClassLoader(). getResource("chromedriver.exe"). getPath(). Thanks for the help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.