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
Related
I Have TestNg Class look like the following code:
And I have On Jenkins two jobs: job1 and job2 job1 to execute TestsFluxPro and job2 to execute TestsVente tests
my question is how to configure Jenkins to tell in each job run the chosen class test for example in job 1 I want to execute com. AZ. testsFlux. TestsVente!!!
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="false">
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter"
/>
<listener class-name="com.az.utilities.CustomListeners" />
</listeners>
<test name="Managetestss" group-by-instances="true">
<parameter name="browser" value="firefox"></parameter>
<classes>
<class name="com.az.testsFlux.TestsFluxPro" />
<class name="com.az.testsFlux.TestsVente" />
</classes>
</test>
</suite>
Reconsider using testng.xml, you will not be able to parameterize it from Jenkins.
There is a possibility to run your TestNG test in command-line mode where you have -testclass parameter:
-testclass A comma-separated list of classes that can be found in your classpath. A list of class files separated by commas (e.g. org.foo.Test1,org.foo.test2).
So you should be able to kick off your tests execution like:
For com.az.testsFlux.TestsFluxPro :
java -cp "/path/to/test.jar;/path/to/test/dependencies/*" org.testng.TestNG -testclass com.az.testsFlux.TestsFluxPro
For com.az.testsFlux.TestsVente
java -cp "/path/to/test.jar;/path/to/test/dependencies/*" org.testng.TestNG -testclass com.az.testsFlux.TestsVente
To run both:
java -cp "/path/to/test.jar;/path/to/test/dependencies/*" org.testng.TestNG -testclass com.az.testsFlux.TestsVente,com.az.testsFlux.TestsFluxPro
etc.
I am executing TestNG test with Jenkins build and Allure plugin. My problem is that if I am executing them from IDEA all test results are displayed.
If I am using same configuration from Jenkins some tests are missing.
XML Suite file
<suite name="All in one" verbose="1" thread-count="2" parallel="methods" >
<test name="Chrome:MainPage">
<parameter name="browser" value="chrome"/>
<classes>
<class name="mainPage.MainPageTest" />
<class name="patients.PatientsPageTest"/>
</classes>
</test>
<test name="Firefox:MainPage">
<parameter name="browser" value="firefox"/>
<classes>
<class name="mainPage.MainPageTest" />
<class name="patients.PatientsPageTest"/>
</classes>
</test>
Result from Allure when directly "called" on results is good.
Allure plugin from Jenkins ignores some tests , and i have no idea why.
I found solution after 2 days , i am not sure which of them worked , but maybe someone will run into same issue someday...
Check Jenkins version of Allure plugin
Check Gradle version of Allure plugin
Check TestNG for validity i missed this
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
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
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!
Currently I have a GitHub Repo that contains 4 Selenium/Maven Tests. I am able to run each test individually on my local machine via mvn test
I have Jenkins running also on my local machine and created a maven project to pull my GitHub Repository, select the pom.xml in one of the test (P_ProfileChangeMavenTest) and then execute a test as my maven goal.
When Jenkins runs my test, it begins to go though my maven project but is not pulling up Firefox browser to interact with my test.
pom.xml
<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.test.profilechange</groupId>
<artifactId>Profile</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Profile</name>
<description>PRofile</description>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.39.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire</artifactId>
<version>2.16</version>
<type>pom</type>
</dependency>
</dependencies>
</project>
I am fairly new to Automation and am trying to verify that everything works correctly on my local machine first before sending these tests to run on a server with a selenium grid.
All the help would be greatly appreciated since I need to get this working ASAP.
Thanks in advanced!
What I have found works for us is using testNg to run the tests. We create an XML file with the different tests that we want run and we use
mvn test -D testng=testname.xml
TestNG is a great framework for integration style tests whereas the J Unit testing framework is more designed for unit tests.
A sample of the xml file would be something like this.
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name=" Report - Create New Report and Add Fields By Double Click and Filter by Right Clicking" parallel="none" verbose="1">
<test verbose="1" name="is site available" preserve-order="true">
<classes>
<class name="com.somecompany.qa.seleniumautomation.PucDD">
<methods>
<include name="siteAvailable" />
</methods>
</class>
</classes>
</test>
<test verbose="1" name="Login as 'admin' 'password'" preserve-order="true">
<classes>
<class name="com.somecompany.qa.seleniumautomation.PucDD">
<methods>
<parameter name="login.user" value="admin" />
<parameter name="login.password" value="password" />
<include name="login" />
</methods>
</class>
</classes>
</test>
<test verbose="1" name="Create a new Report based on the provided data source" preserve-order="true">
<classes>
<class name="com.somecompany.qa.seleniumautomation.Reports">
<methods>
<parameter name="data.source.name" value="Orders" />
<include name="createNewReport"/>
</methods>
</class>
</classes>
</test>
<test verbose="1" name="Add the passed fields to the report by double clicking and add the passed filters by right clicking the field." preserve-order="true">
<classes>
<class name="com.company.qa.seleniumautomation.Reports">
<methods>
<parameter name="login.user" value="admin" />
<parameter name="login.password" value="password" />
<parameter name="fields" value="Customer Number,Customer Name,Order Date,Status,Shipped Date" />
<parameter name="filterCriteria" value="Customer Number:lte=300,Customer Number:gte=150,Product Lines:contains=a" />
<include name="addFilters"/>
</methods>
</class>
</classes>
</test>
<test verbose="1" name="Close the report" preserve-order="true">
<classes>
<class name="com.company.qa.seleniumautomation.Reports">
<methods>
<include name="close"/>
</methods>
</class>
</classes>
</test>
</suite>
the jenkins job is running on it's own client. it don't have a visible UI, that's why you test failed.
you should change you test code to use Remote Webdriver or Selenium Grid
//need to start a selenium standalone server
DesiredCapabilities capability = DesiredCapabilities.firefox();
WebDriver driver = new RemoteWebDriver(new URL("http://SERVER_ADDRESS:4444/wd/hub"), capability);
refer to Selenium Grid Wiki for more detaisl
If you start Jenkins using command line and if you run tests then you can see running tests on browser.
Command to start Jenkins using command line :
java -jar jenkins.war
Hope this helps.
Try to run it as admin from the command prompt, worked for me.
If you are on Windows :
1).Go to command prompt:
type "cmd"
2).Press Ctl+Shft+Enter(to open as admin)
3).Type "Services.msc"
4).It will open the Windows Services,select "Jenkins" Service , right click & open properties and go to "Log On" tab and select "Local System Account" and select "Allow service to interact with the Desktop".
5).Press OK.
6).A dialog box will open .Click "View The Message" on the window "A program running on this computer is trying to display a message".
Now you can see the tests running on the same machine...enjoy!