Design Automation Framework --PO Mode Self - parametric data driver configured --tdd - read excel-- nested lists List - Baidu search - assertions - before each use case before - after execution

import  unittest
from selenium import webdriver
from ddt import  ddt,data,unpack
import time
from aaa import readxls

test_data = readxls()
@ddt
class TestMath(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.driver = webdriver.Firefox()
        cls.driver.get('http://www.baidu.com')

    @classmethod
    def tearDownClass(cls):
        cls.driver.quit()

    DEF the setUp (Self): 
        self.driver.find_element_by_id ( ' kW ' ) .clear ()
         Print ( ' start ------------- ' ) 

    DEF the tearDown (Self):
         Print ( ' end - ----------------------- ' ) 


    @data ( * TEST_DATA) 
    @unpack     # after "de-coat", for each data you get split according comma 
    DEF test_print_data (Self, a, B):   # required transmission parameters according to the number of split out within each of the data 

        self.driver.find_element_by_id ( ' kW ' ) .send_keys (STR (B)) 
        self.driver.find_element_by_id (' SU ' ) .click () 

        the time.sleep ( 10 ) 

        self.assertEqual (self.driver.title, B + ' _ Baidu search ' )



        
Import to xlrd
 DEF readxls (): 
    XL = xlrd.open_workbook ( ' C: \\ the Users del \\ \\ \\ book.xls Desktop ' )   # open Excel spreadsheet 
    Sheet1 = xl.sheet_by_name ( ' Sheet1 ' )   # specified in Table 1 
    = listData []      # define empty list, for storing each row of data read out 
    for I in Range (1, 4):   # cycles 1 to 4 (not included 4), i.e. 3 cycles 
        j = sheet1.row_values ( i, 0, 2)   # reading of 0 to 2 (excluding column 2) i-th row 
        listdata.append (J) # read line into additional line in listData 
    # Print (listData) 
    returnlistData   # returns a list of 

IF  __name__ == " __main__ " :
     Print (readxls ())

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Results of the:

 

Guess you like

Origin www.cnblogs.com/xiaobaibailongma/p/12632170.html