Automated Testing (V): Automated testing Framework

Source: Internet
Author: User

Framework (Reusable function, method) type:

① data-driven (use test data to drive script run, test script and data separation ??? )

② keyword driver (object.action (param), higher abstraction, separation of business logic, scripts, data)

structure: Automation

①aut: Configuration file, XML file

②config (Object Repository): Objects, TSR files (FLIGHR.TSR)

③testdata: test data, i.e. test case, TXT file (flight_testcase.txt)

④script: Test script, read Test Data, pass to execute Testcase, pass to business process, get result, pass to Report,vbs file (Testdriven_flight.vbs,flight folder)

⑤report

⑥log

⑦exception

⑧controller file Invocation (Runqtp.vbs,runtime.bat)

Note: Business processing functions are written in QTP, and then copied

Flight_testcase.txt

|mercury| Please enter agent name

mer|mercury| Agent name must is at least 4 characters long

|mercury| Please enter passwoed

Mercury|mercury|null

Testdriven_flight.vbs

Const Forreading = 1

Const ForWriting = 2

Const forappending= 8

' File invocation

Controller "C:\AUTOMATION_FLIGHT\CONFIG\LOGIN_FLIGHT.TSR", "D:\Software\QTP10\samples\flight\app\flight4a.exe", " C:\Automation_Flight\TestData\flight_testcase.txt "

' File Call function

Function Controller (Bvval tsrpath, ByVal AppPath, ByVal datapath)

Repositorysconnection.add Tsrpath

Systemutil.run AppPath

Executetestcase DataPath

Window ("Flight reservation"). Close

End Function

' Execute the use case, write the test report function

Function executetestcase (ByVal filepath)

Dim FSO, fil, txt, arr, Test_result, Result_record

Set fso = CreateObject ("Scripting.FileSystemObject")

Set fil = fso.opentextfile (filepath, ForReading)

Do and not fil. AtEndOfStream

txt = Trim (fil. ReadLine)

arr = Split (txt, "|")

Test_result = Login (arr (0), arr (1), arr (2))

Result_record = Result_record & "Username:" & arr (0) & ", password" & Arr (1) & ", TestResult----> "& Test_result & VbCrLf

Loop

Writetestreport "C:\Automation\Report\testreport.txt", Result_record

Fil.close

Set fil = Nothing

Set fso = Nothing

End Function

' Reporting functions

Function Writetestreport (ByVal filepath, ByVal str)

Dim FSO, fil

Set fso = CreateObject ("Scripting.FileSystemObject")

Set fil = fso.opentextfile (filepath, ForWriting, True)

Fil. Write Str

Fil.close

Set fil = Nothing

Set fso = Nothing

End Function

' Business logic flow, business processing functions are written in QTP, then copied

Function Login (ByVal un, ByVal pw, ByVal errmsg)

Dialog ("Login"). Winedit ("Agent Name:"). Set UN

Dialog ("Login"). Winedit ("Password:"). Set PW

Dialog ("Login"). Winbutton ("OK"). Click

If dialog ("Login"). Dialog ("Flight reservations"). Exist Then

Actuan_result = Dialog ("Login"). Dialog ("Flight reservations"). Static ("ErrMsg"). Getroproperty ("text")

If Action_result = ErrMsg Then

Login = "Pass"

Else

Login = "Fail"

End If

Dialog ("Login"). Dialog ("Flight reservations"). Winbutton ("OK"). Click

Else

If window ("Flight reservations"). Exist and errmsg = "NULL" Then

Login = "Fail"

End If

End If

End Function

Enter the following in QTP, saved under script Flight folder

Executefile "C:\Automation\Script\testdriven_flight.vbs"

QTP Automation, AOM

Runqtp.vbs

Dim Qtpapp

Set Qtpapp = CreateObject ("Quicktest.application")

Qtpapp. Launch

Qtpapp.visiable = True

