skip to main |
skip to sidebar
Platform:
- Windows 7 VM (Oracle VM ViortualBox)
Software:
- Python 3.5.1 (32-bit)
- Python 3.5 pywin32-220
- Python unittest-xml-reporting 2.1.0
- Python Jenkins 0.4.13
- Java 8 Update73
- Jenkins 1.642.4
- Jenkins Next Builder Number plugin
- Jenkins Email Extension Plugin
Python scripts structure example:
Python TestSuite_jenkins.py example:
Install:
- Download and install python 3.5.1 on Windows 7 VM (get python from https://www.python.org/downloads/)
- Download
and install python3.5 pywin32 on Windows 7 VM (get pywin32 from
https://sourceforge.net/projects/pywin32/files/pywin32/)
- Download and install unittest-xml-reporting 2.1.0 on Windows 7 WM (get it from https://pypi.python.org/pypi/unittest-xml-reporting)
- Donwload and install Python Jenkins on Windows 7 VM (get info from https://pypi.python.org/pypi/python-jenkins)
- Download and install Java 8 runtime on Windows 7 VM (get Java 8 from http://www.java.com/en/download/windows_xpi.jsp)
- download
and install Jenkins on Windows 7 VM (get Jenkins from
https://jenkins.io/content/thank-you-downloading-windows-installer/#stable)
- Open a web browser, load URL: http://localhost:8080. examine the Jenkins main page is loaded.
- Jenkins main page, select Manage Plugins. Download and install "Email Extension Plugin".
Jenkins Setup:
- Configure the PATH in Jenkins:
- Jenkins main page, select Manage Jenkins to load Manage Jenkins page.
- Manage Jenkins page, select Configure System to load configuration page.
- Under Global properties, enable Environment variables and add a new key-value pairs as following:
name: PYTHON_PATH
value: C:\Python35\;C:\Python35\python.exe;C:\Python35\lib;C:\Python35\DLLs;C:\Python35\lib\site-packages;C:\Python35\lib\site-packages\win32;C:\Python35\lib\site-packages\win32\lib;C:\Python35\lib\site-packages\Pythonwin
- Add a Python Job to Jenkins:
- Jenkins main page, select New Item. Input Item Name, let's say PythonAutoTestSuites. Select Freestyle project.
- Setup python Job:
- enable Advanced Project Options, select Use custom workspace. input Directory string "C:\eclipse_workspace\python\PATS", which is the OS path to the pyton script main folder.
- Under Build section, select Add build step to add a new "Execute Windows batch command". Input following string under Command fields:
SET PATH=%PATH%;%PYTHON_PATH%
python C:\eclipse_workspace\python\PATS\TestSuite_jenkins.py
- Under Post-build Actions, select Add post-build action to add "Publish Junit test result report". Input following string junder Test report XMLs field.
test_reports\*.xml
How to reset build number:
- Rename <project name> to <project name> - Copy.
- Create a new job named <project name>, using 'Copy existing job' option, from <project name> - Copy.
- Delete job <project name> - Copy.
How to modify build number to display name and description:
- the default build number 1, 2, 3 ... is not user friendly. we can customized and make it display a name and description instead of the number.
- to make this work, we need using Python Jenkins module and Jenkins Next Builder Number plugin.
- modify TestSuite_jenkins.py as following:
- the new build will display "Build 0.0.1 Overnig test" instead of a number, and there's description for the new build.
How to setup email notification and including test result summary inside email:
- select job configuration for PythonAutoTestSuite.
- Under Post-build Actions, select add "Editable Email Notification"
- input email addresses under Project Recipient List fields.
- select HTML (text/html) as Content Type.
- input $(SCRIPT, template="PythonAutoTestSuites-Subject.groovy"} under Default Subject field.
- input ${SCRIPT, template="PythonAutoTestSuites-Content.groovy"} under Default Content field.
- Add an "Always" Trigger, select Send to "Recipient List".
- Apply changes to current job.
- locate jenkins home directory, let's say C:\Program Files (x86)\Jenkins
- create a new folder "email-templates" if it is not exist.
- add two groovy script files to email-templates folder: PythonAutoTestSuites-Subject.groovy, PythonAutoTestSuites-Content.groovy. the sample groovy scripts are as following
- Jenkins configuration, under E-mail Notification, make sure you have SMTP Server setup properly.
- each time you generate a build / test, the receipients will receiving an email notification which including the testing build and test summary informaiton like following:
How to enable web browser interactive test:
- If jenkins is loaded as a windows service, the tests which interactive with web browser (selenium webdriver) will not load and display web browser.
- you have to:
1. Stop / disable jenkins from windows services
2. Create a windows batch file, let's call it jenkins.bat with following lines
SET JENKINS_HOME=C:\Program Files (x86)\Jenkins
java -jar "C:\Program Files (x86)\Jenkins\jenkins.war"
3. Modify C:\Program Files (x86)\Jenkins folder security property to give full access control to current user.
4. Execute jenkins.bat batch file to load jenkins.