Do we use Maven only to create dependencies in pom.xml file? Isn't there any other use of Maven in selenium project?
POM is surely one of the main advantages of Maven. But there are more:
- Maven provides support for managing the full life cycle of a test project
- Maven enables you to extend your project with maven plugins (test reports etc.)
- JARS are done automatically this means that Maven automatically downloads the corresponding files
- POM is centralized hence each tester or testengineer use same JAR dependencies
- Provides structure with naming conventions -> easier to locate
For more information please read:
Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information.
Maven in Java based test automation projects is often only used as a build-runner and depency manager, but it has way more features. It seems the facto standard for Java projects, not sure you really need to research its other features.
You can see many general advantages of maven from other answers, but the main two reasons for having a build automation tool like maven in the test framework would be:
- Managing dependencies:
Maven POM file allows adding details of dependencies like, which tool, which version, from which repository
This ensures that all stakeholders or users of your test framework use the same versions of dependencies that are tested to be working and this avoids issues that arise by using wrong versions of tools.
<dependencies> <!-- https://testng.org/doc/download.html --> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.10</version> </dependency> <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-testng</artifactId> <version>2.0.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.141.59</version> </dependency> </dependencies>
Users do not have to download and add each dependency manually, maven install command will automatically download all the required dependencies according to the POM file.
So you just have to download the framework folder structure and do a maven install, you are ready with a working test framework (IDE like eclipse does it automatically for you, so just add the project to eclipse and you are ready to go).
- Easy CI/CD integration.
You can use maven surefire plugin to run TestNG tests through maven test command
Just add the below maven surefire plugin, and point to the TestNG xml.
Now just run maven test, you can see the TestNG tests getting executed.
<build> <!-- // Following plugin executes the testng tests --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.14.1</version> <configuration> <!-- // Suite testng xml file to consider for test execution --> <suiteXmlFiles> <suiteXmlFile>src/files/testtest.xml</suiteXmlFile> </suiteXmlFiles> </configuration> </plugin> </build>