Sahi Pro - Integrate with Jenkins
abstract
Jenkins and other Continuous Integration systems can trigger Sahi scripts as part of the build process.
Execution of Sahi scripts/suites can be triggered via ANT targets. Jenkins triggers Sahi via ANT.
Execution of Sahi scripts/suites can be triggered via ANT targets. Jenkins triggers Sahi via ANT.
Building the new jenkins software project
Sahi Pro needs real browsers to playback test scenarios. But most Jenkins/build machines run in server mode and do not have a GUI.
This forces end users to either try with headless browsers or to execute Sahi scripts remotely.
With Sahi, this is what you can do:
Jenkins machine (J): Run Jenkins on server. No Sahi installed.
Sahi Master machine (SM): Sahi Pro runs on this machine and behaves as Master
Sahi slave machines (SL1, SL2, SL3): These are slave machines with Sahi Pro running on them.
During the build process:
Jenkins pulls the latest scripts from the Source Control Management (SCM) system.
It calls the Sahi ant target. Sahi target copies over the scripts from Jenkins (J) to master (SM).
SM then copies scripts to SL1, SL2, SL3, distributes the execution and collects all reports.
Sahi ant target then pulls reports from SM to Jenkins.
This allows Jenkins to remain a headless server and does not need Sahi installed on it.
Also all distribution of scripts and pulling of reports happens through Sahi's ant target itself.
Prerequisites
Before integration, you will first need an ant target to run the suite file.You can create the ANT target from the editor using playback options.
Save the file in any path accessible by Jenkins (say
C:\jenkins_sahi
) and lets call it build.xml
.info
At the end of the configuration steps in this page, your folder structure should look like this:
C:
|--jenkins_sahi
|
|--build.xml
|--email.properties
|--lib
|
|--ant-sahi.jar
In the build.xml make sure that:
scriptDir
points to where your Sahi scripts will reside on your Jenkins machine.
This will mostly be the local directory where the scripts are checked out via Git or SVN.
If your checkout directory isE:/automation/scripts/
your build.xml should have
<property name="scriptDir" value="E:/automation/scripts/"/>
- Offline reports path should be configured correctly.
The path in report tag in build.xml should be the same as that used in Publish HTML Reports in Jenkins configuration
In this example, we use<report type="html" logdir="C:/jenkins_sahi/logs/"/>
-
If email is configured to be sent at the end of a build,
the path toemail.properties
inbuild.xml
should point to the correct location.
You will need to copySahiPro/userdata/config/email.properties
intoC:/jenkins_sahi/email.properties
and have this inbuild.xml
<property name="emailproperties" value="C:/jenkins_sahi/email.properties"/>
Also Install the HTML Publisher plugin if you wish to see HTML logs via Jenkins UI.
Let us assume that Jenkins is available in
C:\.jenkins\
Configure Jenkins
- From the Jenkins dashboard, click on
New job
(orNew item
). - Enter job (or item) name as
SahiFunctionalTests
(This will be the name of the job identified by Jenkins.) - Select
Build a free-style software project
. Click OK.
- At this point, you should be directed to the Configure page. Click on
Add build step
. Selectinvoke Ant
- Type
-f C:/jenkins_sahi/build.xml
in the ANT target textbox.
- Copy
SahiPro/lib/ant-sahi.jar
from your Sahi Pro installation folder intoC:/jenkins_sahi/lib/ant-sahi.jar
-
To publish HTML reports after build, click on
Add Post Build Action
button and selectPublish HTML Reports
.
infoNote: You need to install HTML Publisher plugin for this step. To learn more, please use this linkProvide Logs directory and other details.
Please note, in the field of "HTML directory to archive" you need to provide the same path defined in the report attribute of Sahi task in build.xml.
e.g.<report type="html" logdir="C:/jenkins_sahi/logs/"/>
. This is configured via theOffline Reports
in the Editor Playback Properties UI.
-
On the Jenkins dashboard, click
Build now
.
info- If you are using distributed playback with a different Master, make sure that Sahi Pro is installed and running on the Master and relevant slaves. Sahi Pro installation is not required on Jenkins machine in this case. (RECOMMENDED)
- If you are using parallel or single session or distributed run with same master, make sure Sahi Pro is installed and running on the Jenkins machine and on relevant slaves.
View Sahi Pro HTML Logs in Jenkins
info
Note: You need to have HTML Publisher plugin installed.
Make sure you have configured HTML Reports as described in the section above.
Once HTML Reports are configured, one can view Sahi's report logs by clicking on the "HTML Reports" link on the left side navigation links on the Jenkins project page.Make sure you have configured HTML Reports as described in the section above.
Sahi Pro HTML logs look like this: