Exemple #1
0
    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']))
Exemple #2
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)
Exemple #3
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)))            
Exemple #4
0
    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
Exemple #5
0
    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)))
Exemple #6
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         
Exemple #7
0
    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()
Exemple #8
0
 def test_get_legal_filename(self):
     self.assertEqual(FileSystemUtils.get_legal_filename("你好&-|他*"),
                      '你好&-他')
     self.assertEqual(FileSystemUtils.get_legal_filename("\n你好&-|他*"),
                      '你好&-他')