Preliminary Exploration of the interface testing framework-python Series 6, Preliminary Exploration-python
Click "Blue name" under the title to quickly follow
What we insist on is sharing, moving knowledge, showing everyone's progress, no paid training, no fake information, and paying attention and forwarding if you like (free to help more partners) if you want to know more, please leave a message to bring you more value. We are looking forward to it. If you are more interested, please refer to our subscription number. The contact information is as follows:
More books are coming soon
Background
This is the python 6th lesson. I don't know what the previous knowledge is like. Do you feel that you have come into contact with the interface testing framework? I will continue to practice.
1. Job content
Question 5: Write a network request, pass in CityName and CountryName, get the weather condition URL: http://www.webservicex.net/globalweather.asmx/GetWeather
Parameters: CityName and CountryName
Method: post
Requirements:
1. The parameter value is obtained from excel (two columns). The actual value and result are reversed to the end of the corresponding row.
2. Each row is a test case.
3. Specify the expected value and determine whether the expected value is equal to the actual value. If the expected value is equal, the result is pass. Otherwise, the result is failed.
4. Enter the response time of each request.
2 related knowledge points
1. database for processing xlsx files
Http://www.python-excel.org/with a column, choose the first openpyxl, directly use pipinstallinstallation.
Working with Excel Files in Python
This site contains pointers to the best information available about working with Excel files
In the Python programming language.
The Packages
There are python packages available to work with Excel files that will run on any Python
Platform and that do not require either Windows or Excel to be used. They are fast, reliable
And open source:
Openpyxl
The recommended package for reading and writing Excel 2010 files (ie:. xlsx)
Download | Documentation | Bitbucket
Xlsxwriter
An alternative package for writing data, formatting information and, in particle, charts in
The Excel 2010 format (ie:. xlsx)
Download | Documentation | GitHub xlrd
This package is for reading data and formatting information from older Excel files (ie:. xls)
Download | Documentation | GitHub
Xlwt
This package is for writing data and formatting information to older Excel files (ie:. xls)
Download | Documentation | Examples | GitHub
Xlutils
This package collects utilities that require both xlrd and xlwt, including the ability to copy
And modify or filter existing excel files.
NB: In general, these use cases are now covered by openpyxl!
Download | Documentation | GitHub
2. Basic use of the openpyxl Library
Open Table
Table = openpyxl. load_workbook (filename)
Get the first sheet name
Sheetname = table. get_sheet_names () [0]. encode ('ascii ')
Obtain the value at a certain position
Value = table [sheetname] [XX]. value. encode ('ascii ')
Set/modify the value of a location
Table [sheetname] [XX]. value = setvalue
Save table
Table. save (filename)
Basically, these commands are used to read and modify the table, where the position is spliced by reading the current row cyclically.
3. process the xml returned by the request
The request is the previous content. urllib2 is used for the request and the passed parameters are encoded using urllib. urlencode.
Req = urllib2.Request (url)
Data = urllib. urlencode (data)
Response = urllib2.urlopen (url, data)
The returned xml is as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
<Stringxmlns = "http://www.webserviceX.NET"> & lt ;? Xmlversion = "1.0" encoding = "UTF-16 "? & Gt;
& Lt; CurrentWeather & gt;
& Lt; Location & gt; Beijing, China (ZBAA) 39-56N 116-17E55M & lt;/Location & gt;
& Lt; Time & gt; Mar 15,201 6-pm edt/2016.03.16 0200UTC & lt;/Time & gt;
& Lt; Wind & gt; from the ENE (060 degrees) at 7 MPH (6KT): 0 & lt;/Wind & gt;
& Lt; Visibility & gt; 1 mile (s): 0 & lt;/Visibility & gt;
& Lt; Temperature & gt; 48 F (9 C) & lt;/Temperature & gt;
& Lt; DewPoint & gt; 35 F (2 C) & lt;/DewPoint & gt;
& Lt; RelativeHumidity> 61% & lt;/RelativeHumidity>;
& Lt; Pressure & gt; 30.06 in. Hg (1018hPa) & lt;/Pressure & gt;
& Lt; Status & gt; Success & lt;/Status & gt;
& Lt;/CurrentWeather & gt; </string>
A layer is nested in an xml file.
There are two solutions:
1. Remove a header
First, xml. sax. saxutils. unescape is used to handle html Encoding Problems.
Use regular expressions to remove the content of the second line and the end </string>
And then pass it to xml. dom. minidom. parseString to format it into an xml object.
2. Use xml. dom. minidom. parseString twice
After formatting the returned content for the first time, use the string xmlns child to format it again.
Because the xml. dom. minidom. parseString handle the UTF-16 error of the encoding declaration, you also need to replace it with a UTF-8. Use the method getElementsByTagName obtained from method 1 or method 2 to obtain the required tag value. The request response time is obtained using the time () function for subtraction twice.
4. Loop Processing
Use the openpyxl library to obtain the number of rows in the entire xlsx table, and set the loop range to the last row from the second row to the file. Read the parameters of each row, establish a request to obtain the results, compare the results, and modify the results of the row. Save.
Post 3
For reference examples, please join the QQ group to get it. Here, we have offered all the knowledge points and reference examples for 6th lessons and 5th assignments. Let's take actions!
Recommended articles
Test Framework of APIS-python Series 1
Test Framework of APIS-python Series 2
Test Framework of APIS-python Series 3
Test Framework of APIS-python Series 4
Fiddler records jmeter scripts and shares valuable information
Jmeter interface automation, you dare to think, I dare to play
Interface Test practice -- SoapUI Pro5.1.2
On the test road, talk about ideas and methods.
Gentle knowledge-History List
Jenkins Series 1 -- tag automatically
Click "read original". [view more information]