Jamming With Jenkins: Integrate

In the first part of this series, we have seen how to install and make the Jenkins up and running.

image.png

In this part, we will integrate the framework with Jenkins to trigger the test cases. First of all, start your Jenkins server by executing the war file in the local in the cmd window before you hit the localhost URL, switch to Java version 11[supported], then write java -jar jenkins.war and hit enter. It will start your server on local host:8080

image.png

And, you will see the Jenkins up and running in the browser window.

image.png

Provide your login details which you created at setup, and click on the sign-in button.

image.png

Creating first job/project in Jenkins

Click on New Item on the dashboard page.

image.png

Enter the Project name, select Freestyle Project and click on the OK button

image.png

Once you click on OK, it will take you to the Configuration page there you need to click on Advanced under General Section and select the Use custom workspace checkbox

image.png

Now, provide the Path location of the Eclipse Project that you wish to Run, in the Directory.

image.png

Paste the location in the Directory

image.png

Now, go down to the Build Section and select Invoke top-level Maven targets.

image.png

Provide the same command that we used in Running Test cases with the Maven article

test verify -Dcucumber.filter.tags="@AddBook" image.png

Save the project

image.png

Running your project in Jenkins. To run your test cases, click on Build Now and go to the console output.

Started by user Prem Singh Rathore
Running as SYSTEM
Building in workspace C:\Users\prem.rathore\eclipse-workspace\LibraryAPIFramework
[LibraryAPIFramework] $ cmd.exe /C "mvn test verify -Dcucumber.filter.tags=@AddBook && exit %%ERRORLEVEL%%"
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for CucumberBDD:LibraryAPIFramework:jar:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-surefire-plugin is missing. @ line 19, column 21
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] 
[INFO] ------------------< CucumberBDD:LibraryAPIFramework >-------------------
[INFO] Building LibraryAPIFramework 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from central: https://repo.maven.apache.org/maven2/io/cucumber/messages/maven-metadata.xml
Progress (1): 2.0 kB

Downloaded from central: https://repo.maven.apache.org/maven2/io/cucumber/messages/maven-metadata.xml (2.0 kB at 1.4 kB/s)
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ LibraryAPIFramework ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\prem.rathore\eclipse-workspace\LibraryAPIFramework\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ LibraryAPIFramework ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ LibraryAPIFramework ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\prem.rathore\eclipse-workspace\LibraryAPIFramework\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ LibraryAPIFramework ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ LibraryAPIFramework ---
[INFO] Surefire report directory: C:\Users\prem.rathore\eclipse-workspace\LibraryAPIFramework\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running cucumber.Options.TestRunner
Library/Addbook.php
Book ID from response body-->atmttd22776
Library/GetBook.php
?????????????????????????????????????????????????????????????????????????????????????
? Share your Cucumber Report with your team at https://reports.cucumber.io          ?
? Activate publishing with one of the following:                                    ?
?                                                                                   ?
? src/test/resources/cucumber.properties:          cucumber.publish.enabled=true    ?
? src/test/resources/junit-platform.properties:    cucumber.publish.enabled=true    ?
? Environment variable:                            CUCUMBER_PUBLISH_ENABLED=true    ?
? JUnit:                                           @CucumberOptions(publish = true) ?
?                                                                                   ?
? More information at https://reports.cucumber.io/docs/cucumber-jvm                 ?
?                                                                                   ?
? Disable this message with one of the following:                                   ?
?                                                                                   ?
? src/test/resources/cucumber.properties:          cucumber.publish.quiet=true      ?
? src/test/resources/junit-platform.properties:    cucumber.publish.quiet=true      ?
?????????????????????????????????????????????????????????????????????????????????????
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 10.622 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ LibraryAPIFramework ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\prem.rathore\eclipse-workspace\LibraryAPIFramework\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ LibraryAPIFramework ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ LibraryAPIFramework ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\prem.rathore\eclipse-workspace\LibraryAPIFramework\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ LibraryAPIFramework ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ LibraryAPIFramework ---
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ LibraryAPIFramework ---
[INFO] 
[INFO] --- maven-cucumber-reporting:5.5.4:generate (execution) @ LibraryAPIFramework ---
[INFO] About to generate Cucumber report.

Aug 14, 2021 8:36:53 PM net.masterthought.cucumber.ReportParser parseJsonFiles
INFO: File 'C:\Users\prem.rathore\eclipse-workspace\LibraryAPIFramework\target\jsonReports\Library-report.json' contains 1 features
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  24.849 s
[INFO] Finished at: 2021-08-14T20:36:54+05:30
[INFO] ------------------------------------------------------------------------
Finished: SUCCESS

In the next part, we will see how to run the Jenkins job/project with a parameterized build.

Thanks for reading.