0% found this document useful (0 votes)
44 views6 pages

X07b - Integrating Jenkins With Automated Integration and UI Testing

This document discusses integrating Jenkins with automated integration and UI testing. It provides guidance on using Selenium and HtmlUnit to perform automated integration and UI testing. It describes setting up a Jenkins pipeline with two stages, one for deploying a PHP app and one for running integration and UI tests on the app using Selenium and HtmlUnit.

Uploaded by

Aqil Syahmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views6 pages

X07b - Integrating Jenkins With Automated Integration and UI Testing

This document discusses integrating Jenkins with automated integration and UI testing. It provides guidance on using Selenium and HtmlUnit to perform automated integration and UI testing. It describes setting up a Jenkins pipeline with two stages, one for deploying a PHP app and one for running integration and UI tests on the app using Selenium and HtmlUnit.

Uploaded by

Aqil Syahmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Lab-X07b Page 1 of 6

Integrating Jenkins with Automated


Integration and UI Testing
Overview

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

ICT3103/3203 Secure Software Development AY2023/2024 Trimester 1


2020
Lab-X07b Page 2 of 6

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.

Unzip and initialize it as a Git repository using the command:


git init

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:

Next, commit with the commands:


git add .
then
git commit -m “Add initial files”

ICT3103/3203 Secure Software Development AY2023/2024 Trimester 1


2020
Lab-X07b Page 3 of 6

2: Integrating Automated Integration and UI Testing


into Jenkins Pipeline
Create new Jenkins Pipeline

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.

ICT3103/3203 Secure Software Development AY2023/2024 Trimester 1


2020
Lab-X07b Page 4 of 6

Run Jenkins Pipeline with Integration and UI Test

a) Before running the Jenkins pipeline, follow the path /home/src/test/java/mycompany/app


and open using a text editor the AppTest.java to change the variable url currently pointing
to localhost to the actual allocated IP address (not 127.0.0.1) of your laptop (because
the PHP app seems not accessible via localhost or 127.0.0.1 within docker even though
it is running locally).

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:

ICT3103/3203 Secure Software Development AY2023/2024 Trimester 1


2020
Lab-X07b Page 5 of 6

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.

e) After a while, the integration and UI test should pass as indicated:

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!

ICT3103/3203 Secure Software Development AY2023/2024 Trimester 1


2020
Lab-X07b Page 6 of 6

3: References
Selenium API https://www.selenium.dev/selenium/docs/api/java/

HtmlUnit API https://www.selenium.dev/htmlunit-


driver/index.html?org/openqa/selenium/htmlunit/HtmlUnitDriver.html

END OF DOCUMENT

ICT3103/3203 Secure Software Development AY2023/2024 Trimester 1


2020

You might also like