コード例 #1
0
ファイル: p_report.py プロジェクト: RockFeng0/rtsf
 def __get_log_file(self):
     log_file_name = u"%s_%s.log" % (self.meta_data['case_name'],
                                     DateTimeUtils.get_stamp_date())
     log_file = os.path.join(self.case_log_path, log_file_name)
     if not os.path.isfile(log_file):
         FileSystemUtils.mkdirs(self.case_log_path)
     return log_file
コード例 #2
0
ファイル: p_report.py プロジェクト: RockFeng0/rtsf
    def start_test(self, module_name, case_name, resp_tester, tester):
        '''
        @param module_name: test set name or test module name
        @param case_name: normal text case name, may contain '@#$~%^(+=-)&* ...'
        @param resp_tester: name of responsible tester
        @param tester: name of tester who run this case  
        '''
        self.meta_data = {
            "module_name": module_name,
            "raw_case_name": case_name,
            "case_name": FileSystemUtils.get_legal_filename(case_name),
            "status": "pass",
            "resp_tester": resp_tester,
            "tester": tester,
            "start_at": time.time(),
            "end_at": "",
        }

        FileSystemUtils.mkdirs(self.case_log_path)
        #         FileSystemUtils.mkdirs(self.screen_shot_path)

        log_file = self.__get_log_file()
        with codecs.open(log_file, "a", "utf-8") as f:
            f.write(u"\n**************  %s [%s]  ***************\n" %
                    (u"Case Log From Rock4 Test Service Framework",
                     self.meta_data['case_name']))
コード例 #3
0
ファイル: test_p_common.py プロジェクト: RockFeng0/rtsf
    def test_mkzip(self):
        p = os.path.join(self.results_path, "testcase")
        t = os.path.join(self.results_path, "testcase.zip")
        ZipUtils.mkzip(p, t)

        self.assertEqual(os.path.isfile(t), True)
        FileSystemUtils.force_delete_file(t)
コード例 #4
0
ファイル: test_p_common.py プロジェクト: RockFeng0/rtsf
    def test_getFileSize(self):
        f = os.path.join(self.results_path, 'md5test.txt')
        with open(f, 'w') as fn:
            fn.write(u"千山鸟飞绝,万径人踪灭")

        self.assertEqual(FileSystemUtils.getFileSize(f), 22)
        FileSystemUtils.force_delete_file(f)
コード例 #5
0
ファイル: test_p_common.py プロジェクト: RockFeng0/rtsf
    def test_add_unique_postfix(self):
        f = os.path.join(self.results_path, 'md5test.txt')
        with open(f, 'w') as fn:
            fn.write(u"千山鸟飞绝,万径人踪灭")

        self.assertNotEqual(FileSystemUtils.add_unique_postfix(f),
                            'md5test_2.txt')
        FileSystemUtils.force_delete_file(f)
コード例 #6
0
ファイル: test_p_common.py プロジェクト: RockFeng0/rtsf
    def test_getFileMd5(self):
        f = os.path.join(self.results_path, 'md5test.txt')
        with open(f, 'w') as fn:
            fn.write(u"千山鸟飞绝,万径人踪灭")

        self.assertEqual(FileSystemUtils.getFileMd5(f),
                         "92e5a625b232d4c52ceb9d9330e02e44")
        FileSystemUtils.force_delete_file(f)
コード例 #7
0
ファイル: test_p_common.py プロジェクト: RockFeng0/rtsf
    def test_unzip(self):
        p = os.path.join(self.results_path, "testcase")
        fzip = os.path.join(self.results_path, "testcase.zip")
        ZipUtils.mkzip(p, fzip)

        t = os.path.join(self.results_path, "test-unzip")
        ZipUtils.unzip(fzip, t)

        self.assertEqual(os.path.isfile(fzip), True)
        self.assertEqual(os.path.isdir(t), True)

        FileSystemUtils.force_delete_file(fzip)
        shutil.rmtree(t)