Qtpapp.open "C:\Automation\Script\flight"

Qtpapp. Test.run, True

Qtpapp. Quit

Set Qtpapp = Nothing

Runtime.bat Batch processing files

At 11:54/interactive cscript C:\Automation\Controller\runQTP

Exercise1 :Simple automated test framework exercise for Windows Calculator

structure: Automation_calc

①config:windows Calculator for object files TSR

②controller:runqtp.vbs

③report: Generating Reports

④script:testdriven_clac.vbs Calc Folder

⑤testdata:testcase.xls

Runqtp.vbs

Dim Qtpapp

Set Qtpapp = CreateObject ("Quicktest.application")

Qtpapp. Launch

Qtpapp.visible = True

Qtpapp.open "C:\Automation_calc\Script\calc"

Qtpapp. Test.run, True

Qtpapp. Quit

Set Qtpapp = Nothing

Testdriven_clac.vbs

Controller "C:\AUTOMATION_CALC\CONFIG\CALC.TSR", "C:\WINDOWS\system32\calc.exe", "C:\Automation_calc\TestData\ Testcase.xls "

' File Call function

Function Controller (ByVal tsrpath,byval apppath,byval datapath)

Repositoriescollection.add Tsrpath

Systemutil.run AppPath

Executetestcase DataPath

Window ("Calculator"). Close

End Function

' Execute use case function

Function executetestcase (ByVal filepath)

Dim xlapp, Xlworkbook, Xlsheet

Dim Irowcount, Iloop, Num1,op,num2,expect_result,test_result, Result_record

Set xlapp = CreateObject ("Excel.Application")

' Xlapp.visible = True

Set xlworkbook = Xlapp.workbooks.open (filepath)

Set xlsheet = Xlworkbook.sheets ("Calc")

Irowcount = Xlsheet.usedrange.rows.count

For iloop = 2 to Irowcount

NUM1 = Xlsheet.cells (Iloop, 1)

op = Xlsheet.cells (Iloop, 2)

num2 = Xlsheet.cells (Iloop, 3)

Expect_result = Xlsheet.cells (Iloop, 4)

Test_result = calculation (Num1,op,num2,expect_result)

Result_record = Result_record & num1 & op & num2 & "=" & Expect_result & "TestResult---->" &am P Test_result & vbCrLf

Next

Writetestreport "C:\Automation_calc\Report\testreport.txt", Result_record

' Xlworkbook.save

Xlworkbook.close

xlApp.Quit

Set xlsheet = Nothing

Set xlworkbook = Nothing

Set xlapp = Nothing

End function

' Business logic functions

Function calculation (ByVal num1, ByVal op, ByVal num2, Expect_result)

Dim Actual, expect

Window ("Calculator"). Winedit ("Edit"). Type (NUM1)

Window ("Calculator"). Winbutton (OP). Click

Window ("Calculator"). Winedit ("Edit"). Type (NUM2)

Window ("Calculator"). Winbutton ("="). Click

Actual_result = window ("calculator"). Winedit ("Edit"). Getroproperty ("text")

actual = Trim (Actual_result)

arr = Split (Actual, ".")

If arr (0) = Trim (Expect_result) Then

Calculation = "Pass"

Else

Calculation = "Fail"

End If

End Function

' Reporting functions

Function Writetestreport (ByVal filepath, ByVal str)

Dim FSO, fil

Set fso = CreateObject ("Scripting.FileSystemObject")

Set fil = fso.opentextfile (filepath, 2, True)

Fil. Write Str

Fil.close

Set fil = Nothing

Set fso = Nothing

End Function

QTP Enter the following statement to save to C: \ Under the Automation_calc\script\calc folder

Executefile "C:\Automation_calc\Script\ Testdriven_clac.vbs"

Testcase.xls

Num1

Op

Num2

Expect_result

20

*

3

60

35

-

5

30

40

+

21st

61

55

/

11

5

Automated Testing (V): 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.