Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | # Copyright |
| 4 | |
| 5 | # DESCRIPTION |
| 6 | # This is script for running all selected toaster cases on |
| 7 | # selected web browsers manifested in toaster_test.cfg. |
| 8 | |
| 9 | # 1. How to start toaster in yocto: |
| 10 | # $ source poky/oe-init-build-env |
| 11 | # $ source toaster start |
| 12 | # $ bitbake core-image-minimal |
| 13 | |
| 14 | # 2. How to install selenium on Ubuntu: |
| 15 | # $ sudo apt-get install scrot python-pip |
| 16 | # $ sudo pip install selenium |
| 17 | |
| 18 | # 3. How to install selenium addon in firefox: |
| 19 | # Download the lastest firefox addon from http://release.seleniumhq.org/selenium-ide/ |
| 20 | # Then install it. You can also install firebug and firepath addon |
| 21 | |
| 22 | # 4. How to start writing a new case: |
| 23 | # All you need to do is to implement the function test_xxx() and pile it on. |
| 24 | |
| 25 | # 5. How to test with Chrome browser |
| 26 | # Download/install chrome on host |
| 27 | # Download chromedriver from https://code.google.com/p/chromedriver/downloads/list according to your host type |
| 28 | # put chromedriver in PATH, (e.g. /usr/bin/, bear in mind to chmod) |
| 29 | # For windows host, you may put chromedriver.exe in the same directory as chrome.exe |
| 30 | |
| 31 | |
| 32 | import unittest, time, re, sys, getopt, os, logging, platform |
| 33 | import ConfigParser |
| 34 | import subprocess |
| 35 | |
| 36 | |
| 37 | class toaster_run_all(): |
| 38 | def __init__(self): |
| 39 | # in case this script is called from other directory |
| 40 | os.chdir(os.path.abspath(sys.path[0])) |
| 41 | self.starttime = time.strptime(time.ctime()) |
| 42 | self.parser = ConfigParser.SafeConfigParser() |
| 43 | found = self.parser.read('toaster_test.cfg') |
| 44 | self.host_os = platform.system().lower() |
| 45 | self.run_all_cases() |
| 46 | self.collect_log() |
| 47 | |
| 48 | def get_test_cases(self): |
| 49 | # we have config groups for different os type in toaster_test.cfg |
| 50 | cases_to_run = eval(self.parser.get('toaster_test_' + self.host_os, 'test_cases')) |
| 51 | return cases_to_run |
| 52 | |
| 53 | |
| 54 | def run_all_cases(self): |
| 55 | cases_temp = self.get_test_cases() |
| 56 | for case in cases_temp: |
| 57 | single_case_cmd = "python -m unittest toaster_automation_test.toaster_cases.test_" + str(case) |
| 58 | print single_case_cmd |
| 59 | subprocess.call(single_case_cmd, shell=True) |
| 60 | |
| 61 | def collect_log(self): |
| 62 | """ |
| 63 | the log files are temporarily stored in ./log/tmp/.. |
| 64 | After all cases are done, they should be transfered to ./log/$TIMESTAMP/ |
| 65 | """ |
| 66 | def comple(number): |
| 67 | if number < 10: |
| 68 | return str(0) + str(number) |
| 69 | else: |
| 70 | return str(number) |
| 71 | now = self.starttime |
| 72 | now_str = comple(now.tm_year) + comple(now.tm_mon) + comple(now.tm_mday) + \ |
| 73 | comple(now.tm_hour) + comple(now.tm_min) + comple(now.tm_sec) |
| 74 | log_dir = os.path.abspath(sys.path[0]) + os.sep + 'log' + os.sep + now_str |
| 75 | log_tmp_dir = os.path.abspath(sys.path[0]) + os.sep + 'log' + os.sep + 'tmp' |
| 76 | try: |
| 77 | os.renames(log_tmp_dir, log_dir) |
| 78 | except OSError : |
| 79 | logging.error(" Cannot create log dir(timestamp) under log, please check your privilege") |
| 80 | |
| 81 | |
| 82 | if __name__ == "__main__": |
| 83 | toaster_run_all() |
| 84 | |
| 85 | |
| 86 | |
| 87 | |