In eclipse, when we run some java file, having test methods, by right clicking on it and selecting Run As -> TestNG Test, we can see following line in 'Console' tab -
[TestNG] Running:
C:\Users\USER-NAME\AppData\Local\Temp\testng-eclipse-1663319006\testng-customsuite.xml
This means TestNG generates testng-cutomsuite.xml and runs it.
testng-cutomsuite.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default suite">
<test verbose="2" name="Default test">
<classes>
<class name="org.test.saifur.StackOverflowTest"/>
</classes>
</test> <!-- Default test -->
</suite> <!-- Default suite -->
But if I've testng.xml in my project and it has parameters like -
<parameter name="browser" value="chrome" />
<parameter name="baseUrl" value="http://stackoverflow.com" />
and when I run my test class as TestNG through eclipse, I want these parameters to be added to testng-customsuite.xml so that those parameters will be used in the test script.
Is there any way by which I can achieve above?
I got answer for this question from testng-users google groups(https://groups.google.com/forum/#!topic/testng-users/q7mLtIsEUCc). Posting same here so that if others who are looking for this get benefited -
Set your testng.xml as a TestNG template xml file via Project > Properties > TestNG in eclipse. What you are looking for should now be available.
This feature exists only in eclipse and not in IntelliJ
Here , this is one another link, so thought of sharing for someone looking for answer. It shows exactly what your question ask. We need to create XML Template globally and then
c.getCurrentXmlTest().getParameter("n") this can get the parameters in #Test
Related
I have a project which have Grid + Selenium + Java + Testng + maven.
Is there is a way to set up, that the person who will run test he will be able to pass his own configurations which will overwrite default configs?
Here is my testng.xml file which i`m running:
<suite name="TestSuite" parallel="tests">
<test name="firefox test">
<parameters>
<parameter name="platform" value="MAC" />
<parameter name="browser" value="firefox" />
<parameter name="version" value="50.1.0" />
<parameter name="url" value="google.com" />
</parameters>
<classes>
<class name="com.ParallelTest.CreateRandomProfileTest"/>
<class name="com.ParallelTest.LogInTest">
</class>
</classes>
</test>
</suite>
For example if someone will want to run 5 Tests against Chrome on Win? How to pass it without changing the code and where it should be overwritten. Can someone drop me a link for resources where i can check it? Thanks!
It can be done easily by file parameter plugin of Jenkins.
https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Build
Ie, Lets assume this a workspace with default folder structure
data
pageobjects
tests
suite.xml
now an user uploads his own version of suite.xml and run the job.
Jenkins will pull the project from source control/github and replaces the suite.xml with the one uploaded by the user and runs the project.
You could try this way as well.
Pass variable from jenkins to testng.xml
Actually I'm testing multiple website for my company. All the website have the same structure and i'm testing various things on each.
For my test i have a Selenium Java Maven project using TestNG. For each web site, i've created a sub folder and generate a specific testing.xml file to specify each test i'm doing for the website.
Here the structure : http://imgur.com/g0VHfMw
My testing.xml files are like this :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test suite website 1" parallel="tests" thread-count="2">
<test name="Test1">
<classes>
<class name="package.for.mytest1"></class>
</classes>
</test>
<test name="Test2">
<classes>
<class name="package.for.mytest2"></class>
</classes>
</test>
<test name="Test3">
<classes>
<class name="package.for.mytest3"></class>
</classes>
</test>
</suite>
How can I merge this 4 test suite in one testNG report ? And if it's possible, is there a way to only show the unstable or failed test on it ?
Any ideas ? Thanks for your help
Try Allure it could easily generate combined report for several suites and show only failed/broken tests by default.
Either you can Use Suite-XML tag in TestNG.xml file to report all your test in single report or implement a reporter of your own to collect all the results and then at the end flush everything into report of your own format with whatever information you need.
You can create a separate testng.xml file in which you can give the path of other testsuites files.
eg:-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name= "Allsuites" verbose="1" preserve-order="true" >
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter"/>
<listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
</listeners>
<suite-files preserve-order="true">
<suite-file path="testng1.xml" />
<suite-file path="testng2.xml" />
<suite-file path="testng3.xml" />
</suite-files>
</suite>
I have created maven project using selenium webdriver in these I have integrate the testng, but when I validate my maven project it displayed "Attribute "parallel" with value "none" must have a value from the list "false methods tests classes instances" in testng-failed.xml and in testng.xml.
Can anyone please help me to resolved this problem.
testng-failed.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Failed suite [Gmail]" parallel="none">
<test name="GmailLoginTest(failed)" parallel="none">
<classes>
<class name="gmailTestcc.LoginTest">
<methods>
<include name="setUp"/>
<include name="mainAndGmailDashboardTest"/>
</methods>
</class> <!-- gmailTestcc.LoginTest -->
</classes>
</test> <!-- GmailLoginTest(failed) -->
</suite> <!-- Failed suite [Gmail] -->
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Gmail" parallel="none">
<test name="GmailLoginTest">
<classes>
<class name="gmailTestcc.LoginTest"/>
</classes>
</test> <!-- GmailLoginTest -->
</suite> <!-- Gmail -->
Based on your error message, I think this problem was caused by this attribute in your testng.xml "parallel="none"". Could you change it to false to have a try?
The issue is not related to Maven, it relates to TestNG itself, you can try solving it either by replacing
parallel="none" by parallel="false"
or changing your TestNG version from (6.9.10) to (6.9.9) because this issue is related to TestNg version 6.9.10.
Please note that if you used the second solution (which is better), you have to change
parallel="none" by parallel="false"
Error: Attribute "parallel" with value "none" must have a value from the list "false methods tests classes instances throws by the testNG if parallel execution is not handling properly in test suite :
if want to handle test execution parallel then use below xml suite:
<suite name="regression" parallel="test" threadcount="10">
Otherwise don't use parallel attribute in test suite
I currently have two different TestSuites (SUITE1.XML and SUITE2.xml) with different configurations (e.g browsers, Os)...
I call both SUITES inside testng.xml to run on saucelabs... and it runs fine... Only what I am concerned is, I want these suites to run parallel instead of sequential...
The output i get is
[TestNG] Running:
/Users/muzamilabbasi/Automation/BaublebarTest/Suite1.xml
This is Browser String FIREFOX
This is Platform String WIN8
This is Version String 25
This is Browser String FIREFOX
This is Platform String WIN8
This is Version String 25
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
Page Title isGoogle
Page Title isGoogle
===============================================
mysuite1
Total tests run: 2, Failures: 0, Skips: 0
===============================================
[TestNG] Running:
/Users/muzamilabbasi/Automation/BaublebarTest/Suite2.xml
This is Browser String FIREFOX
This is Platform String XP
This is Version String 7
This is Browser String FIREFOX
This is Platform String XP
This is Version String 7
Page Title isGoogle
Page Title isGoogle
I have searched alot of web and mostly answers I got is using ANT {PARALLEL} task I can achieve but how? I need an example.. Please help.
I am using macOS & TESTNG 6.8.6
Another option is to use a suite-of-suites. I'll preface this by saying it's been a while since I've worked with this setup, but hopefully you'll find enough detail here to at least get started.
First, you'd define two (or more) suite XML files:
<suite name="Suite1">
<test name="test1">
<classes>
<class name="fully.qualified.ClassName" />
</classes>
<methods>
<include name="method1" />
</methods>
</test>
</suite>
and...
<suite name="Suite2">
<test name="test2">
<classes>
<class name="fully.qualified.ClassName" />
</classes>
<methods>
<include name="method2" />
</methods>
</test>
</suite>
Then, you'd define a suite-of-suites XML file:
<suite name="suite of suites">
<suite-files>
<suite-file path="Suite1.xml" />
<suite-file path="Suite2.xml" />
</suite-files>
</suite>
Do note, that the suite-file path value is the relative path from the current suite-of-suites XML file to the XML file you're calling. If they're in the same directory, simply the file name will suffice.
Additionally, both XML types do support the <parameter> tag. The standard suite XML will read both at <suite> and in the <test> levels, and I've found that <parameter> tags at the <suite> level on the suite-of-suites XML file will work as well.
Finally, on execution, you'd need only pass in the suite-of-suites XML file as your suite file argument.
EDIT:
Here's how I was able to make my two suites run in parallel. The trick was setting up my main() method properly.
public class TestRunner
{
public static void main(String[] args)
{
TestNG testng = new TestNG();
TestListenerAdapter adapter = new TestListenerAdapter();
List<String> suites = new ArrayList<String>();
testng.addListener(adapter);
suites.add(args[0]);
testng.setTestSuites(suites);
testng.setParallel("parallel");
testng.setSuiteThreadPoolSize(5);
testng.setOutputDirectory("path to output");
testng.run();
}
}
Then, on the command line:
java -jar ParallelSuiteDemo.jar SuiteOfSuites.xml
Note, my jar and all xml files were in the same directory with this configuration. The command line args and <suite-file> entries would need to be configured properly if you wish you use a directory structure.
This yielded my two suite.xml files running in parallel on a Selenium Grid.
There may be better ways of doing this, to be honest. This is just what worked for me when I was trying to do something similar.
You no need to run suits in parallel....instead you can write two tests in single testng.xml suit and can run it in parallel.
If you want to use two different configurations for different tests (browser/os etc) make that as a parameter in testng.xml and use selenium grid to redirect each threads to appropriate nodes
Have look at the below example
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Test Suit" verbose="2" parallel="tests">
<test name="Regression Test">
<parameter name="browser" value="firefox" />
<parameter name="os" value="win7" />
<classes>
<class name="pakagename.classname" />
</classes>
</test>
<test name="Smoke Test">
<parameter name="browser" value="chrome" />
<parameter name="os" value="mac" />
<classes>
<class name="pakagename.classname" />
</classes>
</test>
Also may be you can run two testng.xml suits using ANT or MAVEN. But I prefer 1st one. Please add the below section in pom.xml of your MAVEN project
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng1.xml</suiteXmlFile>
<suiteXmlFile>testng2.xml</suiteXmlFile>
</suiteXmlFiles>
<reportsDirectory>${basedir}/src/test/java/</reportsDirectory>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugins>
<build>
Yes, you can do this by using "suitethreadpoolsize" attribute of testng
<suite-files suitethreadpoolsize="2">
<suite-file path="suite1.xml" />
<suite-file path="suite2.xml" />
</suite-files>
Refer the testng's official website for more details
http://testng.org/doc/documentation-main.html#parallel-running
Thanks!
I'm working in a test suite and I'm currently trying to implement the following design based on the following xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
<parameter name="server" value="http://www.smartdate.com/"/>
<test name="Test" preserve-order="false">
<classes>
<class name="testscripts.SetUp"/>
<class name="testscripts.TestHome"/>
</classes>
</test>
</suite>
In this short example I want the following:
Run SetUp configurations (this class only defines #BeforeSuite, #AfterSuite and may be other annotations like #BeforeClass, #AfterClass, no #Test methods here).
Run all the following classes, in this example just one, "TestHome" but maintaining the previous configurations.
Now the question is, is this possible?
Thank you in advance,
Nahuel
Well, have you tried your proposed design at all? It should work. Try it and report back if something is not working as expected.