Background: In the testing process, in order to achieve the implementation of the different test data batch cycle input, consider the need to read the CSV file by the way of parameterization of the steps to further parameterization, the sample code is as follows:
Import CSV
...
Data_set = R ' C:\\test.csv '
data = Csv.reader (file (Data_set, ' RB '))
def test_insert (self):
...
# A total of four fields for each data to be entered
Info0 = 0
INFO1 = 1
Info2 = 2
Info3 = 3
For record in data:
# loop 5 times, 5 data to be entered
For x in range (0,5):
...
DRIVER.FIND_ELEMENT_BY_ID ("Telephone"). Send_keys (Record[info0])
DRIVER.FIND_ELEMENT_BY_ID ("Company"). Send_keys (Record[info1].decode (' gb2312 '))
driver.find_element_by_id ("description"). Send_keys (Record[info2].decode (' gb2312 '))
driver.find_element_by_id ("service"). Send_keys (Record[info3].decode (' gb2312 '))
Info0 = Info0 + 4
Info1 = Info1 + 4
Info2 = Info2 + 4
Info3 = Info3 + 4
...
The local contents of the Test.csv file are as follows:
13000000001,a Company, a company profile, a company provides services, 13000000002,b company, B Company Profile, B Company provides services, 13000000003,c company, C Company Profile, C Company provides services,...
Note: If the input data contains Chinese, it can be decode to prevent the script from failing due to possible coding problems.
Automated testing – Batch input of test data with Python+selenium