コード例 #8
0
    def test_init_test_suite_from_dir(self):
        cases_path = r'test_tmp\testcases'
        p1 = os.path.join(cases_path, "t1")
        p2 = os.path.join(cases_path, "t2")

        FileSystemUtils.mkdirs(p1)
        FileSystemUtils.mkdirs(p2)
        shutil.copyfile(self.case, os.path.join(cases_path, "t.yaml"))
        shutil.copyfile(self.case, os.path.join(p1, "t1.yaml"))
        shutil.copyfile(self.case, os.path.join(p2, "t2.yaml"))

        task_obj = init_test_suite(cases_path, Runner)

        self.assertEqual(isinstance(task_obj, TaskSuite), True)
        self.assertEqual(len(task_obj.tasks), 3)
コード例 #9
0
    def translate(self):
        ''' usage:
            m = YamlCaseLoader(r"D:\auto\buffer\test.yaml")
            for i in m.translate():print(i)
        :return iterator (case_name, execute_function)
        
        @note:  this method is useless
        '''
        if not self.check():
            return

        for idx in range(len(self.testcases)):
            testing = self.testcases[idx]
            case_id = testing.get("testcaseid")
            case_name = FileSystemUtils.get_legal_filename(
                "%s[%s]" %
                (case_id, p_compat.str(testing[self.__case_title_field])))

            # executer actions
            execute_actionss = []
            for field in self.__executer_seq_fields:
                steps_info = testing.get(field)
                for execute_function in steps_info:
                    if not execute_function:
                        continue
                    execute_actionss.append(execute_function)
            yield (case_name, execute_actionss, idx)
コード例 #10
0
    def test_load_files_from_dir(self):
        # file path.
        cases_path = r'test_tmp\testcases'
        p1 = os.path.join(cases_path, "t1")
        p2 = os.path.join(cases_path, "t2")

        FileSystemUtils.mkdirs(p1)
        FileSystemUtils.mkdirs(p2)
        shutil.copyfile(self.case, os.path.join(cases_path, "t.yaml"))
        shutil.copyfile(self.case, os.path.join(p1, "t1.yaml"))
        shutil.copyfile(self.case, os.path.join(p2, "t2.yaml"))

        cases = YamlCaseLoader.load_files(cases_path)
        self.assertEqual(len(cases), 3)

        all_cases_file_name = [
            os.path.basename(case["file_path"]) for case in cases
        ]
コード例 #11
0
ファイル: test_p_common.py プロジェクト: RockFeng0/rtsf
    def test_load_folder_files(self):

        cases_path = r'test_tmp\testcases'
        p1 = os.path.join(cases_path, "t1")
        p2 = os.path.join(cases_path, "t2")

        FileSystemUtils.mkdirs(p1)
        FileSystemUtils.mkdirs(p2)
        shutil.copyfile(self.case, os.path.join(cases_path, "t.yaml"))
        shutil.copyfile(self.case, os.path.join(p1, "t1.yaml"))
        shutil.copyfile(self.case, os.path.join(p2, "t2.yaml"))

        result1 = FileUtils.load_folder_files(p1, recursive=False)
        self.assertEqual(len(result1), 1)

        result2 = FileUtils.load_folder_files(cases_path, recursive=True)
        self.assertEqual(len(result2), 3)

        result3 = FileUtils.load_file(self.csv)
        self.assertIsInstance(result3, list)
        self.assertIsInstance(result3[0], dict)
コード例 #12
0
ファイル: test_p_common.py プロジェクト: RockFeng0/rtsf
    def test_get_value_from_cfg(self):
        results_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                    "test_tmp")
        fn = os.path.join(results_path, "test.conf")
        with open(fn, 'w') as f:
            f.write("""
[device-1]
dut_ip = 192.168.1.1
user = admin
passwd = 123456

[device-2]
dut_ip = 192.168.1.2
user = admin
passwd = 123456
 
            """)

        conf = CommonUtils.get_value_from_cfg(fn)
        self.assertEqual(conf["device-1"]["dut_ip"], "192.168.1.1")
        self.assertEqual(conf["device-2"]["passwd"], "123456")
        FileSystemUtils.force_delete_file(fn)
