How to Run Single Testng xml file from multiple files as per user's choice using maven cmd #maven

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome to the session 23 in my own series in this session we are going to see how we can run a single test injection file from multiple xmls as per user Choice using Maven command so a few days back one of the candidate asked this question and he is facing issue while handling this type of scenario so as an example let's consider in our framework under the xmls folder I have Senate XML regression XML and coverage XM also okay so among these three xmls I want to run a single test ngx all file using a maven command so how I can do that so for a demonstration I have these Maven project under this main project I have created uh three test NG XML files okay so these are the three uh test NG XML files from which we are running different test engine methods and that I have created under the esrc test Java okay so different package contain different test NG classes and it contains some test energy methods so here we are going to print some statement only as of now so if I want to run any of the test engine X1 files using the main one I need to set up a certified plugin in the form.xml file so I have added a Surefire plugin so compiler plugin ensure file plugin here plugin we need to define the configuration for our suit XML files so if I want to run the sanity XML file I need to provide the file name here sanity.xml but this file is available under the xmls folder so here I need to provide the folder name as well XML slash sineator.xml okay so currently we have hard coded this test NG file name here in the Surefire plugin okay so my requirement is I should have some parameter by which I can provide the name of the test engine XML file that I want to run okay so at the runtime I will provide the name of the test injection file and that uh testing XML file should run okay so if you hard code this value every time the sanity.xml file will run right let's try to run this XML first and then we will see how we can uh create the parameter and how we can run it and we can provide the test NG file name at the runtime so all the four tests from the Senate XML files has been executed okay and if I want to run some test from the regression XML again I need to change the file name here regression dot XML okay this is working fine so now challenge here is I need to update the test engine external file name again and again okay so what I need to do is I need to create a parameter here and I will send the value of that parameter and that value will be used in sure5 plugin here okay so how we can do that so that is our scenario how we can run the single testing X1 file as per the user choice so first in the pom.xn file create a property so I will use the property stack and I am going to create a property name file so for this property you can provide any default file name or any default or testing Json file that you want to run okay so in case you want to run this project directly the default test injection file that should be run so that name you can provide here okay so for example let's say I am going to run XML slash sanity in case user do not provide any parameter value the sanitation file will be executed by default so to use this file property as a parameter uh go to the Shopify plugin and here we need to Define that parameter okay so we have already a parameter name that is file so we need to use the dollar and give curly bracket this is my file parameter so whatever value for this file parameter I provide while running this my own project using demand command that the value will be used here in the Surefire plugin okay so this is the setting you need to do so let's try to verify if it is working or not so we need to provide the parameter at the runtime while running the main on command so I will go to the terminal okay and I will give mdn let's say clean test okay so if you run this command this will by default uh take the Senate XML file okay because by default value for this file parameter is XML slash 780.xml hit enter okay working fine so now I want to run the regression XML okay so I will give space hyphen D then here we need to provide the parameter name that is my file equal to u double quote and under double quote I need to provide the parameter value so if you run this command the value for this file parameter is XML slash regression dot XML so that will be given here so we are giving choice to the user whatever test engine XML file they want to run they can provide the name at the runtime in the maven command so you can see here test cases from the regression suit has been executed now if I want to run the coverage XML just use that name in the maven command coverage dot XML so even though you are using any Jenkins job to trigger your automation you can create a Jenkins parameter for this file and name you can provide at the runtime from the Jenkins job okay so that also you can do to run the any test engine XML file from the multiple testing xmls okay so I will quickly show you from the eclipse as well so many people use the eclipse okay so same project I have opened in the eclipse ID so for the eclipse we don't have any terminal so if I want to run the main command right click on your my own project or right click on the palm.xml file then go to run ads then click on my own build so here you can provide the goal that you want to run so here we don't require to use the mvn because we are using the neon project we are going to run the main project so in case you are using the terminal or command prompt you need to use this mun keyword okay so for the eclipse we don't require so I mean then clean test so if we run this this will use the sanity.xml by default right so let's run it and then we will try to run the regression XML so again right click on the email project go to run as you can build then clean test hyphen d your file parameter its value in the double quote you say XML slash regression dot XML click on run so as per the user Choice the test case is from the regression suit will be executed okay so very important scenario guides in the real time projects as well as in the entries as well thank you [Music]
Info
Channel: AJ AUTOMATION
Views: 1,048
Rating: undefined out of 5
Keywords: run single testng xml, how to run test using maven pom.xml, testng with maven, testng maven intellij, testng maven, testng maven project in eclipse, how to run multiple testng xml in maven, how to run single testng xml file as per user choice, run single testng using surefire plugin, testng tutorial, testng framework in selenium, how to run testng.xml file in eclipse, run testng xml with maven command at run time, How to Run Single XML Test Suite from Multiple Files
Id: AjsW_RPOjOM
Channel Id: undefined
Length: 8min 18sec (498 seconds)
Published: Thu Aug 24 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.