def steps(self, path):
with open(path, encoding="utf-8") as f:
name = inspect.stack()[1].function
# 对yaml文件进行解析,取出跟name对应的value
steps = yaml.safe_load(f)[name]
# element = None
raw = json.dumps(steps)
for key, value in self._params.items():
raw = raw.replace(f'${{{key}}}', value)
steps = json.loads(raw)
# 遍历steps(yaml文件内容)
for step in steps:
# 查找元素
# if "by" in step.keys():
# element = self.find(step["by"], step["locator"])
# 多个动作解析
if "action" in step.keys():
action = step["action"]
if action == "click":
self.find(step["by"], step["locator"]).click()
if action == "send":
# value = step["value"]
# print(f"send{value}")
self.find(step["by"], step["locator"]).send_keys(step["value"])
if action == "len > 0":
eles = self.finds(step["by"], step["locator"])
return len(eles) > 0
if action == "text":
text = self.find(step["by"], step["locator"]).text
return text