コード例 #13
0
 def __init__(self):
     super(RemoteDriver, self).__init__(is_local_driver=False)
             
     self._default_devices = []
     
     self._default_drivers = []        
     executors = SeleniumHatch.get_remote_executors(RemoteDriver._remote_ip, RemoteDriver._remote_port)
     chrome_capabilities = SeleniumHatch.get_remote_browser_capabilities(browser=RemoteDriver._browser,
                                                                         download_path=RemoteDriver._download_path,
                                                                         marionette=RemoteDriver._marionette)
     for executor in executors:
         fn = FileSystemUtils.get_legal_filename(executor)
         self._default_devices.append(fn)            
         self._default_drivers.append((fn, SeleniumHatch.gen_remote_driver(executor, chrome_capabilities)))            
コード例 #14
0
ファイル: p_report.py プロジェクト: RockFeng0/rtsf
    def generate_html_report(self, proj_name, proj_module=None):
        html_results = []
        all_summary = HtmlReporter.get_summary(self.summary,
                                               proj_name=proj_name)

        for summary in all_summary:
            html_report = os.path.join(
                self.result_path, u"[{}]{}_{}.html".format(
                    FileSystemUtils.get_legal_filename(
                        summary["project_name"]),
                    FileSystemUtils.get_legal_filename(summary["module_name"]),
                    DateTimeUtils.get_stamp_datetime_coherent(),
                ))
            if proj_module == None:
                html_results.append(
                    HtmlReporter.render_html(html_report, summary))

            elif summary["module_name"] == proj_module:
                html_results.append(
                    HtmlReporter.render_html(html_report, summary))
                break
            else:
                summary = {}
        return html_results
コード例 #15
0
ファイル: driver.py プロジェクト: RockFeng0/rtsf-app
    def __init__(self):
        super(RemoteDriver, self).__init__(is_local_driver=False)
        desired_cap = Android.gen_capabilities(
            apk_abs_path=RemoteDriver._apk_abs_path,
            app_package=RemoteDriver._app_package,
            app_activity=RemoteDriver._app_activity,
            aapt_exe_4path=RemoteDriver._aapt_exe_path)
        self._default_devices = []
        self._default_drivers = []
        executors = Android.get_remote_executors(
            hub_ip=RemoteDriver._remote_ip, port=RemoteDriver._remote_port)
        for udid, udversion, executor in executors:
            fn = FileSystemUtils.get_legal_filename(executor)
            self._default_devices.append(fn)

            cap = desired_cap.copy()
            cap["deviceName"] = udid
            cap["platformVersion"] = udversion
            self._default_drivers.append(
                (fn,
                 Android.gen_remote_driver(executor=executor,
                                           capabilities=cap)))
