diff --git a/flybirds/core/dsl/globalization/i18n.py b/flybirds/core/dsl/globalization/i18n.py index 3890bad..f91d9fd 100644 --- a/flybirds/core/dsl/globalization/i18n.py +++ b/flybirds/core/dsl/globalization/i18n.py @@ -266,7 +266,10 @@ "the [{param}] contained by the element [{selector}] has attribute [{attr_name}] not contain value [{" "attr_value}]": ["包含参数[{param}]的元素[{selector}]的属性[{attr_name}]值不包含[{attr_value}]"], + "the [{param}] contained by the element [{selector}] element value is [{attr_value}]": + ["包含参数[{param}]的元素[{selector}]的value为[{attr_value}]"], "click[{selector}] and accept dialog": ["点击[{selector}]并接受弹窗"], "click[{selector}] and cancel dialog": ["点击[{selector}]并取消弹窗"], + "upload image to element[{selector}]": ["上传图片到元素[{selector}]"] }, } diff --git a/flybirds/core/dsl/step/element.py b/flybirds/core/dsl/step/element.py index fae3792..0f548e7 100644 --- a/flybirds/core/dsl/step/element.py +++ b/flybirds/core/dsl/step/element.py @@ -815,6 +815,27 @@ def ele_contain_param_attr_exist(context, param=None, selector=None, attr_name=N g_Context.step.ele_contain_param_attr_exist(context, param, selector, attr_name, attr_value) +@step("the [{param}] contained by the element [{selector}] element value is [{attr_value}]") +@FlybirdsReportTagInfo(group="element", selectors={ + "path": [{"type": "text", "value": "param", "name": "文本"}, + {"type": "path", "value": "selector", "name": "元素"}]}, + verify={"type": ErrorFlag.text_equ, "value": "attr_value"}, + verify_function="ele_verify_text_error_parse") +@VerifyStep() +@ele_wrap +def ele_contain_param_attr_exist(context, param=None, selector=None, attr_value=None): + """ + 包含参数[{param}]的元素[{selector}]的value为[{attr_value}] + The specified selector element string exists in the page + :param context: step context + :param param: element value. + :param selector: locator string for selector element (or None). + :param attr_name: attribute name + :param attr_value: attribute value + """ + g_Context.step.ele_with_param_value_equal(context, param, selector, attr_value) + + @step("the [{param}] contained by the element [{selector}] has attribute [{attr_name}] contain value [{attr_value}]") @FlybirdsReportTagInfo(group="element", selectors={ "path": [{"type": "text", "value": "param", "name": "文本"}, @@ -944,6 +965,22 @@ def scroll_ele_into_view(context, selector=None): g_Context.step.scroll_ele_into_view(context, selector) +@step("upload image to element[{selector}]") +@FlybirdsReportTagInfo(group="element", selectors={ + "path": [{"type": "path", "value": "selector", "name": "元素"}]}, verify_function="common_error_parse", + action=ActionType.upload) +@ele_wrap +def scroll_ele_into_view(context, selector=None): + """ + 移动元素[{selector}]至可视区域 + Full screen swipe in the specified direction to find the specified + selector element + :param context: step context + :param selector: locator string for selector element (or None). + """ + g_Context.step.upload_image_to_ele(context, selector) + + @step("clear [{selector}] and input[{param2}]") @FlybirdsReportTagInfo(group="element", selectors={ "path": [{"type": "path", "value": "selector", "name": "元素"}, diff --git a/flybirds/core/exceptions.py b/flybirds/core/exceptions.py index ef91e6e..3ee0737 100644 --- a/flybirds/core/exceptions.py +++ b/flybirds/core/exceptions.py @@ -326,6 +326,7 @@ class ActionType: disappear: str = "disappear" move: str = "move" select: str = "select" + upload: str = "upload" setPageSize: str = "setPageSize" switchPage: str = "switchPage" setCookie: str = "setCookie" diff --git a/flybirds/core/plugin/plugins/default/web/element.py b/flybirds/core/plugin/plugins/default/web/element.py index bca00a6..35200d3 100644 --- a/flybirds/core/plugin/plugins/default/web/element.py +++ b/flybirds/core/plugin/plugins/default/web/element.py @@ -11,6 +11,7 @@ from flybirds.core.exceptions import FlybirdVerifyException, \ FlybirdsVerifyEleException, ErrorName from flybirds.core.global_context import GlobalContext as g_Context +from flybirds.core.plugin.plugins.default.screen import BaseScreen from flybirds.utils import language_helper as lan from flybirds.utils.dsl_helper import handle_str, params_to_dic import re @@ -229,6 +230,12 @@ def ele_not_contain_value(self, context, selector, param): timeout=timeout) verify_helper.text_not_container(param, ele_value) + def ele_with_param_value_equal_attr(self, context, selector, attr_value): + locator, timeout = self.get_ele_locator(selector) + ele_value = locator.evaluate('(element) => { console.log("element.value");return element.value}', + timeout=timeout) + verify_helper.text_equal(attr_value, ele_value) + def wait_for_ele(self, context, param): locator, timeout = self.get_ele_locator(param) locator.wait_for(timeout=timeout, state='visible') @@ -326,6 +333,24 @@ def find_full_screen_slide(self, context, param1, param2): locator, timeout = self.get_ele_locator(param2) locator.scroll_into_view_if_needed(timeout=timeout) + def upload_image(self, context, param2): + locator, timeout = self.get_ele_locator(param2) + try: + page = gr.get_value("plugin_ele").page + with page.expect_file_chooser() as fc_info: + try: + # click the upload button to trigger the file chooser + locator.click(timeout=2000) + except Exception as e: + log.info(e) + step_index = context.cur_step_index - 1 + img_path = BaseScreen.screen_link_to_behave(context.scenario, step_index, "screen_") + file_chooser = fc_info.value + file_chooser.set_files(img_path) + except Exception as e: + log.info(e) + raise FlybirdsVerifyEleException(message="upload image failed", error_name=ErrorName.ElementNotFoundError) + def get_ele_attr(self, selector, attr_name, params_deal_module=None, deal_method=None): locator, timeout = self.get_ele_locator(selector) diff --git a/flybirds/core/plugin/plugins/default/web/step.py b/flybirds/core/plugin/plugins/default/web/step.py index 56fab6c..5c5ad73 100644 --- a/flybirds/core/plugin/plugins/default/web/step.py +++ b/flybirds/core/plugin/plugins/default/web/step.py @@ -225,6 +225,14 @@ def ele_contain_param_value(cls, context, param1, selector, param2): ele = gr.get_value("plugin_ele") ele.ele_text_equal(context, selector, param2) + @classmethod + def ele_with_param_value_equal(cls, context, param, selector, attr_value): + params = param.split(',') + for param in params: + selector = selector.replace('{}', param, 1) + ele = gr.get_value("plugin_ele") + ele.ele_with_param_value_equal_attr(context, selector, attr_value) + @classmethod def ele_contain_param_contain_value(cls, context, param1, selector, param2): params = param1.split(',') @@ -342,6 +350,14 @@ def scroll_ele_into_view(cls, context, selector): ele = gr.get_value("plugin_ele") ele.find_full_screen_slide(context, None, selector) + @classmethod + def upload_image_to_ele(cls, context, selector): + """ + from {param1} find[{param2}]element + """ + ele = gr.get_value("plugin_ele") + ele.upload_image(context, selector) + @classmethod def ele_attr_equal(cls, context, selector, param2, param3): ele = gr.get_value("plugin_ele")