X07b - Integrating Jenkins With Automated Integration and UI Testing
X07b - Integrating Jenkins With Automated Integration and UI Testing
Recall that the Agile testing pyramid recommends not only automated unit testing, but also suitable
amount of integration and UI testing although with lesser amount of automation.
You may be wondering how to perform automated integration and UI testing where user
interactions are required. The answer lies with the use of headless browser which is a browser
without GUI. Specifically, one of the popular tools available is Selenium coupled with WebDriver
such as HtmlUnitDriver, FirefoxDriver or ChromeDriver, etc.
To help you, this Lab 7b will guide you on the use of Selenium and HtmlUnit to perform automated
integration and UI testing so that you are able to start incorporating it into your team project.
Outcomes
Upon completion of this lab, you should be able to:
• Write test cases for automated integration and UI testing using Selenium with HtmlUnit
• Create Jenkins pipeline to perform automated integration and UI testing on a simple PHP
application
• Start incorporating Jenkins Pipeline with automated testing into your team project
1: Pre-requisite
PHP
We’ll use the PHP Login and Logout with Session example from https://www.wdb24.com/session-
in-php-example-for-login-logout/ but the original codes seem to have some bugs. So, the codes
are corrected, simplified with one pair of hard-coded email and password for one user, and are
zipped up inside the provided attached file jenkins-php-selenium-test.zip.
Git
Besides the PHP app, the attached file jenkins-php-selenium-test.zip also contains a
Jenkinsfile and an AppTest.java file with example test cases for automated integration and UI
testing using Selenium with HtmlUnit.
Change the access rights of the two accompanied script files so that they can be run by Jenkins:
git update-index --chmod=+x jenkins/scripts/deploy.sh
git update-index --chmod=+x jenkins/scripts/kill.sh
Inside the script file deploy.sh, update the path c:\\...\\jenkins-... as shown below to
correspond to the location of your Git repository:
Create a new Pipeline for the app in Section 1. If you need help, refer to Lab X05.
The Jenkinsfile
Notice that the Jenkins pipeline is written with two stages running in parallel, where the
stage(‘Deploy’) is to deploy the PHP server whereas the stage(‘Headless Browser Test’) will
perform the integration and UI test when the server is running.
b) After updating, go through the example codes to have a feel of how to write integration
and UI testing using Selenium with HtmlUnit. The url for the available Selenium and
HtmlUnit APIs can be found in Section 3 References.
c) Next, run the Jenkins pipeline where you will notice that the PHP server is being deployed
as shown:
d) While the test is running, you may wish to open up a web browser to visit the web server
at http://localhost to have a feel of how the PHP app works.
f) When done, click the Proceed button to kill the PHP server process as shown:
g) Exit from the Blue Ocean UI and return to Jenkins classic UI where you will see the Test
Result Trend as shown on Page 1 of this hand-out.
Hope that now you have a good understanding of how to implement automated integration and UI
testing and is able to start incorporating it into your team project. Enjoy!
3: References
Selenium API https://www.selenium.dev/selenium/docs/api/java/
END OF DOCUMENT