0

I need to create simple autotest using ChromeDriver with Maven.

excerpt from pom.xml:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>2.53.1</version>
</dependency>

test case:

@BeforeTest
public void StartBrowser_NavURL() {
    driver = new ChromeDriver();
    driver.manage().window().maximize();
}

@AfterTest
public void CloseBrowser() {
    driver.quit();
}

@Test
public void testToCompareDoubles() {
    driver.get("http://www.google.com");
}

And after running test executing command

mvn -test

I receive the following exception:

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:199) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109) at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32) at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:116) at com.testTask.GoogleTest.StartBrowser_NavURL(GoogleTest.java:26) at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:77) at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:110) at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:106) at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115) at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75) ... Removed 23 stack frames

I've read discussion accesible via the link below: How to run Selenium WebDriver test cases in Chrome?

But I can't download executables on my server. So, it's not an option for me. But Maven downloads "selenium-chrome-driver-2.53.1.jar" on the server (which is OK for me).

Is there a way to use dowloaded .jar file instead of executable?

P.S. For this project I use IntelliJ Idea Community Edition and I'm not an expert with it

Community
  • 1
  • 1
Eugene
  • 5,353
  • 6
  • 27
  • 37

2 Answers2

1

You have an answer in the thrown exception. Just set the path to the executable chrome driver before initializing your driver.

System.setProperty("webdriver.chrome.driver", "path to your chrome driver executable")

You can download chrome driver executable from the below link and put it to desired location:

https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver

Edited:

If you don't want to download the chrome driver manually then add dependency like this.

<dependency>
   <groupId>io.github.bonigarcia</groupId>
   <artifactId>webdrivermanager</artifactId>
   <version>1.4.9</version>
</dependency>

This will download the latest version of driver and set the proper java system variable using the command:

ChromeDriverManager.getInstance().setup();
optimistic_creeper
  • 2,739
  • 3
  • 23
  • 37
  • Once more: I have NO permissions to download executables. – Eugene Oct 01 '16 at 17:57
  • What does that mean? You need to have executable chrome driver to run tests on chrome. – optimistic_creeper Oct 01 '16 at 18:00
  • Your advice works: my tests are executed after downloading "chromedriver.exe". But all this stuff is supposed to be run with a single Maven command (e.g.: mvn -test). And I don't know, could Maven download files from the internet or not. So, I'm looking for a solution, which will minimise the quantity of downloaded external files. Otherwise, I should go to stakeholders to renegotiating. – Eugene Oct 01 '16 at 18:28
  • 1
    Perfect! That's what I was looking for. Many thanks! – Eugene Oct 01 '16 at 21:07
  • Thanks this helped a lot –  Jul 08 '18 at 14:55
0

First download chromedriver.exe file and make sure it is compatible with Selenium Webdriver version.

then you have to setup the path using System.Setproperty as shown in below code

@BeforeTest
public void StartBrowser_NavURL() {
//setup the chromedriver path
System.setProperty("webdriver.chrome.driver", "Path to your chrome driver");
driver = new ChromeDriver();
driver.manage().window().maximize();
}

After this you need configure maven Surefire plugin in order to run maven project through command line.

Link : https://maven.apache.org/surefire/maven-surefire-plugin/