4

This is my testng.xml file:

<suite name="Suite1" verbose="1" parallel="true" thread-count="5">
 <suite-files>
 <suite-file path="xml-files/live.xml"></suite-file>
 <suite-file path="xml-files/test.xml"></suite-file>
 </suite-files>
</suite>

I want to run both these xml and though it does start running but the problem is, it only runs single file(test.xml) two times. does anyone have idea why is it happening?

Update: Added pom, live and test.xml files

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hiverqa</groupId>
<artifactId>hiverqa</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>hiverqa</name>
<url>http://maven.apache.org</url>
<properties>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 <suiteXmlFile>testng.xml</suiteXmlFile>
</properties>
<build>
 <plugins>
 <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-surefire-plugin</artifactId>
 <version>2.20.1</version>
 <configuration>
 <suiteXmlFiles>
 <suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
 </suiteXmlFiles>
 </configuration>
 </plugin>
 </plugins>
</build>
<dependencies>
 <dependency>
 <groupId>junit</groupId>
 <artifactId>junit</artifactId>
 <version>3.8.1</version>
 <scope>test</scope>
 </dependency>
 <dependency>
 <groupId>org.seleniumhq.selenium</groupId>
 <artifactId>selenium-java</artifactId>
 <version>3.6.0</version>
 </dependency>
 <dependency>
 <groupId>org.testng</groupId>
 <artifactId>testng</artifactId>
 <version>6.8</version>
 <scope>test</scope>
 </dependency>
 <dependency>
 <groupId>javax.mail</groupId>
 <artifactId>mail</artifactId>
 <version>1.4.3</version>
 </dependency>
 <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
 <dependency>
 <groupId>org.apache.commons</groupId>
 <artifactId>commons-io</artifactId>
 <version>1.3.2</version>
 </dependency>
 <!-- https://mvnrepository.com/artifact/com.twilio.sdk/twilio -->
 <dependency>
 <groupId>com.twilio.sdk</groupId>
 <artifactId>twilio</artifactId>
 <version>7.14.5</version>
 </dependency>
</dependencies>

live.xml

<parameter name="browser" value="chrome"></parameter>
<parameter name="isExtensionInstalled" value="true" />
<parameter name="profileEnvironment" value="Live" /> <!-- default is selenium browser,Use 'Test' for test environment -->
<test name="SM Onboarding with Extension Test">
 <classes>
 <class name="tests.Onboarding_NonMP_SM_WebSignUP" />
 <class name="tests.Onboarding_NonMP_SL_SignUP" />
 <class name="tests.Onboarding_MP_SM_Signup" />
 </classes>
</test> <!-- Test -->

test.xml

<parameter name="isExtensionInstalled" value="true" />
<parameter name="profileEnvironment" value="Test" /> <!-- default is selenium browser,Use 'Test' for test environment -->
<test name="SM Onboarding with Extension Test">
 <classes>
 <class name="tests.Onboarding_NonMP_SM_WebSignUP" />
 <class name="tests.Onboarding_NonMP_SL_SignUP" />
 <class name="tests.Onboarding_MP_SM_Signup" />
 </classes>
</test> <!-- Test -->
asked Oct 27, 2017 at 12:10
2
  • Can you add the some more code like All 3 xml files ? Commented Oct 28, 2017 at 4:47
  • @NarendraR I have only two xmls to run. the problem is that when i try to run these files, last xml runs multiple times. do you have any idea why? Commented Nov 3, 2017 at 6:25

2 Answers 2

1

First of all you need to configure live.xml file and test.xml file in your pom.xml file using maven-surefire-plugin. You can do it in following way after your </dependencies> tag.

<build>
 <plugins>
 <plugin>
 <groupId>org.apache.maven.plugins</groupId>
 <artifactId>maven-surefire-plugin</artifactId>
 <version>2.20.1</version>
 <configuration>
 <suiteXmlFiles>
 <suiteXmlFile>"xml-files/live.xml"</suiteXmlFile>
 <suiteXmlFile>"xml-files/test.xml"</suiteXmlFile>
 </suiteXmlFiles>
 </configuration>
 </plugin>
 </plugins>
</build>

Then next you can run your testng.xml as it is..

Sagar007
1,3403 gold badges9 silver badges24 bronze badges
answered Oct 30, 2017 at 4:24
6
  • i've tried that too but it did not work. It runs test.xml(last suite file) multiple times. Commented Nov 3, 2017 at 6:20
  • can you show your test.xml file live.xml file pom file and testng.xml file? Commented Nov 3, 2017 at 9:24
  • Please see updated question Commented Nov 3, 2017 at 10:05
  • In your pom file you have configured your tesng.xml file two times, is there any reason for that? <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <suiteXmlFile>testng.xml</suiteXmlFile> </properties> and <configuration> <suiteXmlFiles> <suiteXmlFile>${suiteXmlFile}</suiteXmlFile> </suiteXmlFiles> </configuration> Commented Nov 6, 2017 at 3:08
  • Yes, its intended. Basically, i'm referring testng.xml file from <properties> tag. Commented Nov 8, 2017 at 17:41
0

You can try below approach which will help you execute to run multiple testNg.xml file together

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.testng.TestNG;
public class TestNGRunner {
 public static void main(String[] args) {
//Place all your multiple testng.xml suit file this progarm will it'self take care and execute one by one in single go of execution 
 String currentDir = System.getProperty("user.dir")+ "/src/test/resources/testRunners";
 File directory = new File(currentDir);
 File[] listOfFiles = directory.listFiles();
 List<String> suitFiles = new ArrayList<>();
 for (File file : listOfFiles) {
 suitFiles.add(currentDir + "/" + file.getName());
 System.out.println(file.getName());
 }
 TestNG runner = new TestNG();
 runner.setTestSuites(suitFiles);
 runner.run();
 }
}
answered Feb 20, 2023 at 18:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.