Python Learning Notes (interface Automation framework)

Source: Internet
Author: User

Previously, the UnitTest test framework was used with Python's own

This time I design one after another a little bit inside add function

(PS: Of course, this framework is really simple.) Very simple... Very simple... )

Excel file Format:

1 #!/usr/bin/env python2 #-*-coding:utf_8-*-3 4 Importxlrd5 ImportJSON6 7 8 classCreateexcel:9     def __init__(self):Ten         Pass One  A @classmethod -     defOpen_excel (CLS): -Path ="Testcase.xls" theWorkbook =Xlrd.open_workbook (path) -Table =workbook.sheets () [0] -         returnTable -     #Get Sheet +  - @classmethod +     defget_nrows (CLS, table): Anrows =table.nrows at         returnnrows -     #Get line number -  - @classmethod -     defget_name (CLS, table, nrows): -TestName = [] in          forIinchRange (1, nrows): - Testname.append (Table.cell (i, 0). Value) to         returntestname +     #get the use case name -  the @classmethod *     defget_data (CLS, table, nrows): $TestData = []Panax Notoginseng          forIinchRange (1, nrows): -data = Json.loads (Table.cell (i, 1). Value) the testdata.append (data) +         returntestdata A     #get Data Interface Parameters the  + @classmethod -     defGet_url (CLS, table, nrows): $Testurl = [] $          forIinchRange (1, nrows): -Testurl.append (Table.cell (i, 2). Value) -         returnTesturl the     #get interface Test URL - Wuyi @classmethod the     defGet_method (CLS, table, nrows): -TestMethod = [] Wu          forIinchRange (1, nrows): -Testmethod.append (Table.cell (i, 3). Value) About         returnTestMethod $     #Get interface test method -  - @classmethod -     defGet_pattern (CLS, table, nrows): ATestpattern = [] +          forIinchRange (1, nrows): theTestpattern.append (Table.cell (i, 4). Value) -         returnTestpattern $     #Get interface Expected response result the  the @classmethod the     defget_report (CLS, table, nrows): theTestreport = [] -          forIinchRange (1, nrows): inTestreport.append (Table.cell (i, 5). Value) the         returnTestreport the         #get the run results expected by the use case About  the  the if __name__=="__main__": theCreateexcel ()

The above code is for working with Excel documents

The following code is the test platform

1 #!/usr/bin/env python2 #-*-coding:utf_8-*-3 4 5 ImportRequests6 ImportRe7  fromCreateexcelImportCreateexcel8 9 Ten classcreatetest: One     def __init__(self): A         Pass -  - @classmethod the     defTest_api (CLS, method, URL, data): -         GlobalResults -         ifmethod = ="Post": -Results =requests.post (URL, data) +         ifmethod = ="Get": -Results =requests.get (URL, data) +         returnResults A  at @classmethod -     deftest_on (CLS): -         Print "use case execution start" -  - @classmethod -     defTest_close (CLS): in         Print "End of use case execution" -  to @classmethod +     defTest_result (CLS, RA, RB): -         ifRA = =RB: the             Print "test Result: Test pass" *         Else: $             Print "test Result: Test Failed"Panax Notoginseng  - @classmethod the     deftest_http (CLS, code): +         ifCode = = 200: A             Print "Test Request: Request through" the  + @classmethod -     defTest_main (CLS): $         Global Report $Table =Createexcel.open_excel () -nrows =createexcel.get_nrows (table) -          forIinchRange (0, nrows-1): theTestName =createexcel.get_name (table, nrows) [i] -TestData =createexcel.get_data (table, nrows) [i]WuyiTesturl =createexcel.get_url (table, nrows) [i] theTestMethod =Createexcel.get_method (table, nrows) [i] -Testpattern =Createexcel.get_pattern (table, nrows) [i] WuTestreport =createexcel.get_report (table, nrows) [i] - createtest.test_on () About             Print "test Case:", TestName $             Try: -TestResults =Createtest.test_api (TestMethod, Testurl, testdata) - createtest.test_http (Testresults.status_code) -Pattern =re.compile (Testpattern) AMatch =Pattern.search (Testresults.url) +                 ifMatch.group () = =Testpattern: thereport ="Pass" - Createtest.test_result (testreport, report) $             exceptAttributeerror: thereport ="No" the Createtest.test_result (testreport, report) the             exceptException.__base__: the                 Print "Test Request: Request failed" -report =None in Createtest.test_result (testreport, report) the createtest.test_close () the  About  the if __name__=='__main__': theCreatetest ()

Python Learning Notes (interface Automation framework)

Related Article

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.