コード例 #16
0
 def run_test(self, testcase_dict, variables, driver_map):
     fn, fn_driver = driver_map        
     parser = self.parser        
     tracer = self.tracers[fn]
     
     _Actions = ModuleUtils.get_imported_module("webuidriver.actions")
     _Actions.Web.driver = fn_driver
     
     functions = {}
     web_functions = ModuleUtils.get_callable_class_method_names(_Actions.Web)
     web_element_functions = ModuleUtils.get_callable_class_method_names(_Actions.WebElement)
     web_context_functions = ModuleUtils.get_callable_class_method_names(_Actions.WebContext)
     web_wait_functions = ModuleUtils.get_callable_class_method_names(_Actions.WebWait)
     web_verify_functions = ModuleUtils.get_callable_class_method_names(_Actions.WebVerify)
     web_actions_functions = ModuleUtils.get_callable_class_method_names(_Actions.WebActions)
     functions.update(web_functions)
     functions.update(web_element_functions)
     functions.update(web_context_functions)
     functions.update(web_wait_functions)
     functions.update(web_verify_functions)
     functions.update(web_actions_functions)   
     parser.bind_functions(functions)
     
     _Actions.WebContext.glob.update(variables)
     parser.update_binded_variables(_Actions.WebContext.glob)        
     
     case_name = FileSystemUtils.get_legal_filename(parser.eval_content_with_bind_actions(testcase_dict["name"]))
     tracer.start(self.proj_info["module"], case_name, testcase_dict.get("responsible","Administrator"), testcase_dict.get("tester","Administrator"))        
     tracer.section(case_name)
     
     try:
         tracer.normal("**** bind glob variables")                
         glob_vars = parser.eval_content_with_bind_actions(testcase_dict.get("glob_var",{}))
         tracer.step("set global variables: {}".format(glob_vars))                
         _Actions.WebContext.glob.update(glob_vars)            
          
         tracer.normal("**** bind glob regular expression")
         globregx = {k: re.compile(v) for k,v in testcase_dict.get("glob_regx",{}).items()}
         tracer.step("set global regular: {}".format(globregx))            
         _Actions.WebContext.glob.update(globregx)
                          
         tracer.normal("**** precommand")
         precommand = testcase_dict.get("pre_command",[])    
         parser.eval_content_with_bind_actions(precommand)
         for i in precommand:
             tracer.step("{}".format(i))
          
         tracer.normal("**** steps")
         steps = testcase_dict["steps"]
         for step in steps:
             #print("---")            
             if not "webdriver" in step:
                 continue
             
             if not step["webdriver"].get("action"):
                 raise KeyError("webdriver.action")            
             
             #print(step)
             if step["webdriver"].get("by"):
                 by = parser.eval_content_with_bind_actions(step["webdriver"].get("by"))
                 tracer.normal("preparing: by -> {}".format(by))
                 
                 value = parser.eval_content_with_bind_actions(step["webdriver"].get("value"))
                 tracer.normal("preparing: value -> {}".format(value))
                 
                 index = parser.eval_content_with_bind_actions(step["webdriver"].get("index", 0))
                 tracer.normal("preparing: index -> {}".format(index))
                 
                 timeout = parser.eval_content_with_bind_actions(step["webdriver"].get("timeout", 10))
                 tracer.normal("preparing: timeout -> {}".format(timeout))                           
             
                 prepare =parser.get_bind_function("SetControl")
                 prepare(by = by, value = value, index = index, timeout = timeout)
                             
             result = parser.eval_content_with_bind_actions(step["webdriver"]["action"])
             #print(":",result)           
             if result == False:
                 tracer.fail(step["webdriver"]["action"])
             else:
                 tracer.ok(step["webdriver"]["action"])
                     
         tracer.normal("**** postcommand")
         postcommand = testcase_dict.get("post_command", [])        
         parser.eval_content_with_bind_actions(postcommand)
         for i in postcommand:
             tracer.step("{}".format(i))
         
         tracer.normal("**** verify")
         verify = testcase_dict.get("verify",[])
         result = parser.eval_content_with_bind_actions(verify)
         for v, r in zip(verify,result):
             if r == False:
                 tracer.fail(u"{} --> {}".format(v,r))
             else:
                 tracer.ok(u"{} --> {}".format(v,r))
                     
     except KeyError as e:
         tracer.error("Can't find key[%s] in your testcase." %e)
     except FunctionNotFound as e:
         tracer.error(e)
     except VariableNotFound as e:
         tracer.error(e)
     except Exception as e:
         tracer.error("%s\t%s" %(e,CommonUtils.get_exception_error()))
     finally:
         #tracer.normal("globals:\n\t{}".format(parser._variables)) 
         tracer.stop()
     return tracer         
