In one of my last tutorials, i show how to develop test tools for software tester with Python. Now i will show you, how to publish continuous integration status information for other team members like Scrum master, Product owner or Test manager.
If you don`t have Jenkins or Hudson running, search some public services with Google!
Example: inurl:8080 intitle:”Dashboard [Jenkins]”
Steps
Create a python script like this:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import ast
import urllib
class JenkinsAPI(object):
api = "/api/python?depth=1&tree=jobs[displayName,lastBuild[result]]"
def __init__(self):
self.url = 'http://masi.vuse.vanderbilt.edu:8080/jenkins/'
def _get_status(self):
xml_input_no_filter = ast.literal_eval(
urllib.urlopen(self.url + self.api).read()
)
all_jobs = xml_input_no_filter['jobs']
return all_jobs
def show_results(self):
job = self._get_status()
fail = [row for row in job if 'SUCCESS' != row['lastBuild']['result']]
passed = len(job) - len(fail)
print "Jenkins: %s" % self.url
print "Jobs: %s - Successful: %s - Failed: %s" % (
len(job), passed, len(fail)
)
if len(fail) > 0:
for (i, item) in enumerate(fail):
print " > Job: %s - %s" % (
item['displayName'], item['lastBuild']['result']
)
del i
if __name__ == '__main__':
RUN = JenkinsAPI()
RUN.show_results()
Now start GeekTool and create a new Geeklet. Drag a Shell Geeklet on you Desktop. Now insert values for name, size, set colors and so on and add the python script on “Command”.
… the script.
Thats it! Now you can export the Geeklet and share it with you team members. My current screen looks like:
A lot of software testers do have no or less development skills. They also have less skills to use commandline tools and need GUI applications. In addition, the test applications for the respective claims should be easy to use. This guide will show you how to easily deploy software testers the needed test tools. This is just an example, please feel free to expand it!
After create a new PyCharm project (with virtualenv), create 2 new empty files (requirements.txt, ShowHeaders.py) and import a icon. You can found icons (*.icns) on iconarchive for free.
Open the “requirements.txt” file and add Requests library.
requests==2.6.0
Open the “ShowHeader.py” and add the following content.
For first test, run the application. If there are no issues – open the PyCharm terminal and run the following command.
$ py2applet --make-setup ShowHeaders.py
# or if you use virtualenv
$ /Users/<username>/ShowHeaderEnv/bin/py2applet --make-setup ShowHeaders.py
Now you should see the generated file “setup.py” in the Project. Open the file and add the icon. The content should look like this:
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ['ShowHeaders.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True, 'iconfile':'header.icns'}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
Now execute the following command to build, for first test.
$ python setup.py py2app -A
After some messages in terminal, your Project should show 2 new folders (build, dist). The alias mode (-A / –alias) instructs py2app to build an application, but it is not portable to other machines! You can open the Application in Finder or from terminal for your tests. If there are changes, just run the build-command again.
$ open dist/ShowHeaders.app
If everything is fine and your Application is ready for ship, run the following command.
After given the new name for the project on Location, select for Interpreter “Create VirtualEnv”.
Create Virtual Environment dialog box opens. Here type the name of the new virtual environment and specify the target directory for he new virtual environment on Location. Select one “Base interpreter” and if needed, select the check box “Inherit global site-packages”.
Press “OK” button to apply changes and close the dialog box. After press the “Create” button – PyCharm create the new project.
Mac OS X include Apache server and PHP, but since some version by default only at root level. To start the Apache on root level simple use the following commands.
After starting the Apache server, on browser you can use the URL “http://localhost”. You should see something like: “It Works”. The location for files is “/Library/WebServer/Documents/”.
Small note I have to apologize! The security policies of my provider do not allow the usage or combination for special words. Therefore, at various points images were used.
User level
Now we create the Apache on user level with a few configuration steps.
# Create folder (if not exists)
$ mkdir ~/Sites
Inside this folder create a simple PHP file (index.php)
<?php phpinfo(); ?>
In the third step, the configuration file of the user is created. The name always includes the user name!
$ cd /etc
$ vi /apache2/users/<username>.conf
Add the following content and save
<Directory "/Users/<username>/Sites/">
AllowOverride All
Options Indexes MultiViews FollowSymLinks
Require all granted
</Directory>
Check the access permissions for “-rw-r–r–” or “664”! To enable the configuration, open the “httpd-userdir.conf” and uncomment one line above <IfModule>.
$ cd /etc
$ sudo vi apache2/extra/httpd-userdir.conf
In the last step, only the correct modules must be loaded.
Now uncomment the LoadModule lines for “mod_userdir.so” and “libphp5.so” and include for user home.
Thats it! If you now start/restart the Apache and call the URL “http://localhost/~<username>/” in your browser, you should see the parsed content of PHP file.
On double-click the Mac OS X finder opens the default editor for script files. With the Automator you can very easy create services, which run these scripts. This example shows how to run python direct from finder.
Steps
Start Automator and select “Service”
The service should receive “Files and Folder” on “Finder”.
Now add from library “Run as Shellscript” with following content.
for f in "$@"
do
python "$f"
done
Now save your Automator workflow. The location should be automatically set to: “/Users/<user>/Library/Services”. Now select a python file, over the context menu or navigation item service, you can run it directly. My service is called “RunAsPython.
In software development, testers need to create a lot of documentation. Mac users can create very comfortable the documentation in PDF.
manpage to PDF
# Create PDF from manpage ping and open in Preview.app
$ man -t ping | open -f -a /Applications/Preview.app
Text to PDF
# Create PDF from text file
$ cupsfilter foo.txt > lorem.pdf 2> /dev/null
# Create PDF from text file and open in Preview.app
$ cupsfilter foo.txt 2>/dev/null | open -f -a /Applications/Preview.app
Image to PDF
# Create PDF from JPG
$ sips -s format pdf test.jpg --out test.pdf
Command’s to PDF
Many test steps would be carried out via command line and again later documented. This takes a lot of time and can lead to errors in documentations.
# Create file from history
$ history > history.txt
# Create PDF from history.txt
$ cupsfilter history.txt 2>/dev/null | open -f -a /Applications/Preview.app
PostScript to PDF
# Convert PostScript into PDF
$ pstopdf foo.ps
# Convert PostScript into PDF with specific name
$ pstopdf foo.ps -o bar.pdf