Working With A number of testng.xml Recordsdata – DZone – Uplaza

Whereas engaged on an open supply GitHub mission that was created to showcase the working of Selenium WebDriver framework with Java, because the mission grew, there was a have to create a number of testng.xml recordsdata for operating totally different checks. 

These a number of recordsdata had been created to segregate the checks and place all of the checks associated to a respective web site in a single testng.xml (I’ve used totally different demo web sites to demo totally different actions that may be automated utilizing Selenium WebDriver).

I considered throwing some mild on the utilization of a number of testng.xml recordsdata and the right way to execute checks. Since Maven is the construct software that’s getting used, a single testng.xml file is required to run all of the checks within the mission. Additionally, there are instances that needed to be debugged for the take a look at failures by operating a single testng.xml file.

On this mission, I’ve created 9 totally different testng.xml recordsdata which have a number of checks, and I’m operating all checks in these 9 totally different testng.xml recordsdata utilizing a single testng.xml file. Sure, that’s doable!

So, be a part of my journey the place I’ll reveal the right way to execute a number of testng.xml recordsdata utilizing a single testng.xml file. I may even be shedding some mild on executing a single testng.xml file out of the 9 out there ones and operating it from the command line utilizing Maven.

Working A number of testng.xml Recordsdata Utilizing a Single testng.xml File

Let’s first give attention to operating all of the checks with all of the 9 totally different testng.xml recordsdata. The answer to that is to make use of the  tag in your testng.xml file and supply the opposite testng.xml file’s path between this tag. Right here is the instance file to reveal what I’m speaking about:

As soon as we execute this file, it is going to execute the respective testng.xmls within the order as up to date between the tag. So, “testng-saucedemo.xml” can be executed first, after which, “testng-automationpractice.xml” can be executed, and so forth.

All of the testng.xml recordsdata supplied within the above instance have a number of checks in them. So, all of the checks inside the respective testng.xml will get executed and after completion, the following XML file can be picked for execution.

The next are the contents of the testng-saucedemo.xml file:

As soon as all of the checks as up to date on this XML file get executed (doesn’t matter cross or fail), and the execution is finished, the following file can be picked for operating one other set of checks.

Working the suite recordsdata in parallel will not be supported by testng.

Working a Single testng.xml File Utilizing Maven

You may have an possibility in IDE to run your checks utilizing testng.xml file by right-clicking on it and choosing the choice to run the checks. Nevertheless, in the case of executing the checks within the CI/CD pipeline, that possibility doesn’t maintain properly, as you should execute the checks utilizing instructions within the automated pipeline.

Configuring Your Venture To Run suite-xml File Utilizing Command Line

We have to set the next configuration to have the ability to run the testng.xml file utilizing Maven.

Replace the Maven Surefire plugin in your pom.xml:

Discover the  tag within the above screenshot. The worth for suiteXmlFile is about as ${suite-xml}. We can be setting the default worth for this declaration within the properties block of the pom.xml file as follows:

The default path to testng.xml is about for the file that we used within the above part of this weblog and have up to date the suite-files path in it.

So, now if we run the command mvn clear set up or mvn clear take a look at, Maven will decide up the testng.xml default file based mostly on the file path that’s up to date within the properties block and execute all of the checks.

Now, the query that involves thoughts is: “What should I do if I want to execute any other testng.xml file, is it possible to do so?”

The reply is “Yes”: we are able to run any testng.xml file in our mission by including the -Dsuite-xml= in our mvn command.

Keep in mind, we had earlier set this configuration in our Maven Surefire plugin block in pom.xml.

We simply have to cross the values for the suite-xml property variable within the command line, which may be achieved utilizing the -D possibility in mvn command:

mvn clear take a look at -Dsuite-xml=

Let’s now strive our arms with the command line and run totally different testng.xml recordsdata utilizing Maven from the command line, as we simply discovered.

We’ll run the testng-internet.xml file, verify that it ought to override the present default testng.xml, and run solely the one which we cross within the command. We have to cross the complete path the place the testng.xml is saved, and in our case, it’s out there in test-suite folder, so the complete path is test-suitestestng-theinternet.xml. Right here is the command that we’ll run (be sure to are on the mission’s root folder path within the command line window earlier than you execute the Maven command):

mvn clear take a look at -Dsuite-xml=test-suitetestng-theinternet.xml

“-Dsuite-xml” possibility can be utilized with different maven instructions like as follows : mvn clear set up/ mvn clear confirm, and so on.

The checks had been efficiently run and the outcomes had been printed on the console. It says 32 checks ran and handed efficiently.

To substantiate that the right XML file was picked and checks had been executed, let’s execute the checks for testng-theinternet.xmlfile utilizing IDE and verify the variety of checks executed.

We are able to see that 32 checks had been executed and handed, which confirms that the checks we executed utilizing the mvn command had been appropriately executed for the testng.xml file we handed.

Conclusion

We are able to have a number of testng.xml recordsdata to segregate the checks based mostly on the totally different modules/web sites in our mission and these a number of testng.xml recordsdata may be executed utilizing a single testng.xml file.

Likewise, we are able to execute a testng.xml file from the command line utilizing the Maven Surefire plugin.

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version