Skip to content

Commit 5583eae

Browse files
authored
Merge pull request #328 from rustpypeng/main
feat: add web image upload
2 parents 50ddd23 + 18fb81d commit 5583eae

File tree

5 files changed

+82
-0
lines changed

5 files changed

+82
-0
lines changed

flybirds/core/dsl/globalization/i18n.py

+3
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@
266266
"the [{param}] contained by the element [{selector}] has attribute [{attr_name}] not contain value [{"
267267
"attr_value}]":
268268
["包含参数[{param}]的元素[{selector}]的属性[{attr_name}]值不包含[{attr_value}]"],
269+
"the [{param}] contained by the element [{selector}] element value is [{attr_value}]":
270+
["包含参数[{param}]的元素[{selector}]的value为[{attr_value}]"],
269271
"click[{selector}] and accept dialog": ["点击[{selector}]并接受弹窗"],
270272
"click[{selector}] and cancel dialog": ["点击[{selector}]并取消弹窗"],
273+
"upload image to element[{selector}]": ["上传图片到元素[{selector}]"]
271274
},
272275
}

flybirds/core/dsl/step/element.py

+37
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,27 @@ def ele_contain_param_attr_exist(context, param=None, selector=None, attr_name=N
815815
g_Context.step.ele_contain_param_attr_exist(context, param, selector, attr_name, attr_value)
816816

817817

818+
@step("the [{param}] contained by the element [{selector}] element value is [{attr_value}]")
819+
@FlybirdsReportTagInfo(group="element", selectors={
820+
"path": [{"type": "text", "value": "param", "name": "文本"},
821+
{"type": "path", "value": "selector", "name": "元素"}]},
822+
verify={"type": ErrorFlag.text_equ, "value": "attr_value"},
823+
verify_function="ele_verify_text_error_parse")
824+
@VerifyStep()
825+
@ele_wrap
826+
def ele_contain_param_attr_exist(context, param=None, selector=None, attr_value=None):
827+
"""
828+
包含参数[{param}]的元素[{selector}]的value为[{attr_value}]
829+
The specified selector element string exists in the page
830+
:param context: step context
831+
:param param: element value.
832+
:param selector: locator string for selector element (or None).
833+
:param attr_name: attribute name
834+
:param attr_value: attribute value
835+
"""
836+
g_Context.step.ele_with_param_value_equal(context, param, selector, attr_value)
837+
838+
818839
@step("the [{param}] contained by the element [{selector}] has attribute [{attr_name}] contain value [{attr_value}]")
819840
@FlybirdsReportTagInfo(group="element", selectors={
820841
"path": [{"type": "text", "value": "param", "name": "文本"},
@@ -944,6 +965,22 @@ def scroll_ele_into_view(context, selector=None):
944965
g_Context.step.scroll_ele_into_view(context, selector)
945966

946967

968+
@step("upload image to element[{selector}]")
969+
@FlybirdsReportTagInfo(group="element", selectors={
970+
"path": [{"type": "path", "value": "selector", "name": "元素"}]}, verify_function="common_error_parse",
971+
action=ActionType.upload)
972+
@ele_wrap
973+
def scroll_ele_into_view(context, selector=None):
974+
"""
975+
移动元素[{selector}]至可视区域
976+
Full screen swipe in the specified direction to find the specified
977+
selector element
978+
:param context: step context
979+
:param selector: locator string for selector element (or None).
980+
"""
981+
g_Context.step.upload_image_to_ele(context, selector)
982+
983+
947984
@step("clear [{selector}] and input[{param2}]")
948985
@FlybirdsReportTagInfo(group="element", selectors={
949986
"path": [{"type": "path", "value": "selector", "name": "元素"},

flybirds/core/exceptions.py

+1
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ class ActionType:
326326
disappear: str = "disappear"
327327
move: str = "move"
328328
select: str = "select"
329+
upload: str = "upload"
329330
setPageSize: str = "setPageSize"
330331
switchPage: str = "switchPage"
331332
setCookie: str = "setCookie"

flybirds/core/plugin/plugins/default/web/element.py

+25
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from flybirds.core.exceptions import FlybirdVerifyException, \
1212
FlybirdsVerifyEleException, ErrorName
1313
from flybirds.core.global_context import GlobalContext as g_Context
14+
from flybirds.core.plugin.plugins.default.screen import BaseScreen
1415
from flybirds.utils import language_helper as lan
1516
from flybirds.utils.dsl_helper import handle_str, params_to_dic
1617
import re
@@ -229,6 +230,12 @@ def ele_not_contain_value(self, context, selector, param):
229230
timeout=timeout)
230231
verify_helper.text_not_container(param, ele_value)
231232

233+
def ele_with_param_value_equal_attr(self, context, selector, attr_value):
234+
locator, timeout = self.get_ele_locator(selector)
235+
ele_value = locator.evaluate('(element) => { console.log("element.value");return element.value}',
236+
timeout=timeout)
237+
verify_helper.text_equal(attr_value, ele_value)
238+
232239
def wait_for_ele(self, context, param):
233240
locator, timeout = self.get_ele_locator(param)
234241
locator.wait_for(timeout=timeout, state='visible')
@@ -326,6 +333,24 @@ def find_full_screen_slide(self, context, param1, param2):
326333
locator, timeout = self.get_ele_locator(param2)
327334
locator.scroll_into_view_if_needed(timeout=timeout)
328335

336+
def upload_image(self, context, param2):
337+
locator, timeout = self.get_ele_locator(param2)
338+
try:
339+
page = gr.get_value("plugin_ele").page
340+
with page.expect_file_chooser() as fc_info:
341+
try:
342+
# click the upload button to trigger the file chooser
343+
locator.click(timeout=2000)
344+
except Exception as e:
345+
log.info(e)
346+
step_index = context.cur_step_index - 1
347+
img_path = BaseScreen.screen_link_to_behave(context.scenario, step_index, "screen_")
348+
file_chooser = fc_info.value
349+
file_chooser.set_files(img_path)
350+
except Exception as e:
351+
log.info(e)
352+
raise FlybirdsVerifyEleException(message="upload image failed", error_name=ErrorName.ElementNotFoundError)
353+
329354
def get_ele_attr(self, selector, attr_name, params_deal_module=None,
330355
deal_method=None):
331356
locator, timeout = self.get_ele_locator(selector)

flybirds/core/plugin/plugins/default/web/step.py

+16
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@ def ele_contain_param_value(cls, context, param1, selector, param2):
225225
ele = gr.get_value("plugin_ele")
226226
ele.ele_text_equal(context, selector, param2)
227227

228+
@classmethod
229+
def ele_with_param_value_equal(cls, context, param, selector, attr_value):
230+
params = param.split(',')
231+
for param in params:
232+
selector = selector.replace('{}', param, 1)
233+
ele = gr.get_value("plugin_ele")
234+
ele.ele_with_param_value_equal_attr(context, selector, attr_value)
235+
228236
@classmethod
229237
def ele_contain_param_contain_value(cls, context, param1, selector, param2):
230238
params = param1.split(',')
@@ -342,6 +350,14 @@ def scroll_ele_into_view(cls, context, selector):
342350
ele = gr.get_value("plugin_ele")
343351
ele.find_full_screen_slide(context, None, selector)
344352

353+
@classmethod
354+
def upload_image_to_ele(cls, context, selector):
355+
"""
356+
from {param1} find[{param2}]element
357+
"""
358+
ele = gr.get_value("plugin_ele")
359+
ele.upload_image(context, selector)
360+
345361
@classmethod
346362
def ele_attr_equal(cls, context, selector, param2, param3):
347363
ele = gr.get_value("plugin_ele")

0 commit comments

Comments
 (0)