How can I use the ChromeDriver path not hard?

In my selenium tests, I have a ChromeDriver path encoded using

        System.setProperty("webdriver.chrome.driver", "C:\\Users\\kday\\Desktop\\Selenium Stuff\\chromedriver.exe");
        WebDriver driver = new ChromeDriver(); 

However, this means that when I export the program as a jar executable, the test will not work because it cannot find the hard path (if it is on another computer). Is there any way to do this so that either ..

a.) - ChromeDriver is part of the jar and works with it
b.) - I can initialize it in code without hard coding the value in this

Basically, I want all tests to be executed (in IE, Chrome, FF), just by launching the jar.

+4
source share
4 answers

, .exe ( ). .exe getResourceAsStream("path_to_your_exe_file").

EXE temp. . Apo commons IO. FileUtils.copy(in, out).

exe , System.setProperty("webdriver.chrome.driver",C:\\Users\\kday\\Desktop\\Selenium Stuff\\chromedriver.exe");

+2

- . chromedriver.exe main/resources , .. ClassLoader.getResource().

, , . Eclipse project → properties → Java build path

URL url = classLoader.getResource("chromedriver.exe");
System.setProperty("webdriver.chrome.driver", url.toString());

, url.toString(), . .

+1

Chrome ,

System.getProperty("user.dir");

, .

+1

Source: https://habr.com/ru/post/1608556/


All Articles