Friday, April 22, 2016

Make UnitTest Report Using HTMLTestRunner

I am a big fan of Python, and I am a big fan of TDD (Test Driven Development). The problem that I face for team development was that it is quite difficult to communicate the testing results to the team, because the results are in terminal so only us and God know :D

Fortunately, somebody out there know my problem and create this amazing HTMLTestRunner.py. This tool is very handy and very easy to use. It almost feels like you don't need to do anything. OK, here's one example on how we use HTMLTestRunner. Ah, forget it. Download HTMLTestRunner.py from this website, and put somewhere in your computer. Say in this example, I put in ~/Downloads/HTMLTestRunner folder

import unittest
import sys
_path = r"Downloads/HTMLTestRunner"
sys.path.append(_path)
import HTMLTestRunner

class TestDemo(unittest.TestCase):
    def testA(self):
        assert True
    def testB(self):
        assert False

class TestDemo2(unittest.TestCase):
    def testC(self):
        assert True
    def testD(self):
        assert True

def suite():
    suite = unittest.TestSuite()
    # TestDemo
    suite.addTest(TestDemo('testA'))
    suite.addTest(TestDemo('testB'))
    # TestDemo2
    suite.addTest(TestDemo2('testC'))
    suite.addTest(TestDemo2('testD'))

    return suite

if __name__ == "__main__":
    suite = suite()
    unittest.TextTestRunner(verbosity=2)
    output = open("results.html", 'w')
    runner = HTMLTestRunner.HTMLTestRunner(stream=output, title='Test Report', description='This is a test')
    runner.run(suite)

After you run it, boom... you will get a beautiful and informative report in html file. Here is the results in my example:

Thursday, April 21, 2016

Import Python Script to SikuliX

When we need to import python script into sikulix workspace, here is one of the way to do:

1. Import sys
2. Append the path to the script into sys.path
3. Import your python script

Here is an example

import sys

sys.path.append("/Users/arwankhoiruddin/Downloads/python_packages/HTMLTestRunner")

import HTMLTestRunner

However, it has some limitations. You should refer to this document: https://answers.launchpad.net/sikuli/+faq/1114

Monday, April 11, 2016

Get Operating System used by SikuliX

If we write SikuliX code to check app on different operating system, we may need to define characteristic for each OS (e.g. image library or specific code). To check it, we can use built-in SikuliX script. Following is an example of OS checking

if Settings.isWindows():
    print "I am running on Windows"
elif Settings.isLinux():
    print "I am running on Linux"
elif Settings.isMac():
    print "I am running on Mac"

That's it. Hope it helps.