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:""



TAG: pytest yaml

快要秃头的娜娜的个人空间 引用 删除 快要秃头的娜娜   /   2021-06-10 17:03:37
-5
 

评分:0

我来说两句

我的栏目

日历

« 2024-03-20  
     12
3456789
10111213141516
17181920212223
24252627282930
31      

我的存档

数据统计

  • 访问量: 562
  • 日志数: 1
  • 建立时间: 2021-06-10
  • 更新时间: 2021-06-10

RSS订阅

Open Toolbar