Maven in selenium
Click to rate this post!
[Total: 0 Average: 0]

In Maven, every step related to a goal. It comes from an inbuilt life cycle. Integration tests run after the project that you design and Deploy. This comes from Default life cycle. To illustrate, the integration test phase of default life cycle executed for your project, when it compiled with Maven in selenium.

We all know that Maven is an inbuilt tool, which guides to manage selenium projects. It guides us to create correct project design and handle the Jar files, in a project built path.The main thing in software testing is integrating the test results. The inbuilt tool that your project utilizes it. Developers run tests very easily. Probably they don’t run them. Another Reason you can run your tests very easily. They run Maven skip tests, another reason is integrating tests. For Encouraging clean project that design Process.

Maven in Selenium

Generally, Maven utilizes POM.xml Configuration files, that keeps total project configuration related information. For selenium software, you have to offer selenium web driver that related Information in POM.xml file. Then it downloads each Information that needed for jar files in an automatic way. After that, if you want to modify version of Selenium web driver. Then you have to send modify version In POM.xml file only. After that Maven downloads latest version jar files, that automatically store in the local repository. It shows that if you update any dependency version In Pom.xml file.Moreover, First, you have to check. That version’s Jar files are available. They are not in a local repository. If it is available, maven repository.

 

Maven Plugins

Verifier, it verifies the existence of some conditions used for Integration.

Surefire, It runs Junit unit tests in isolated class loader.

Site, it generate a site for current project.

Resources, it copies resources, to output directory that include JAR.

Install, installs the built artifact in local repository.

Failsafe, it operates Junit maven Integration tests with isolated Class loader.

Deploy, it deploy artifact to remote repository.

Compiler, it compiles Java code.

Clean, it cleans up after build.

Maven in Selenium

When we use Maven we find, each and Every seleniumhq artifact, that directly. Included in central Maven repository. For Initiating, we have to use, latest web driver Implementations. That is in your maven project. It will add Dependency for your pom.xml with IT courses.

<dependency>

<groupId>org.seleniumhq.selenium</groupId>

<artifactId>selenium-java</artifactId>

<version>3.141.59</version>

</dependency>

For Getting an total Overview Over selenium Maven download Artifacts. See below Picture.

If you recognize, you only see web driver Implementation. That is just like onlineitguru Driver. It Doesn’t need Selenium Java Artifact. Furthermore,  you have to add dependency on artifact, that you require.

<dependency>

<groupId>org.seleniumhq.selenium</groupId>

<artifactId>selenium-onlineitguru-driver</artifactId>

<version>3.141.59</version>

</dependency>

If we go with 2.53.0, we need explicitly, that contain Html Unit Driver as a dependency which contain. Equally Important, Version Number of Driver, that track HTML unit Inbuilt

<dependency>

<groupId>org.seleniumhq.selenium</groupId>

<artifactId>htmlunit-driver</artifactId>

<version>2.33.2</version>

</dependency>

Generally, When we use the old, selenium, you have to start selenium server. Usually, it is the trusted way that you have to download selenium server Standalone.jar. As a matter of fact, You can embed selenium server in your project. Furthermore, You can also add Dependency to pom.xml

<dependency>

<groupId>org.seleniumhq.selenium</groupId>

<artifactId>selenium-server</artifactId>

<version>3.141.59</version>

</dependency>

Simultaneously, From many Days, we are using Selenium API in Code. For that you need selenium jar files for project. In the same fashion, Which is in eclipse, you have to go to properties of your project. For instance, that is Java build path – libraries- added external jars).

For Every Dependency, there is a version number. Moreover, the version number can hard coded or it stored in a property.

Especially, Big Deal is, When we run our project Maven command, it checks libraries in their computer. Eventually, If they don’t do it, they Download them within an automatic mode, with central Maven repository.

Eventually, it will upgrade libraries, you have to update the central repository. Specifically, After that, it upgrades libraries that update version numbers in XML and maven that take care until the end.

For Configuring Pom.xml we need mvn-compiler-plugin and Surfire Plugin

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<version>3.5.1</version>

<configuration>

<source>${jdk.level}</source>

<target>${jdk.level}</target>

</configuration>

</plugin>

Maven-surefire-plugin is used for running tests that placed in test source.

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-surefire-plugin</artifactId>

<version>2.19.1</version>

<configuration>

<suiteXmlFiles>

<!-- TestNG suite XML files -->

<suiteXmlFile>testng.xml</suiteXmlFile>

</suiteXmlFiles>

</configuration>

</plugin>

Maven Integration With Selenium

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.onlineitguru.onlineitguruDriver;

import org.testng.annotations.Test;

public class Testonlineitguru {

@Test

public void Testonlineitguru(){

WebDriver driver=new onlineitguruDriver();

driver.manage().window().maximize();

driver.get("http://www.onlineitguru.com");

driver.quit();

}

}

Selenium Maven Plugin

<plugin>

<groupId>org.codehaus.mojo</groupId>

<artifactId>selenium-maven-plugin</artifactId>

<executions>

<execution>

<phase>pre-integration-test</phase>

<goals>

<goal>start-server</goal>

<goal>selenese</goal>

</goals>

<configuration>

<background>true</background>

<browser>*onlineitguru</browser>

<results>src/test/resources/selenium/result.html</results>

<startURL>http://localhost/MyProject</startURL>

<suite>src\test\resources\selenium\Testsuite.html</suite>

</configuration>

</execution>

</executions>

</plugin>

Cargo-maven Plugin

<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.0.6</version>
<configuration>
<wait>false</wait>
<!-- Container configuration -->
<container>
<type>installed</type>
<containerId>tomcat6x</containerId>
<home>${TOMCAT_HOME}</home>
</container>
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- Skip the normal tests,
we'll run them in the integration-test phase -->
<skip>true</skip>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>

Selenium with Maven Sure fire

<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId> <
<configuration>
<outputDirectory>${basedir}/target/wso2qa</outputDirectory>
</configuration>
</plugin>
</plugins>
</reporting>

Selenium with Maven Failsafe

moduleA
scr/main/…
src/test/integration/java/…
scr/test/unit/java/…

moduleB
scr/main/…
src/test/integration/java/…
scr/test/unit/java/…

moduleC (only for selenium tests)
scr/main/java/com/selenium/A.java
src/test/java/…

Maven Resource Plugin

resources:resources
Copy resources to main source code to main output directory.
Every time it uses project.build. In the same fashion, resources element to specify the resources to copy.

resources:testResources
It Copy resources for the testing source code to the testing output directory.
Always uses the project.build.testResources element to specify the resources to copy.

resources:copy-resources
Copy resources for configured plugin attribute resources.

resources:help
Display guide information on maven-resources-plugin.

Maven Deploy Plugin

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>deploy-features-xml</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<repositoryId>${project.distributionManagement.snapshotRepository.id}</repositoryId>
<url>${project.distributionManagement.snapshotRepository.url}</url>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<file>features.xml</file>
</configuration>
</execution>
</executions>
</plugin>

Maven Site Plugin

<plugin>


<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-site-plugin</artifactId>

<version>3.7.1</version>


</plugin>
Keep Learning:

 
Drop Us A Query

100% Secure Payments. All major credit & debit cards accepted.

Call Now Button