Python Learning notes (excel+requests)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.