Reputation: 851
I am working in Selenium. It is demo project. I am using maven for dependency management. I have downloaded the Gecko driver and has kept to folder location in local drive. But it will create a dependency to with local machine.
We have have folder in maven, called resource. I want to use that. I want to keep the Firefox driver there and want to load it from here.
Maven Dependency
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>maven-selemium</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- Add Following Lines in Your POM File -->
<properties>
<selenium.version>2.53.1</selenium.version>
<testng.version>6.9.10</testng.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-firefox-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
Java Code
public class PG1 {
public static void main(String[] args) throws Exception {
String baseUrl = "https://www.google.co/";
// System.setProperty("webdriver.gecko.driver", "C:/Users/Dell/Downloads/geckodriver-v0.29.1-win64/geckodriver.exe");
System.setProperty("webdriver.gecko.driver", "E:/Drive_H/projects/selenium/src/main/resources/geckodriver-firefox.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
driver.get(baseUrl);
driver.close();
}
}
I have tried with this line but error : unable to load driver.
System.setProperty("webdriver.gecko.driver", "geckodriver-firefox.exe");
Upvotes: 1
Views: 494
Reputation: 632
Use System.getProperty("user.dir")
to get the project user directory path and then access the desired executable.
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "\\src\\main\\resources\\geckodriver-firefox.exe");
Upvotes: 1