Пример #1
0
    def test_search_conf_item(self):
        func_obj = ModuleUtils.search_conf_item(self.file_module, "function",
                                                "test1")
        self.assertEqual(func_obj(), "call test1 ok.")

        var_value = ModuleUtils.search_conf_item(self.file_module, "variable",
                                                 "var1")
        self.assertEqual(var_value, "value1")
Пример #2
0
    def test_filter_module(self):
        result = ModuleUtils.filter_module(self.MyTest, "function")
        self.assertIn("func1", result)
        self.assertIn("_func2", result)
        self.assertIn("func3", result)

        result = ModuleUtils.filter_module(self.MyTest, "variable")
        self.assertIn("var1", result)
        self.assertNotIn("_var2", result)
Пример #3
0
    def test_is_variable(self):
        is_vars = {"username": "******", "password": 123456}
        not_vars = {"_unknow": "", "object": self.MyTest, "module": os}

        for k, v in is_vars.items():
            self.assertEqual(ModuleUtils.is_variable((k, v)), True)

        for k, v in not_vars.items():
            self.assertEqual(ModuleUtils.is_variable((k, v)), False)
Пример #4
0
    def test_filter_module_from_file(self):
        module = ModuleUtils.get_imported_module_from_file(self.file_module)

        result = ModuleUtils.filter_module(module, "function")
        self.assertIn("test1", result)
        self.assertIn("test2", result)
        self.assertIn("_test3", result)

        result = ModuleUtils.filter_module(module, "variable")
        self.assertIn("var1", result)
        self.assertNotIn("_var2", result)
Пример #5
0
 def test_WebAction_rtsf(self):  
     Actions = ModuleUtils.get_imported_module("webuidriver.actions")
     Actions.Web.driver = self.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)  
     self.assertNotEqual(functions, {})        
     
     print(functions)
     functions.get("NavigateTo")("http://www.baidu.com")
     functions.get("SetControl")(by = 'id', value = "kw")
     functions.get("SendKeys")(123456)
     time.sleep(1)
     functions.get("WebClose")()
     functions.get("WebQuit")()
Пример #6
0
    def test_AppActions_rtsf(self):
        Actions = ModuleUtils.get_imported_module("appuidriver.actions")
        Actions.App.driver = App.driver

        functions = {}
        app_functions = ModuleUtils.get_callable_class_method_names(
            Actions.App)
        app_element_functions = ModuleUtils.get_callable_class_method_names(
            Actions.AppElement)
        app_context_functions = ModuleUtils.get_callable_class_method_names(
            Actions.AppContext)
        app_wait_functions = ModuleUtils.get_callable_class_method_names(
            Actions.AppWait)
        app_verify_functions = ModuleUtils.get_callable_class_method_names(
            Actions.AppVerify)
        app_touch_action_functions = ModuleUtils.get_callable_class_method_names(
            Actions.AppTouchAction)
        app_actions_functions = ModuleUtils.get_callable_class_method_names(
            Actions.AppActions)
        functions.update(app_functions)
        functions.update(app_element_functions)
        functions.update(app_context_functions)
        functions.update(app_wait_functions)
        functions.update(app_verify_functions)
        functions.update(app_touch_action_functions)
        functions.update(app_actions_functions)
        self.assertNotEqual(functions, {})

        print(functions)
        functions.get("StartActivity")('io.appium.android.apis',
                                       '.view.Controls1')
        functions.get("SetControl")(by='id',
                                    value='io.appium.android.apis:id/edit')
        functions.get("SendKeys")(u'你好    appium')
        functions.get("TimeSleep")(1)
        functions.get("CloseApp")()
Пример #7
0
    def _get_bind_item(self, item_type, item_name):

        if item_type == "function":
            if item_name in self._functions:
                return self._functions[item_name]
            else:
                # is not keyword function, continue to search
                pass
        elif item_type == "variable":
            if item_name in self._variables:
                return self._variables[item_name]
        else:
            raise p_exception.ParamsError(
                "bind item should only be function or variable.")

        try:
            # preference functions
            assert self.file_path is not None
            return ModuleUtils.search_conf_item(self.file_path, item_type,
                                                item_name)
        except (AssertionError, p_exception.FunctionNotFound):
            raise p_exception.ParamsError(
                "{} is not defined in bind {}s!".format(item_name, item_type))
Пример #8
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         
Пример #9
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()
Пример #10
0
    def test_get_imported_module_from_file(self):  #

        module = ModuleUtils.get_imported_module_from_file(self.file_module)
        self.assertEqual(isinstance(module, types.ModuleType), True)
Пример #11
0
    def test_get_imported_module(self):
        module = ModuleUtils.get_imported_module("logging")

        self.assertEqual(isinstance(module, types.ModuleType), True)
Пример #12
0
    def test_is_function(self):
        funcs = ModuleUtils.get_callable_class_method_names(self.MyTest)

        for k, v in funcs.items():
            self.assertEqual(ModuleUtils.is_function((k, v)), True)
Пример #13
0
    def test_get_callable_class_method_names(self):
        funcs = ModuleUtils.get_callable_class_method_names(self.MyTest)

        self.assertIn("func1", funcs)
        self.assertNotIn("_func2", funcs)
        self.assertIn("func3", funcs)
Пример #14
0
    def run_test(self, testcase_dict, variables, driver_map):
        fn, fn_driver = driver_map
        parser = self.parser
        tracer = self.tracers[fn]
        if not self.__has_trace:
            tracer._switch_off()

        _Actions = ModuleUtils.get_imported_module("httpdriver.actions")
        _Actions.Request.session = fn_driver
        parser.bind_functions(
            ModuleUtils.get_callable_class_method_names(_Actions.Request))

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

        case_name = 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.Request.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.Request.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:
                if not "request" in step:
                    continue

                raw_requests = step["request"].copy()
                parsered_requests = parser.eval_content_with_bind_actions(
                    raw_requests)

                url = parsered_requests.pop("url")
                method = parsered_requests.pop("method")
                if not method.capitalize() in ("Get", "Post"):
                    raise FunctionNotFound("Not found method('%s')" % method)

                tracer.step("requests url: \n\t{} {}".format(
                    method.capitalize(), url))
                req = parser.get_bind_function(method.capitalize())

                for k, v in parsered_requests.items():
                    tracer.step("requests {} -> \n\t{}".format(
                        k, json.dumps(v, indent=4, separators=(',', ': '))))

                #resp = req(url, **parsered_requests)
                req_track_obj = self._request(req, url, **parsered_requests)
                resp_info = req_track_obj.trackinfo

                tracer.step("response headers: \n\t{}".format(
                    json.dumps(dict(resp_info["response_headers"]),
                               indent=4,
                               separators=(',', ': '))))
                tracer.step(u"response body: \n\t{}".format(
                    Markup(resp_info["response_body"]).unescape()))

            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)

            self._verify(zip(verify, result), tracer, req_track_obj.response)

        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()