Can already be simple for Excel after the operation
Can start writing test cases through Excel
Read use case execution cases
Write well in advance execl
Here's the code:
1 #!/usr/bin/env python2 #-*-coding:utf_8-*-3 4 Importxlrd5 ImportRequests6 ImportRe7 ImportJSON8 9Workbook = Xlrd.open_workbook (r'E:\work\python Case\learn\testcase.xls')Ten #open an Excel file based on a path OneTable =workbook.sheets () [0] A #get the first sheet -nrows =table.nrows - #Get row Count theTestData = [] - #Array - forIinchRange (1, nrows): -Testdata.append (Table.cell (i,1). Value) + #Add cell data at the end of the loop array - PrintTestData + A forJinchRange (0,nrows-1): atdata =json.loads (Testdata[j]) - #string Escape JSON -TestCase =Data - #loop array assignment into use case parameters - PrintTestCase - #parameters corresponding to use cases inResults = Requests.post ('http://localhost:8081/swcw/back/sysLogin.action', Data=TestCase) - #POST Request toPattern = Re.compile (r'Tomain') + #Regular expression PS: I this is too simple O (︶^︶) o ay -Match =Pattern.search (Results.url) the Try: * ifResults.status_code = = 200: $ ifMatch.group () = ='Tomain':Panax Notoginseng Print 'use case test result: Test pass' - Else: the Print 'use case test Result: request failed' + exceptAttributeerror: A Print 'use case test Result: Test Failed'
The simple code is written.
To view the results of a run:
The direction of this interface Automation test framework has been seen
Python Learning notes (excel+requests)