First, the Environment preparation
1. Install the DDT module, open cmd input pip install DDT online installation
Second, the data-driven principle
1. Test data is a list type of multiple dictionaries
2. Test the class before adding the modified @ddt.ddt
3.case Pre-Modified @ddt.data ()
4. Post-run use cases are automatically loaded into three separate use cases
# coding:utf-8import ddtimport unittest# test Data Test_data = [{"username": "Zhangsan", "pwd": "Zhangsan"}, {"username": "Lisi", "pwd": "Lisi"}, {"username": "Wangwu", "pwd": "Wangwu"}, ]test_data2 = [{"username": "Wukong", "pwd": " Wukong "}, {" username ":" Wuneng "," pwd ":" Woneng "}, {" username ":" Wujing "," pwd ":" Wujing "}, ]@ Ddt.ddtclass Test (unittest. TestCase): def setUp (self): print ("start!") def tearDown (self): print ("end!") @ddt. Data (*test_data) def test_ddt1 (self, data): print (data) @ddt. Data (*TEST_DATA2) def test_ DDT2 (self, data): print (data) if __name__ = = "__main__": Unittest.main ()
Selenium2+python Automation-Data driven (DDT)