When we try to run TestNG or JUnit tests with maven, we usually face this exception saying
For this the chrome executable driver file should be available in the classpath. You can add the chrome driver to the classpath of the current project. But if you want to configure the same in a maven pom file, you should do the following.
To execute TestNG or JUnit test cases, we use maven-surefire-plugin. We can configure the path to the chrome driver as a configuration parameter in this plugin as shown below
Here $(project.basedir) is the directory where this pom.xml file is located. Like this you can configure the chrome driver in the maven. Hope it helps someone who is trying to figure out how to make the driver exe available to the pom to use.
java.lang.RuntimeException:java.lang.IllegalStateException: The path to the driver executable must be set by the webdiver.chrome.driver system property
For this the chrome executable driver file should be available in the classpath. You can add the chrome driver to the classpath of the current project. But if you want to configure the same in a maven pom file, you should do the following.
To execute TestNG or JUnit test cases, we use maven-surefire-plugin. We can configure the path to the chrome driver as a configuration parameter in this plugin as shown below
<build>
<!-- Source directory configuration -->
<sourceDirectory>src</sourceDirectory>
<plugins>
<!-- Following plugin executes the testng tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<!-- Suite testng xml file to consider for test execution -->
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<webdriver.chrome.driver>$(project.basedir)/drivers/chromedriver.exe</webdriver.chrome.driver>
</systemPropertyVariables>
</configuration>
</plugin>
<!-- Compiler plugin configures the java version to be usedfor compiling
the code -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<!-- Source directory configuration -->
<sourceDirectory>src</sourceDirectory>
<plugins>
<!-- Following plugin executes the testng tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<!-- Suite testng xml file to consider for test execution -->
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<webdriver.chrome.driver>$(project.basedir)/drivers/chromedriver.exe</webdriver.chrome.driver>
</systemPropertyVariables>
</configuration>
</plugin>
<!-- Compiler plugin configures the java version to be usedfor compiling
the code -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Here $(project.basedir) is the directory where this pom.xml file is located. Like this you can configure the chrome driver in the maven. Hope it helps someone who is trying to figure out how to make the driver exe available to the pom to use.
Comments
Post a Comment