parameterisation of xml file in POM.xml file :
------------------------------------------
and Runnning Testng.Xml file in cmd prompt window
---------------------------------------------
<configuration>
<suiteXmlFiles>
<!-- <suiteXmlFile>testng.xml</suiteXmlFile>
<suiteXmlFile>testng2.xml </suiteXmlFile> -->
<!-- <suiteXmlFile>C:\brahma\Practise\SelniumPractiseNew\March52024MyWorkspace\MavenProjectThroughCommand\src\test\Resources\Runner\testng.xml </suiteXmlFile>
-->
<!-- <suiteXmlFile>src\test\Resources\Runner\testng.xml </suiteXmlFile>
<suiteXmlFile>src\test\Resources\Runner\testng2.xml </suiteXmlFile> -->
<suiteXmlFile>${suiteXmlFile} </suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
-------------------------------------
Syntax :
--------
run single class --> mvn test -Dtest= class1
run multiple classes --> mvn test -Dtest = class1,class2,class3...etc
Run all maven test classes --> mvn test - if class name ends with "Test" it will run all classes
Run testng.xml file --> mvn test -DsuiteXmlFile= xmlFileName.xml
ex 1: run single testng.xml --> mvn test -DsuiteXmlFile=testng.xml
ex 2:
run "testng2.xml" cmd --> mvn test -DsuiteXmlFile=testng2.xml
Execute above commands :
------------------------
C:\brahma\Practise\SelniumPractiseNew\Jul2023WorkSpace\MavenProjectThroughCommand>mvn test -DsuiteXmlFile=testng.xml
C:\brahma\Practise\SelniumPractiseNew\Jul2023WorkSpace\MavenProjectThroughCommand>mvn test -DsuiteXmlFile=testng2.xml
(or )
we can use this also
mvn clean test -DsuiteXmlFile=testng.xml
ex:
C:\brahma\Practise\SelniumPractiseNew\March52024MyWorkspace\MavenProjectThroughCommand>mvn test -DsuiteXmlFile=testng.xml
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------< com.birla:MavenProjectThroughCommand >----------------
[INFO] Building MavenProjectThroughCommand 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ MavenProjectThroughCommand ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\brahma\Practise\SelniumPractiseNew\March52024MyWorkspace\MavenProjectThroughCommand\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ MavenProjectThroughCommand ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ MavenProjectThroughCommand ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ MavenProjectThroughCommand ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:3.1.2:test (default-test) @ MavenProjectThroughCommand ---
[INFO] Using auto detected provider org.apache.maven.surefire.testng.TestNGProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestSuite
hi IOS Test
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.039 s -- in TestSuite
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.979 s
[INFO] Finished at: 2024-06-20T09:05:57+05:30
[INFO] ------------------------------------------------------------------------
C:\brahma\Practise\SelniumPractiseNew\March52024MyWorkspace\MavenProjectThroughCommand>mvn test -DsuiteXmlFile=testng2.xml
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------< com.birla:MavenProjectThroughCommand >----------------
[INFO] Building MavenProjectThroughCommand 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ MavenProjectThroughCommand ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\brahma\Practise\SelniumPractiseNew\March52024MyWorkspace\MavenProjectThroughCommand\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ MavenProjectThroughCommand ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ MavenProjectThroughCommand ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ MavenProjectThroughCommand ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:3.1.2:test (default-test) @ MavenProjectThroughCommand ---
[INFO] Using auto detected provider org.apache.maven.surefire.testng.TestNGProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running TestSuite
Calling Mobile Test
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.026 s -- in TestSuite
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.443 s
[INFO] Finished at: 2024-06-20T09:09:47+05:30
[INFO] ------------------------------------------------------------------------
C:\brahma\Practise\SelniumPractiseNew\March52024MyWorkspace\MavenProjectThroughCommand>
Run "Multiple" testng.xml files cmd :
----------------------------------
run "single" testng.xml file --> mvn test -DsuiteXmlFile=testng.xml
run "multiple" xml files --> mvn test -DsuiteXmlFile=testng.xml,testng2.xml, testng3.xml,...
mvn test -DsuiteXmlFile=testng.xml,testng2.xml --Dont give spaces -- working
ex 2:
mvn clean test -DsuiteXmlFile=testng.xml,testng2.xml -- working
invalid :
mvn clean test -DsuiteXmlFiles=testng.xml,testng2.xml ---> invalid command - dont use 'suiteXmlFiles'
run :
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.259 s
[INFO] Finished at: 2023-10-24T09:32:40+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.1.2:test (default-test) on project MavenProjectThroughCommand: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:3.1.2:test failed: testSuiteXmlFiles0 has null value -> [Help 1]
[ERROR]
when we get above error- there is some problem in maven cmd..check maven command properly.
Syntax 2:
------------
mvn test -Dsurefire.suiteXmlFiles=testng.xml,testng2.xml --> ok
mvn test -Dsurefire.suiteXmlFiles= testng.xml,testng2.xml ---> not working -- dont use spaces for xml files
(or)
mvn clean test -Dsurefire.suiteXmlFiles=testng.xml,testng2.xml --> Valid- working
note:
------
Run "specific test Method" from given class , from given testng.xml file:
-----------------------------------------------------
public class TestAnnonation1 {
@Test // define annotation before method or Test method or Test annontatin method or Test case
public void testA() // normal java method
{
System.out.println("stmt-1 from test A()");
System.out.println("stmt-2 from testA()");
}
@Test // define annotation before method or Test method or Test annontatin method or Test case
public void testA2() // normal java method
{
System.out.println("stmt-1 from test A2()");
System.out.println("stmt-2 from testA2()");
}
}
-----------------------------
Syntax:
-------
mvn test -DsuiteXmlFile=testng.xml -Dtest=className1#testMethodName
ex1: run testA() method from class 'TestAnnonation1' from testng.xml file
mvn test -DsuiteXmlFile=testng.xml -Dtest=TestAnnonation1#testA
ex2:
Run testB () Method
mvn test -DsuiteXmlFile=testng.xml -Dtest=TestAnnonation1#testB
Run 'multiple test' methods from given class :
-------------------------------------------
Syntax:
--------
mvn test -DsuiteXmlFile=testng.xml-Dtest="ClassName#Testmethod1+Testmethod2"
ex: run testA and testA2
mvn test -DsuiteXmlFile=testng.xml -Dtest="TestAnnonation1#testA+testB"
(or)
mvn test -DsuiteXmlFile=testng.xml -Dtest=TestAnnonation1#testA+testB
HW Create 3 (or) 4 Test Methods run 1 test method using maven cmd ?
HW same as previous question, run 3 test methods using maven cmd ?
No comments:
Post a Comment