Triggering the testng XML from within the POM XML file

The testng.xml that is shown in the preceding code will be triggered from pom.xml. Let's understand how this triggering takes place. For the triggering to happen, a plugin called Maven Surefire Plug-in is used. The corresponding dependency is placed in the pom.xml inside the <plugin></plugin> tag, as shown in the following code snippet. 

Apart from the Maven Surefire plugin, another plugin called the Maven Compiler plugin is also required. For integration tests, the Maven failsafe plugin should be used.

The following snippet of the pom.xml shows the <build></build> tags, inside which are <plugins></plugins> tags. Place the dependencies inside the plugins tag, as shown in the following code (make sure to select Version 1.8 of source and target):

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>
testng.xml
</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

After adding this dependency, save the project and right click on the Project in Eclipse. Click Maven | Update Project.

The next thing to do is right click on pom.xml and select Run As | Maven Test.

Alternatively, you can run Maven from the command line using the command mvn clean verify (using the Maven failsafe plugin) or mvn clean test (using the surefire plugin). JDK that is greater than 1.8 is required. The .java files in the project will be compiled and the tests in the testng.xml will be run. Right now, we only have one class DriverScript.java in testng.xml. Since we have not created this class yet, an error will be thrown after executing the previous command. But that's not a problem.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.32.116