import yaml
import unittest
from selenium import webdriver
import time
from ddt import ddt, data, unpack, file_data
chrome_driver = r"C:\Program Files (x86)\Python38-32\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe"
file = open('test_yml.yml', encoding='utf-8')
res = yaml.load(file, Loader=yaml.FullLoader)
print(res)
@ddt
class for_yml_test(unittest.TestCase):
def setUp(self) -> None:
self.driver = webdriver.Chrome(executable_path=chrome_driver)
self.driver.get('https://www.baidu.com')
def tearDown(self) -> None:
time.sleep(5)
self.driver.quit()
@file_data('test_yml.yml')
def test_a(self, **kwargs):
print(kwargs.get('name'))
self.driver.find_element_by_id('kw').send_keys(kwargs.get('name'))
# self.assertEqual(kwargs.get('name'), '杨过', msg='NotEqual')
self.driver.find_element_by_id('su').click()
if __name__ == '__main__':
unittest.main()
test_yml.yml
-
name: '杨过'
text: 'ghhjj'
-
name: '小龙女'
text: 'ghhjj'
-
name: '乔峰'
text: 'ghhjj'