testcase.yaml:
- id: home_search
- id: search_input_text
input: alibaba
- id: name
- id: current_price
get: text
class TestDemo:
def test_search_from_testcase(self):
TestCase("testcase.yaml").run(self.driver)
class TestCase:
def __init__(self,path):
file = open(path,"r")
self.steps = yaml.safe_load(file)
def run(self,driver:WebDriver):
for step in self.steps:
element = None
if isinstance(step,dict):
if "id" in step.keys():
element = driver.find_element_by_id(step["id"])
elif "xpath" in step.keys():
element = driver.find_element_by_xpath(step["xpath"])
else:
print(step.keys())
if "input" in step.keys():
element.send_keys(step["input"])
else:
element.click()
if "get" in step.keys():
text = element.get_attribute(step["get"])
print(text)