selenium3关于ddt数据驱动。。

 1 from selenium import webdriver
 2 import ddt
 3 import time
 4 import unittest
 5 
 6 @ddt.ddt
 7 class TestLogin(unittest.TestCase):
 8 
 9     @classmethod
10     def setUpClass(cls):
11         cls.driver = webdriver.Chrome()
12         cls.url = "http://192.168.117.9:8080/jforum/forums/list.page"
13 
14     def LoginFunc(self, name, password):
15         self.driver.get(self.url)
16         self.driver.find_element_by_name('username').send_keys(name)
17         self.driver.find_element_by_name('password').send_keys(password)
18         time.sleep(1)
19         self.driver.find_element_by_name('login').click()
20         time.sleep(2)
21         self.driver.find_element_by_id('logout').click()
22 
23     @ddt.data(['admin', 'admin'], ['jack', '123456'], ['tom', '123456'])
24     @ddt.unpack
25     def test_case1(self, name, password):
26         self.LoginFunc(name, password)
27 
28     @classmethod
29     def tearDownClass(cls):
30         cls.driver.quit()
31 
32 if __name__ == "__main__":
33     unittest.main()
View Code

猜你喜欢

转载自www.cnblogs.com/97xiaolai/p/11812016.html
今日推荐