I am trying to run a unique test from testng.xml.My testng.xml is as below:
<suite name="Suite">
<test name="one">
<parameter name="browser" value="firefox"/>
<parameter name="os" value="win"/>
<classes>
<class name="com.snapdeal.qa.Tests.MyAccount.SignUpTest"/>
</classes>
</test>
<test name="two">
<parameter name="browser" value="chrome"/>
<parameter name="os" value="win"/>
<classes>
<class name="com.snapdeal.qa.Tests.MyAccount.BaseTest"/>
<class name="com.snapdeal.qa.Tests.MyAccount.SignUpTest"/>
</classes>
</test>
</suite>
I am using maven and i am passing which test to run through sure-fire like this:
test -Dtests="one"
But its running all tests defined in testng.Where is actually i am wrong. and how to run a specfic test like this in any way
Code should be like below if you want to run only 1 test from xml :
<suite name="Suite">
<test name="one">
<parameter name="browser" value="firefox"/>
<parameter name="os" value="win"/>
<classes>
<class name="yourpackagename.yourclasname"/>
</classes>
</test>
</suite>
Just use test which you want to run like above. Pass package name and class name which you want to run.
If you want to skip specific test then you can set like : #Test(enabled = false) in yout java class file. So testNG will not run that test. So set (enabled = false) for test which you do not want to run.
Related
hope someone help me with this question, thanks !
I have this in testng.xml
<suite name="Test Project" verbose="1" thread-count="1" configfailurepolicy="continue">
<listeners>
<listener class-name="com.tests.TestListener"/>
</listeners>
<test name="Test1">
<classes>
<class name="com.tests.test1.LoginTest1"></class>
</classes>
</test>
<test name="Test2">
<classes>
<class name="com.tests.test2.LoginTest2"></class>
</classes>
</test>
</suite>
How can I run only the 'Test2'?
I tried mvn test -Dtest=Test2 but it was not working, run both tests
As explained in "maven command to run specific test class got org.testng.TestNGException"
You are mixing the two modes of execution. TestNG lets you run tests in two modes:
Via a TestNG suite xml file
Individual test classes by specifying the fully qualified class names of them.
In your case, you would need to use the class name of your Test2:
mvn test -Dtest=com.tests.test2.LoginTest2
I am running a TestNG.xml
I have created a maven project for my automation selenium script and added all the required dependencies to pom.xml. If I run the suite defined in the Testng.xml file using TestNG.run() command TestNG test result console is blank.
And please do share if there is any other way to run the testNG.xml from main() method so that I can get each test case status in testNG console
Please refer the code that I have used
TestNG testng = new TestNG();
List<String> suites = Lists.newArrayList();
suites.add(currdir+"/tempTestNG.xml");//path of xml..
testng.setTestSuites(suites);
testng.run();
Please refer the testNG.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<parameter name="ExecutionType" value="Regression"/>
<listeners>
<listener class-name="config.TestListener"/>
</listeners>
<test name="Test">
<classes>
<class name="testsuits.VerificationOfWiki">
<methods>
<include name="VerifyMainpagetextonWiki"/>
<include name="VerifyRandomArticletextonWiki"/>
</methods>
</class>
</classes>
</test>
</suite>
Iam using Selenium Cucumber Maven framework with Junit. I need to run the feature file in different browsers in parallel(at the same time).
Does this work if we pass browsernames like this ?
mvn test "-Dbrowser=chrome" , "-Dbrowser=firefox" through command line ?
If not please help me with a solution.
I have been asking this doubt for 2 weeks and Iam not getting any reply. It would be really great if you guys help me with a solution. Thanks in advance .
You can have a look at this post and this github project:
Basically, you can use gherkin with qaf to do something like this:
<suite name="run test in parallel Suite" parallel="tests" verbose="1" configfailurepolicy="continue" thread-count="2">
<test name="Tests in FF">
<parameter name="driver.name" value="firefoxDriver" />
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
<test name="Tests in Chrome">
<parameter name="driver.name" value="chromeDriver"/>
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
</suite>
Community NOTE : Since the referenced SO post does not have an accepted or upvoted answer, I could not mark this as duplicate.
I have more than one test tags in my testng.xml file that I am running using maven. I have set the parallel attribute at the suite level to methods and the thread-count as 5. The problem I am facing is that the tests are executed sequentially and only the methods inside the test cases are executed in parallel. To be more clear, though there are unused threads(Selenium nodes in the grid in my case) available the subsequent tests waits till all the methods in the previous test are executed.
Here is the testng.xml that i have used,
<suite name="Suite1" verbose="1" parallel="methods" thread-count="5" preserve-order="false">
<test name="Login" >
<classes>
<class name="testSuite.TestSet1" />
</classes>
</test>
<test name="Product Search">
<classes>
<class name="testSuite.TestSet2"/>
</classes>
</test>
</suite>
As I have more than 10 nodes available in my selenium grid, this behavior increases the execution time considerably and defeats the purpose of having a grid architecture. Please let me know if there's a way using which I can execute the test methods across the suite in parallel. I am sure that I am missing something silly, but could you please help me point that?
<suite name="Suite1" verbose="1" parallel="tests" thread-count="2" preserve-order="false">
<test name="Login" parallel="methods" thread-count="5">
<classes>
<class name="testSuite.TestSet1" />
</classes>
</test>
<test name="Product Search" parallel="methods" thread-count="5">
<classes>
<class name="testSuite.TestSet2"/>
</classes>
</test>
First allow your Suite to run "tests" in parallel with the number of test suites to run at a time (example 2).
Second allow your test to run "methods" parallel with the number of methods each can run (example 5 in each).
If you are bumping against the your thread limit be careful when adjusting these numbers. For example if you add another test group with thread-count of 5 and change your suite thread-count to 3. You'll now be at 15 threads.
Type parallel="tests" in your TestNG xml file
Parallel=methods would do exactly that - "methods inside the test cases are executed in parallel".
If you want your test tags to be executed parallely use parallel=tests.
This would run all your test tags in parallel.
But you state you have 10 nodes available. If above is the only xml you have then only two nodes would be used up at a time since you have just two test tags.
I have a testng.xml like this :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite verbose="0" name="Selenium Parallel Aim Suite" parallel="tests" >
<test name="FB login and Screen capture" parallel="true">
<classes>
<class name="com.jm.webdriver.JTest1"/>
</classes>
</test>
<test name="Google Search" parallel="true">
<classes>
<class name="com.jm.webdriver.JTest2"/>
</classes>
</test>
</suite>
I want to launch these two test cases on say three machines 1. Windows, 2 linux 3. Mac parallelly, How to do so ?
It should be parallel = "true" for suite tag and parallel property is not required for test tags. If you are looking for grid setup then refer the seleniumhq.org documentation.