0

I am doing automation for one of our project, for that I coded like the below:

public void m() throws FileNotFoundException, IOException {
        System.setProperty("webdriver.chrome.driver",Thread.currentThread().getContextClassLoader().getResource("chromedriver.exe").getFile());
        System.out.println("123");
        WebDriver driver = new ChromeDriver();
        driver.get("http://www.google.com");
    }

It's working when I execute in eclipse. but when I am testing with the maven generated jar, it is giving an exception :

Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\Users\rkowsu\Desktop\jar\file:\C:\Users\UU1\Desktop\jar\resources-part-0.0.1-SNAPSHOT.jar!\chromedriver.exe

Is there anything wrong?

Ram Kowsu
  • 711
  • 2
  • 10
  • 30
  • Possible duplicate of [How to work with chrome driver in Maven](http://stackoverflow.com/questions/35867102/how-to-work-with-chrome-driver-in-maven) – buræquete Mar 01 '17 at 06:49
  • I gone through with the above link example, they mentioned the chromedriver.exe path as system path, If I do the same, it'll work. But whereas my requirement is bit different. I placed the .exe file under src/main/resources and I am getting the .exe path with the java code as I mentioned. – Ram Kowsu Mar 01 '17 at 06:52
  • Can you post your POM.xml? – Joe Caruso Mar 04 '17 at 19:46
  • Did you get this to work? I am facing the same problem, I have a JAR with chrome driver within an executable, and I cannot get it to launch, it doesn't find the file. – Miguel Mesquita Alfaiate Oct 10 '18 at 12:23

2 Answers2

1

If you have chromedriver.exe in the src/main/resources directory of your application then it will get packaged up into your jar file.

It can't be executed from there.

Have a look at the answer to How to work with chrome driver in Maven.

Community
  • 1
  • 1
Steve C
  • 18,876
  • 5
  • 34
  • 37
  • Yes. you're right, the .exe file packed into the jar. so the .exe file path always be pointed to windows explorer but not in to the jar right? – Ram Kowsu Mar 01 '17 at 06:59
0

For System.setProperty() you should be providing it with "webdriver.chrome.driver" and the relative\path\to\exe. If your project structure looks like this:

src
    main
          java
             App.java
          resources
             chromedriver.exe

You should use System.setProperty("webdriver.chrome.driver", "src" + File.separator + "main" + File.separator + "resources" + File.separator +"chromedriver.exe")

This should be able to find the .exe whether or not you run from a jar or not.

Joe Caruso
  • 1,266
  • 1
  • 12
  • 26
  • Thanks for the reply Joe, It'll works in windows eclipse with the personal machine. But when we push this code into the environment as a jar, it didn't work. As @Steve mentioned .exe file doesn't executes/do it's job in the jar as it's zipped in the jar. – Ram Kowsu Mar 10 '17 at 06:05