Skip to content

Commit

Permalink
Merge pull request #328 from rustpypeng/main
Browse files Browse the repository at this point in the history
feat: add web image upload
  • Loading branch information
clgwlg authored Nov 22, 2024
2 parents 50ddd23 + 18fb81d commit 5583eae
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
3 changes: 3 additions & 0 deletions flybirds/core/dsl/globalization/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}]"]
},
}
37 changes: 37 additions & 0 deletions flybirds/core/dsl/step/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": "文本"},
Expand Down Expand Up @@ -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": "元素"},
Expand Down
1 change: 1 addition & 0 deletions flybirds/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 25 additions & 0 deletions flybirds/core/plugin/plugins/default/web/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions flybirds/core/plugin/plugins/default/web/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(',')
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 5583eae

Please sign in to comment.