jenkins test automation code example

Example 1: how to trigger test in jenkins

2. Build Triggers
We specify how often we run those tests.
we choose Build periodically because we
want to run in certain schedule. 
in my project, we run smoke tests every morning.
so in the build trigger we entered daily option:
H 6 * * * --> every day around 6 am.
Jenkins used a cron expression, and the different fields are:

  H * * * *   ==> Build every hour at any minute (6.12 am, 8.38pm)
  0 * * * *   ==> Build every hour at exactly on the hour (6.00 am, 8.00pm)
  0 8 * * *   ==> Build every day exactly 8.00 am
  H/5 * * * * ==> Build every 5 minutes
  H 6 * * 1-5 ==> Build around 6 am from first day of the week (Monday) to 5th day (Friday)
  H 1 * 6,20 * * ==> Build on 6th and 20th day of the month around 1 am for regression

Example 2: how to connect test to jenkins

enter into search box ip:8081 or ip:8080 to hit Jenkins.

default port for Jenkins is 8080. In our case, it was switched to 8081.
web application - any application used over the browser.
Steps to create a smoke test job:
I write the name of the test, such as smoke-test.

1. Source Code Management Section
here we specify where to get the code from. we put the link to our 
GitHub repo and also enter the credentials

2. Build Triggers
I specify how often I run those tests. I choose Build periodically 
because I want to run in certain schedule. In my project, I run smoke 
tests every morning at 6 am. So in the build trigger I entered daily option:
	H 6 * * * --> every day 6 in the morning

3. Build Section
I enter the details of the actual run. Since my project is based 
on maven, I choose option: invoke top-level maven targets then I choose 
which maven to run from the version dropdown. In the next field, I enter 
the maven goal: test. In this field we do not need to enter the word mvn. 
I also mention here which tag I want to run. So the command will be: 
	test -Dcucumber.options="--tags @smoke"

4. Add Post-build Actions
In the post build actions, I configure what I want to to after the ends. 
After each test I generate report and email to my team members.
For Report, I select cucumber reports plugin from the post-build actions to 
generate reports. 
For email, I select Editable Email Notification option from the Post-build 
Actions to send emails to my team.

Tags:

Misc Example