UI Automation test under Mac (iv)

Source: Internet
Author: User
Tags sikuli xunit

The UnitTest framework is used when the testcase is actually written, but it needs to be run in Sikuli with the command it provides, located /Applications/sikulix.app/run, using The- r parameter specifies the Sikuli file to run, and then uses the --args parameter to append the parameters you want to pass to the Sikuli file:

sudo file file] cases:[caseID list] build:[build_id]

and in order to be able to output the HTML test report directly, using the Htmltestrunner to run a testsuite with the following code:

1 ImportSYS2 ImportOS3 ImportRe4 ImportUnitTest5 6Lib = Os.path.join (Os.path.expanduser ("~"),"Mac_auto")7 ifLib not inchSys.path:8 Sys.path.append (Lib)9 Ten  fromGlobal_configImport* One  A ifPath_of_site_packages not inchSys.path: - sys.path.append (path_of_site_packages) -  the  fromHtmloutput.html_test_runnerImportHtmltestrunner -  -Report_file =None -Test_case_ids =None +Build =None -  forArginchSys.argv[1:]: +     ifArg.startswith ("Report :"): AReport_file = Arg.split (":") [1] at         Print "test result file is"+Report_file -     ifArg.startswith ("cases:"): -Test_case_ids = Arg.split (":") [1].split (",") -     ifArg.startswith ("Build:"): -Build = Arg.split (":") [1] -  in #It ' ll load all test CAEs in current folder if No. test case indicated - ifTest_case_ids isNoneorLen (test_case_ids) = =0: to     Print "Loading All test Cases in current folder" +Test_case_module_names = [Re.sub ("\.sikuli$",""I forIinchOs.listdir ( -Os.path.join (Test_home_path,"testcases"))ifI.startswith ("Test_case")] the Else: *Test_case_module_names = ["test_case_{0}". Format (i) forIinchTest_case_ids] $ Panax NotoginsengTest_case_modules = [] -  forIinchTest_case_module_names: the     Print "Importing Module"+I +Test_case_modules.append (__import__(I, Globals (), locals (), [], 1)) A  theSuite =None + ifLen (test_case_modules) >= 1: -Suite =UnitTest. Testloader (). Loadtestsfrommodule (Test_case_modules[0]) $  forMinchTest_case_modules[1:]: $ suite.addtests (unittest. Testloader (). Loadtestsfrommodule (m)) -  -outfile = open (Report_file,"W") theRunner = Htmltestrunner (Stream=outfile, verbosity=2, title='OSX Test Report', build=build) - Wuyi Print "Start running Test" theRunner.run (Suite)

The above code will search for the Sikuli file that starts with Test_case in the Testcases directory and dynamically import it to run in Testloader.

Also made a change to the htmltestrunner, so that it can output the specified build information.

Enter the following command on the command line, run all the test cases in the Testcases directory, and output the results to test_result.html:

sudo /applications/sikulix.app/run-r testcases/runner_html.sikuli--args report:test_result.html Build: your_build_id

The output HTML displays the following information:

Python has an excellent test tool called nose, which expands the functionality of UnitTest to make it easier to use, and we can mark our nose with TestMethod tags on testcase sikuli written, Then use Nose.core.run to run the test in the Sikuli file with the following code:

1 ImportSYS2 ImportOS3 4Lib = Os.path.join (Os.path.expanduser ("~"),"Mac_auto")5 ifLib not inchSys.path:6 Sys.path.append (Lib)7 ImportGlobal_config8 9 ifGlobal_config.path_of_site_packages not inchSys.path:Ten sys.path.append (global_config.path_of_site_packages) One ImportNose A  fromHtmloutput.html_for_noseImportHtmloutput -  -Build =None the  forArginchSys.argv[1:]: -     ifArg.startswith ("--build="): -Build = Arg.split ("=") [1] - Sys.argv.remove (ARG) +  -args = Sys.argv[1:] + Printargs A  atNose.core.run (Argv=args, Addplugins=[htmloutput (title='OSX Test Report', Build=build)])

The default nose output is a xunit testresult that can be conveniently parsed on Jenkins. Here I add a nose plugin, so that it can output HTML test results, using a modified version of htmltestrunner.py, located on GitHub here:

https://github.com/openstack-infra/nose-html-output/blob/master/htmloutput/htmloutput.py

Save the above code as a Sikuli file named Runner_nose.sikuli, and then run all the tests marked BVT with the following command:

sudo /applications/sikulix.app/run-r testcases/runner_nose.sikuli--args-v--with-xunit--xunit-file =result.xml--ATTR=BVT--build=your_build_id

The output is a xunit test result, or you can use the following command to output an HTML result:

sudo /applications/sikulix.app/run-r testcases/runner_nose.sikuli--args-v--with-html-output--html-out- file=result.html--attr=bvt--build=your_build_id

UI Automation test under Mac (iv)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.