pytest小练
上一篇 /
下一篇 2021-06-10 14:05:35
/ 个人分类:pytest
数据与代码分离是
自动化测试编写测试代码中应该具备的基本思想,学习用
pytest测试框架完成163邮箱登录,
记录一。
# test_one.py
# -*- coding:utf-8 -*-
importpytest
fromseleniumimportwebdriver
fromtimeimportsleep
fromcommonimportget_yaml
login_case = get_yaml.GetYamlData().get_all_data()
@pytest.mark.parametrize("case_data", login_case)
deftest_a(case_data):
driver = webdriver.Chrome()
driver.get("https://mail.163.com/")
driver.maximize_window()
driver.implicitly_wait(20)
print('Before login================')
#打印当前页面title
title = driver.title
print(title)
#打印当前页面URL
now_url = driver.current_url
print(now_url)
iframe. = driver.find_element_by_xpath('//div[@id="loginDiv"]/iframe')
driver.switch_to.frame(iframe)
driver.find_element_by_xpath("//div[@id='account-box']//input").send_keys(case_data["data"]["account"])
driver.find_element_by_id("userType").send_keys(case_data["data"]["pwd"])
driver.find_element_by_id("wmSubBtn").click()
sleep(5)
print('After login================')
#再次打印当前页面title
title = driver.title
print(title)
#打印当前页面URL
now_url = driver.current_url
print(now_url)
#关闭所有窗口
driver.quit()
# get_yaml.py
# -*- coding:utf-8 -*-
importyaml, os
classGetYamlData:
def__init__(self):
self.filepath ="D:\测试\pytestProject\local_data\Local_login_data.yaml"
defget_all_data(self):
withopen(self.filepath,encoding="utf-8")asfs:
datas = yaml.load(fs,Loader=yaml.FullLoader)
returndatas
if__name__ =='__main__':
GetYamlData().get_all_data()
# login_local_data.yaml
-
data:
account:"username"
pwd:"password"
-
data:
account:"123456"
pwd:"xxxx"
-
data:
account:""
pwd:"123456"
-
data:
account:"123456"
pwd:""
相关阅读:
- 为什么使用Pytest:可以通过命令行来对测试用例进行控制 (大椿菜, 2020-11-25)
- Pytest中断言的重要性,就不需要我重复了吧 (liqianqian1116, 2020-12-23)
- 用例之间如何建立依赖关系?需要这个工具 (liqianqian1116, 2021-2-02)
- python测试框架-unittest & pytest (wphisme, 2021-3-25)
- Pytest参数化-你不知道的使用技巧(一) (大椿菜, 2021-5-11)
- Pytest参数化-你不知道的使用技巧(二) (大椿菜, 2021-5-11)
- Pytest参数化-你不知道的使用技巧(三) (大椿菜, 2021-5-12)
- pytest+yaml实现接口自动化框架之用例参数关联(二) (liqianqian1116, 2021-5-27)
- Pytest参数化-你不知道的使用技巧(四) (大椿菜, 2021-5-13)
- Pytest中断言失败后,也可以继续执行其他用例 (liqianqian1116, 2021-6-01)
收藏
举报
TAG:
pytest
yaml