how to run Selenium tests in Jenkins - jenkins

I want to run my Selenium Webdriver Maven tests in Jenkins. I've followed the tutorial: https://www.guru99.com/maven-jenkins-with-selenium-complete-tutorial.html and https://www.safaribooksonline.com/library/view/jenkins-the-definitive/9781449311155/ch04s06.html
But now, I want to run each of hundreds tests that I've written in Selenium Webdriver with Eclipse.
I use Maven to create testng.xml (where I have my Maven projects to can execute a list of tests in the same execution).
I use Eclipse to write Java to create tests in Selenium Webdriver.
I use github to import tests.
I show you my github project... I don't know how to access into the different folders to execute each testng.xml files, sorry, I'm pretty new here.
Could anybody help me with this issue?
Thanks so much!!!!

Create a freestyle Jenkins job and then go to the configuration page of your job and in Source Code Management section add the URL of your Git repo where you have kept your TestNG tests. This will help to bring the tests from the repository to your workspace.
Then go to the Build section and select Execute windows batch script if and then add the following script:
java -cp ".;/path/to/testng-x.x.x.jar;/path/to/jcommander-x.xx.jar;/path/to/test-classes" org.testng.TestNG /path/to/test.xml
For Linux use the following script with Execute shell in `Build step:
cd /path/to/test.xml
java -cp "/path/to/testng-x.x.x.jar:/path/to/bin" org.testng.TestNG testng.xml
Where /bin folder contains the compiled code for the TestNG tests.
Then save the job and run the build to execute TestNG test cases.
Note: You can find the required JAR files inside the .m2 folder.

Related

Jenkins fails to find SureFire Reports

Jenkins Version : 2.176.2
Executing Selenium tests via Jenkins : Ecplsie+mvn+Jenkins
Selenium Workspace Folder : C:\Users\admin\eclipse-workspace\ACA
The actual location of the testng-results.xml: C:\Users\admin\eclipse-workspace\ACA\target\surefire-reports\testng-results.xml
Jenkins Insatlled / Home Directory: C:\Program Files (x86)\Jenkins
Building in workspace C:\Program Files (x86)\Jenkins\workspace\ACATestAutomationJob
Executing Maven: -B -f C:\Users\admin\eclipse-workspace\ACA\pom.xml clean install
TestNG Reports Processing: START
Looking for TestNG results report in workspace using pattern: **/target/surefire-reports/testng-results.xml
Did not find any matching files.
How do i make jenkins locate this testng-results.xml?
Thanks,
Raj
Look into Jenkins Console Output, it should report where the build is running (so called WORKSPACE) and where TestNG Results Plugin attempts to locate the results file:
The path to the TestNG results file must be relative to the WORKSPACE and have the syntax of Ant FileSet
If you're uncertain regarding how to properly build the path to the test artifacts - post the full paths to WORKSPACE and the testng-results.xml / emailable-report.html and we will help you to come up with the correct definitions.
In the meantime you could use wildcard paths like:
**/testng-results.xml
so Jenkins will scan its WORKSPACE recursively looking for the testng-results.xml file in all available locations
Your install command also looks suspicious, normally you should not be putting your test artifacts to the Maven repository so you might want to use mvn test or mvn verify instead.
More information:
Turbo Boost Your Digital App Test Automation with Jenkins
https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

test-output folder is not created when i execute maven project in jenkins

I have selenium project created using Maven. I have included surefire plugin also . When i execute the "mvn test" command using jenkins . I am not able to see the test-output folder . Could you please help me to fix it
TestNG would create the output folder as test-output only when running it via the IDE such as eclipse or IntelliJ.
When you run TestNG tests via Maven using surefire plugin, then the output folder is controlled by surefire plugin which is passed on to TestNG as part of the initialization.
By default surefire reports are available under target/surefire-reports folder where target folder is the default build output folder.
You can customize or change this folder value via https://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#reportsDirectory
After executing test script then
Right click on your project folder into eclipse and click on refresh
button. test-output folder will appear in TestNG

Can we run Junit5 cases in eclipse mars?

Shall we run Junit5 with eclipse-mars
Below are the jars added into build path

Change directory during a build job on jenkins

I am building a gradle project and the source code is in git. After checking our repo to jenkins' workspace, how do i have jenkins go to a sub-directory and do the build?
I tried adding shell commands but cd will not work as it executes script on a separate shell.
If you are building a gradle project, perhaps you should use the "Invoke gradle script" step rather than a shell script?
As part of the gradle build script, it has an option to specify the "Root Build script", which will let allow you to specify a subdirectory if you wish.
See the Gradle plugin for more information.

How to integrate Gradle jmeter plugin with jmeter + jenkins

How to locate build.gradle file ?. Under which folder i need to create build.gradle file ? I am saving all my .jmx test files under jmeter/bin folder
Do i need to create a new java project in IDE to use Gradle?
Please provide detail steps to integrate Gradle jmeter plugin with jmeter + Jenkins
To create a standalone gradle project that runs jmeter tests, you can create a new folder and add a file build.gradle to it, with the following contents:
plugins {
id "net.foragerr.jmeter" version "1.0.3-2.13"
}
Create a folder src/test/jmeter and place all your test .jmx files there.
From jenkins you can run gradle jmrun to run tests and gradle jmreport to generate reports.

Resources