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()
参考内容: