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!
Related
I have this TestNG part :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<listeners>
<listener class-name="ShufersalMiron.Sprod.Listeners"/>
</listeners>
<test name="Test1">
<classes>
<class name="ShufersalMiron.Sprod.PA_Coupons"/>
</classes>
</test> <!-- Test -->
<test name="Test2">
<classes>
<class name="ShufersalMiron.Sprod.PA_SupermeCoins"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
When I am trying to run it as a suite I get this error :
Can someone please tell me what could be wrong and how to solve it please ?
Thanks.
The error might be due to conflicting dependencies.
extentreports-java version 5.0.9 (latest for now)
https://github.com/extent-framework/extentreports-java/blob/master/pom.xml
uses io.reactivex.rxjava3:rxjava-3.0.4 and org.testng:testng-7.3.0.
I can suggest 2 options:
Try to add io.reactivex.rxjava3 dependency, since
NoClassDefFound error references this.
Maven:
<dependency>
<groupId>io.reactivex.rxjava3</groupId>
<artifactId>rxjava</artifactId>
<version>3.0.4</version>
</dependency>
Gradle:
implementation 'io.reactivex.rxjava3:rxjava:3.0.4'
Try to use testNG 7.3.0 instead of 7.4.0.
i've setup my xml so it will run groups which depends-on different group in order to run.
when the different group fails, i would expect that the groups won't run, but it is still running.
here is my code:
<test name="Test1">
<parameter name="testedApp" value="someValue"/>
<groups>
<run>
**<include name="Test1"/>**
<exclude name="TestX"/>
<exclude name="TextY"/>
</run>
<dependencies>
<!-- Service Health Check -->
**<group name="Test1" depends-on="ServiceHealthCheck"/>**
</dependencies>
</groups>
<packages>
<package name="project.auto.tests.api...*"/>(package)
</packages>
<classes>
<!-- Service Health Check -->
<class name=".....PbServiceHealthCheckTest"/>(class)
</classes>
</test>
Answer: TestNG 6.14.3 has a bug which prevenr the "depends-on" to work correctly.
Upgrade to TestNG 7.1.0 solved the issue.
Whenever we run our test suite in parallel as "tests" with the TestNG xml file, it opens both instances of a chrome driver, but intermediately executes both cucumber features in the same window of chrome.
Gives us some result like this:
Searches two times in the search bar
This are Maven dependencies we have:
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
We use a test runner for each test. All test runners are basically the same. Here is a test runner used:
package bdxReport.biAdsDashboard.AdvertisingPerformance.Content;
import cucumber.api.CucumberOptions;
import org.testng.annotations.Test;
#CucumberOptions(
features = "src/test/resources/FeaturesAdsDashboard/FeaturesAdvertisingPerformance/Content/CheckContentAdvertisingByProduct.feature",
glue = {"stepDefinitions"},
format = {
"pretty",
"html:target/cucumber-reports/AdsDashboard/TestRunnerCheckContentAdvertisingByProduct-Reports",
"json:target/cucumber-reports/AdsDashboard/TestRunnerCheckContentAdvertisingByProductReport.json",
"rerun:target/cucumber-reports/AdsDashboard/TestRunnerCheckContentAdvertisingByProduct-Reports/rerun.txt"
})
#Test
public class TestRunnerCheckContentAdvertisingByProduct {
private TestNGCucumberRunner testNGCucumberRunner;
#BeforeClass(alwaysRun = true)
public void setUpClass() throws Exception {
testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
}
#Test(groups = "cucumber", description = "Runs Cucumber Feature", dataProvider = "features")
public void feature(CucumberFeatureWrapper cucumberFeature) {
testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());
}
#DataProvider
public Object[][] features() {
return testNGCucumberRunner.provideFeatures();
}
#AfterClass(alwaysRun = true)
public void tearDownClass() throws Exception {
testNGCucumberRunner.finish();
}
}
And this is the TestNG xml suite:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="BDX Executive Summary Advertising Performance" parallel="tests" thread-count="20" preserve-order="true">
<listeners>
<listener class-name="common.testcases.TestCaseListener" />
<listener class-name="common.testcases.CaptureScreenshotOnFailureListenerBDX"/>
</listeners>
<test name="01: Check Advertising Performance Section Data">
<classes>
<class name="bdxReport.biExecutiveSummary.AdvertisingPerformance.Data.TestRunnerAdvertisingSectionData" />
</classes>
</test>
<test name="02: Check Advertising Performance Section Content">
<classes>
<class name="bdxReport.biExecutiveSummary.AdvertisingPerformance.Content.TestRunnerAdvertisingSectionContent" />
</classes>
</test>
</suite>
We have done a lot of research on what could be causing this behavior but until now we haven't been able to determine whats causing this behavior
Creating a separate runner file for every feature does not make sense to me. Have you tried "cucumber-jvm-parallel-plugin" to run the features. Please check following answer:
How to execute cucumber feature file parallel
Further, as per my experience this is the issue with the driver you are instantiating either it is static or it is not being managed properly. Firstly, try above link, in the meantime let me implement parallel execution in a fresh automation framework and I will paste the code here
To take maximum advantage of TestNG you should use Testng's QAF framework. It supports multiple bdd syntax including gherkin using GherkinFactory.
QAF considers each scenario as TestNG test and Scenario Outline as TestNG data-driven test. As qaf provides driver management and resource management in-built, you don't need to write single line of code for driver management or resource management. All you need to do is create TestNG xml configuration file as per your requirement either to run parallel methods (scenarios) or groups or xml test on one or more browser.
Below example will run scenarios in parallel.
<test name="Gherkin-QAF-Test" parallel="methods">
<parameter name="step.provider.pkg" value="com.qmetry.qaf.automation.impl.step.qaf" />
<parameter name="scenario.file.loc" value="resources/features" />
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
It enables different possible configuration combinations. Here is another example where it will run scenarios in two browsers and in parallel. You can configure number of threads for each browser as standard TestNG xml configuration.
<suite name="AUT Test Automation" verbose="0" parallel="tests">
<test name="Test-on-chrome" parallel="methods">
<parameter name="step.provider.pkg" value="com.qmetry.qaf.automation.impl.step.qaf" />
<parameter name="scenario.file.loc" value="resources/features" />
<parameter name="driver.name" value="chromeDriver" />
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
<test name="Test FF" parallel="methods">
<parameter name="step.provider.pkg" value="com.qmetry.qaf.automation.impl.step.qaf" />
<parameter name="scenario.file.loc" value="resources/features" />
<parameter name="driver.name" value="firefoxDriver" />
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
</suite>
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
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!