3

I create chrome driver like this:

System.setProperty("webdriver.chrome.driver",
            "C:\\Users\\ragnar_000\\IdeaProjects\\ProjectA\\src\\test\\resources\\chromedriver.exe");
webDriver = new ChromeDriver();

This code is written on Windows platform. When I run it on Mac, I have to edit the path according to Mac platform.

How to set/check the path so that it can run on all platforms, like it just needs the path src/test/resources/chromedrivers.exe

1

3 Answers 3

2

Create a folder under your project and copy the chromedriver.exe to that folder (eg: /resources/chromedrivers.exe).

Then set the path to that folder by

String path = System.getProperty("user.dir");
System.out.println(path); 
System.setProperty("webdriver.chrome.driver",path+"\\resources\\chromedriver.exe");

I have tried in windows and its working.Try if it works on Mac.

Sign up to request clarification or add additional context in comments.

Comments

0

Two ways on answer to this question: First: use absolute path.

Paths.get("." + File.separator + "folder" + File.separator + "chromedriver.exe"); //local project folder
Paths.get(System.getProperty("user.home") + File.separator + "folder" + 
File.separator + "chromedriver.exe"); //file in folder in user home dircetory

That's very dublicate question. Googleit.

Second way: this setting need to store in project *.properties file and reload this propertie on file on every platform without rewrite test source code. Any path ended like "...driver.exe" is not aplicable on unix or mac. Also this way provide posability run tests with driver-path string.

Hope it helps.

Comments

0

Based on the documentation https://www.selenium.dev/documentation/en/

WebDriver driver = new FirefoxDriver(); // for firefox

or

WebDriver driver = new ChormeDriver(); // for chrome

should help resolve this issue. Please ensure that you have imported the relevant classes

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.