Appium_测试步骤读取自外部文件:定制执行引擎

时间:2023-05-12 17:42:52

 1 class TestCase:
 2     def __init__(self,path):
 3         file = open(path,"r")
 4         self.steps = yaml.safe_load(file)
 5         
 6     def run(self,driver:WebDriver):
 7         for step in self.steps:
 8             element = None
 9             if isinstance(step,dict):
10                 if "id" in step.keys():
11                     element = driver.find_element_by_id(step["id"])
12                 elif "xpath" in step.keys():
13                     element = driver.find_element_by_xpath(step["xpath"])
14                 else:
15                     print(step.keys())
16             if "input" in step.keys():
17                 element.send_keys(step["input"])
18             elif "get" in step.keys():
19                 element.get_attribute(step["get"])
20             else:
21                 element.click()

 

参考内容:

1. https://www.bilibili.com/video/av79004717?p=26