コード例 #17
0
ファイル: driver.py プロジェクト: RockFeng0/rtsf-win
    def run_test(self, testcase_dict, variables, driver_map):
        fn, _ = driver_map
        tracer = self.tracers[fn]
        parser = self.parser

        functions = {}
        _Actions = ModuleUtils.get_imported_module("winuidriver.actions")

        win_actions_functions = ModuleUtils.get_callable_class_method_names(
            _Actions.WinActions)
        win_context_functions = ModuleUtils.get_callable_class_method_names(
            _Actions.WinContext)
        win_element_functions = ModuleUtils.get_callable_class_method_names(
            _Actions.WinElement)
        win_verify_functions = ModuleUtils.get_callable_class_method_names(
            _Actions.WinVerify)
        win_wait_functions = ModuleUtils.get_callable_class_method_names(
            _Actions.WinWait)

        functions.update(win_actions_functions)
        functions.update(win_context_functions)
        functions.update(win_element_functions)
        functions.update(win_verify_functions)
        functions.update(win_wait_functions)
        parser.bind_functions(functions)

        _Actions.WinContext.glob.update(variables)
        parser.update_binded_variables(_Actions.WinContext.glob)

        case_name = FileSystemUtils.get_legal_filename(
            parser.eval_content_with_bind_actions(testcase_dict["name"]))
        tracer.start(self.proj_info["module"], case_name,
                     testcase_dict.get("responsible", "Administrator"),
                     testcase_dict.get("tester", "Administrator"))
        tracer.section(case_name)

        try:
            tracer.normal("**** bind glob variables")
            glob_vars = parser.eval_content_with_bind_actions(
                testcase_dict.get("glob_var", {}))
            tracer.step("set global variables: {}".format(glob_vars))
            _Actions.WinContext.glob.update(glob_vars)

            tracer.normal("**** bind glob regular expression")
            globregx = {
                k: re.compile(v)
                for k, v in testcase_dict.get("glob_regx", {}).items()
            }
            tracer.step("set global regular: {}".format(globregx))
            _Actions.WinContext.glob.update(globregx)

            tracer.normal("**** precommand")
            precommand = testcase_dict.get("pre_command", [])
            parser.eval_content_with_bind_actions(precommand)
            for i in precommand:
                tracer.step("{}".format(i))

            tracer.normal("**** steps")
            steps = testcase_dict["steps"]
            for step in steps:
                #print("---")
                if not "windriver" in step:
                    continue

                if not step["windriver"].get("action"):
                    raise KeyError("windriver.action")

                #print(step)
                _properties = ("ControlType", "ClassName", "AutomationId",
                               "Name", "SubName", "RegexName", "Depth")
                properties = {
                    prop: parser.eval_content_with_bind_actions(
                        step["windriver"].get(prop))
                    for prop in _properties if step["windriver"].get(prop)
                }
                if properties:
                    properties.update({
                        "index":
                        parser.eval_content_with_bind_actions(
                            step["windriver"].get("index", 0))
                    })
                    properties.update({
                        "timeout":
                        parser.eval_content_with_bind_actions(
                            step["windriver"].get("timeout", 10))
                    })
                    tracer.normal(
                        "preparing: properties -> {}".format(properties))

                    prepare = parser.get_bind_function("SetSearchProperty")
                    prepare(**properties)

                result = parser.eval_content_with_bind_actions(
                    step["windriver"]["action"])

                if result == False:
                    tracer.fail(step["windriver"]["action"])
                else:
                    tracer.ok(step["windriver"]["action"])

            tracer.normal("**** postcommand")
            postcommand = testcase_dict.get("post_command", [])
            parser.eval_content_with_bind_actions(postcommand)
            for i in postcommand:
                tracer.step("{}".format(i))

            tracer.normal("**** verify")
            verify = testcase_dict.get("verify", [])
            result = parser.eval_content_with_bind_actions(verify)
            for v, r in zip(verify, result):
                if r == False:
                    tracer.fail(u"{} --> {}".format(v, r))
                else:
                    tracer.ok(u"{} --> {}".format(v, r))

        except KeyError as e:
            tracer.error("Can't find key[%s] in your testcase." % e)
            print(CommonUtils.get_exception_error())
        except FunctionNotFound as e:
            tracer.error(e)
        except VariableNotFound as e:
            tracer.error(e)
        except Exception as e:
            tracer.error("%s\t%s" % (e, CommonUtils.get_exception_error()))
        finally:
            #tracer.normal("globals:\n\t{}".format(parser._variables))
            tracer.stop()
コード例 #18
0
ファイル: test_p_common.py プロジェクト: RockFeng0/rtsf
 def tearDown(self):
     FileSystemUtils.force_delete_file(self.file_module)
コード例 #19
0
ファイル: test_p_common.py プロジェクト: RockFeng0/rtsf
 def test_get_legal_filename(self):
     self.assertEqual(FileSystemUtils.get_legal_filename("你好&-|他*"),
                      '你好&-他')
     self.assertEqual(FileSystemUtils.get_legal_filename("\n你好&-|他*"),
                      '你好&-他')
コード例 #20
0
ファイル: test_p_common.py プロジェクト: RockFeng0/rtsf
 def test_mkdirs(self):
     p = os.path.join(self.results_path, 't1', 't2', 't3')
     FileSystemUtils.mkdirs(p)
     self.assertEqual(os.path.isdir(p), True)
     shutil.rmtree(p)