Issue
I have to automate the test cases run confugration in maven. Downloading the appopriate Chrome or Firefox webdriver is also one part of it.
In the pom.xml under the build tag
<plugin>
<groupId>com.github.webdriverextensions</groupId>
<artifactId>webdriverextensions-maven-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<goals>
<goal>install-drivers</goal>
</goals>
</execution>
</executions>
<configuration>
<installationDirectory>${testbench.driver.path}/drivers</installationDirectory>
<drivers>
<driver>
<name>geckodriver</name>
<platform>windows</platform>
<version>0.29.0</version>
</driver>
<driver>
<name>chromedriver</name>
<platform>windows</platform>
<version>90.0.4430.24</version>
</driver>
</drivers>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>failsafe-integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>failsafe-verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<trimStackTrace>false</trimStackTrace>
<systemPropertyVariables>
<webdriver.chrome.driver>${testbench.driver.path}/drivers/chromedriver-windows-32bit.exe</webdriver.chrome.driver>
<webdriver.gecko.driver>${testbench.driver.path}/drivers/geckodriver-windows-64bit.exe</webdriver.gecko.driver>
</systemPropertyVariables>
</configuration>
</plugin>
<!-- The Jetty plugin allows us to easily test the development build by
running jetty:run on the command line. -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<configuration>
<scanIntervalSeconds>2</scanIntervalSeconds>
<stopKey>STOP</stopKey>
<stopPort>8005</stopPort>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
Here I have manually enter the version of the chrome driver to be downloaded and installed. But I want the oorwser version to be automatically detected in the developer's machine and download appropriate driver automatically. If I do not mention the driver version, I am getting error during the build.
How can this be brought? I need support for both Chrome and Firefox webdriver.
Solution
You can use WebDriver Manager API. -It downloads the driver.exe to your /m2/repository/webdriver folder(while using Maven). It also automatically checks your browser version and download the matching version of driver.exe.
To use Webdriver Manager API, Include below lines in your pom.xml file:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>3.6.2</version>
<scope>test</scope>
</dependency>
-Then in your code just call this line before initialing the Webdriver object:
//Call any of the line based on which browser you are using.
WebDriverManager.chromedriver().setup();
WebDriverManager.firefoxdriver().setup();
WebDriverManager.iedriver().setup();
WebDriverManager.operadriver().setup();
WebDriverManager.phantomjs().setup();
WebDriverManager.edgedriver().setup();
So you can eliminate below steps:
1)Downloading the driver binaries manually and placing in the location
2)Below line of code also needs to be removed:
System.setProperty("webdriver.chrome.driver", "path to your driver location");
More info here
Answered By - Nischitha K N
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.