Python learning notes (excel + requests), pythonrequests

Source: Internet
Author: User

Python learning notes (excel + requests), pythonrequests

After a simple excel operation

You can start writing test cases in excel.

Read use case execution case

Write execl in advance

The following code is used:

1 #! /Usr/bin/env python 2 #-*-coding: utf_8-*-3 4 import xlrd 5 import requests 6 import re 7 import json 8 9 workbook = xlrd. open_workbook (r'e: \ work \ python case \ learn \ testcase.xls ') 10 # Open the excel file 11 table = workbook according to the path. sheets () [0] 12 # obtain the first sheet13 nrows = table. nrows14 # obtain the number of rows 15 TestData = [] 16 # array 17 for I in range (1, nrows): 18 TestData. append (table. cell (I, 1 ). value) 19 # Add cell data 20 print TestData21 22 for j in range (0, nrows-1) at the end of the loop array: 23 data = json. loads (TestData [j]) 24 # string escape json25 TestCase = data26 # The cyclic array value is assigned to the test case parameter 27 print TestCase28 # The test case parameter 29 results = requests. post ('HTTP: // localhost: 8081/swcw/back/sysLogin. action ', data = TestCase) 30 # post request 31 pattern = re. compile (r 'tomain') 32 # regular expression ps: I am too simple to use o (Regular Expression) o alas 33 match = pattern. search (results. url) 34 try: 35 if results. status_code = 200:36 if match. group () = 'tomain': 37 print 'test result: test passed '38 else: 39 print 'Test Result: request failed '40 TB AttributeError: 41 print 'test result: Test failed'

 

Simple code is written.

View the running result:

You can see the direction of this API automated testing framework.

 

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.