文件目录:  test_login.py文件:
import os
import time
import pytest
from selenium import webdriver
from testcase2.config.yaml_load import load_yaml
class Testlogin:
def setup(self):
self.driver=webdriver.Chrome()
self.driver.get('http://39.98.138.157/shopxo/index.php?s=/index/user/logininfo.html')
@pytest.mark.parametrize('udata',load_yaml('./data/login.yaml'))
def test_01(self,udata):
self.driver.find_element_by_name('accounts').send_keys(udata['name'])
self.driver.find_element_by_name('pwd').send_keys(udata['pwd'])
self.driver.find_element_by_xpath('/html/body/div[4]/div/div[2]/div[2]/form/div[3]/button').click()
self.driver.maximize_window()
def teardown(self):
time.sleep(2)
self.driver.quit()
if __name__ == '__main__':
pytest.main(['-vs','test_login.py','--alluredir','./allure-results'])
os.system('allure generate ./allure-results -o ./reports ')
yaml_load.py文件:
import yaml
def load_yaml(filename):
stream=open(filename,'r')
data=yaml.load(stream,yaml.FullLoader)
return data
login.yaml文件:
-
name: qiushui
pwd: 123456
-
name: qiushui22
pwd: 123456
测试结果(由于未设置断言,所有全部通过):  
|