The UI Tests should be run automatically. We need to run them automatically, on demand or in given moment in time. A good practice is to create a batch file for running them. This file could be run manually or in part of integrated system or even with Task Scheduler in given time.Sample code for the batch file for running Sikuli UI Tests is:
@echo on
rem the path to the project with test list and tests
set ProjectPath="C:\Work\Tests\ReportingTests"
rem generated the path to the test list
set TestList="%ProjectPath%\TestSuite.sikuli"
rem path to the “Sikuli-IDE” file, which will run the sikuli files
set TestRunner="C:\SikuliX\Sikuli-IDE.bat"
rem run the test-list with the tests
call %TestRunner% -r %TestList%
In the test list we should add a code for integration with HTMLTestRunner. First we need to add a method for creating a new instance of HTMLTestRunner with the correct data and run the test for the given test suite:
def RunSuite(testCase):
#Open the file for the test results
outfile = open("C:\\Results\\Results.html", "w")
#Creating an instance of HTMLTestRunner for the current test list
runner = HTMLTestRunner.HTMLTestRunner(stream=outfile, title=‘UI
Tests’, description=‘Suite with all tests’)
#Starting the tests for the given given test suit
runner.run(suite)
Now at the end of the test list we need to create a test suit with the tests and to call the method for running them:
#Import the package with the test
import UITests
#Creating a variable with the tests
testCaseForUITests=UITests.FirstUITests.FirstUITests
#Creating a new instance of test suite
suite=unittest.TestSuite()
#Add the test to the new test suit
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(testCaseForUITests))
#Call the created method for funning the tests
RunSuite()
After the test are executed the test results are going to be generated in the file that we have specify. When the test are generated we could send them by Email or post somewhere to analyze them.