from time import sleep class WebKeys: def __init__(self): self.driver = webdriver.Chrome() # 访问url def open(self, url): self.driver.get(url) # 退出 def quit(self): self.driver.quit() # 元素定位 def locator(self, name, value): return self.driver.find_element(name, value) # 输入框功能 def input(self, name, value, txt): el = self.locator(name, value) el.clear() el.send_keys(txt)` |
import pytest from time import * from data_driver import yaml_driver @pytest.mark.parametrize('data', yaml_driver.load_yaml('../data/baidu.yaml')) def test_login(data): wk = WebKeys() wk.open(data['url']) wk.input(data["name"], data["value"], data["txt"]) sleep(3) wk.quit() if __name__ == '__main__': pytest.main() |
def load_yaml(path): file = open(path, 'r', encoding='utf-8') data = yaml.load(file, Loader=yaml.FullLoader) return data |
- url: http://www.baidu.com name: xpath value: //*[@id="kw"] txt: 狗狗币 - url: http://www.baidu.com name: xpath value: //*[@id="kw"] txt: 火币 - url: http://www.baidu.com name: xpath value: //*[@id="kw"] txt: 比特币 - url: http://www.baidu.com name: xpath value: //*[@id="kw"] txt: 以太坊 |
if __name__ == '__main__': pytest.main() |
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |