日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

自動化測試(五):自動化測試框架

系統(tǒng) 1913 0

框架(可復用的函數(shù)、方法)類型:

???????? ① 數(shù)據(jù)驅動(用測試數(shù)據(jù)去驅動腳本的運行, 測試腳本和數(shù)據(jù)的分離 ???)

???????? ② 關鍵字驅動(object.action(param),抽象程度更高,業(yè)務邏輯、腳本、數(shù)據(jù)的分離)

結構: Automation

???????? ① AUT:配置文件,xml文件

???????? ② Config(Object Repository):對象,tsr文件(flighr.tsr)

???????? ③ TestData:測試數(shù)據(jù),即測試用例,txt文件(flight_testcase.txt)

???????? ④ Script:測試腳本,讀取Test Data,傳給Execute Testcase,傳給業(yè)務處理,得到結果,傳給Report,vbs文件(testdriven_flight.vbs,flight文件夾)

???????? ⑤ Report

???????? ⑥ Log

???????? ⑦ Exception

???????? ⑧ Controller文件調用(runQTP.vbs,runtime.bat)

?

注: 業(yè)務處理函數(shù)在QTP里面寫,再復制

?

flight_testcase.txt

|mercury|Please enter agent name

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

|mercury|Please enter passwoed

mercury|mercury|null

?

testdriven_flight.vbs

Const Forreading = 1

Const ForWriting = 2

Const ForAppending= 8

?

’文件調用

Controller "C:\Automation_Flight\Config\login_flight.tsr","D:\Software\QTP10\samples\flight\app\flight4a.exe","C:\Automation_Flight\TestData\flight_testcase.txt"

’文件調用函數(shù)

Function Controller(BvVal tsrPath, ByVal appPath, ByVal datapath)

???????? RepositorysConnection.Add tsrPath

???????? Systemutil.Run appPath

???????? ExecuteTestCase datapath

???????? Window(“Flight Reservation”).close

End Function

?

’執(zhí)行用例、寫入測試報告函數(shù)

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 while 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

?

’報告函數(shù)

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

?

’業(yè)務邏輯流程,業(yè)務處理函數(shù)在QTP里面寫,再復制

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("確定").Click

???????? else

???????? ???????? If window("Flight Reservations").exist and errmsg = "null" Then

???????? ???????? ???????? Login = "Fail"

???????? ???????? End If

???????? End If

End Function

?

在QTP中輸入以下內容,保存在script下面的flight文件夾下

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

?

QTP自動化,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 批處理文件

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

?

Exercise1 windows計算器的簡單自動化測試框架練習

結構: Automation_calc

???????? ① Config:windows計算器的對象文件tsr

???????? ② Controller:runQTP.vbs

???????? ③ Report:生成報告

???????? ④ Script:testdriven_clac.vbs? calc文件夾

???????? ⑤ 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"

?

'文件調用函數(shù)

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

???????? RepositoriesCollection.Add tsrpath

???????? SystemUtil.Run apppath

???????? ExecuteTestCase datapath

???????? Window("計算器").Close

End Function

?

'執(zhí)行用例函數(shù)

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---->" & 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

?

'業(yè)務邏輯函數(shù)

Function Calculation(ByVal num1, ByVal op, ByVal num2, expect_result)

?? Dim actual , expect

???????? window("計算器").WinEdit("Edit").Type(num1)

???????? window("計算器").WinButton(op).Click

???????? window("計算器").WinEdit("Edit").Type(num2)

???????? window("計算器").WinButton("=").Click

???????? actual_result = window("計算器").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

?

'報告函數(shù)

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輸入以下語句,保存到C:\ Automation_calc\Script\calc文件夾下

executeFile "C:\Automation_calc\Script\ testdriven_clac.vbs"

?

testcase.xls

num1

op

num2

expect_result

20

*

3

60

35

-

5

30

40

+

21

61

55

/

11

5

自動化測試(五):自動化測試框架


更多文章、技術交流、商務合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 临西县| 玉屏| 张北县| 岱山县| 璧山县| 江城| 温泉县| 兴业县| 惠州市| 进贤县| 如皋市| 周至县| 花垣县| 肇州县| 北碚区| 旅游| 拉萨市| 神农架林区| 上杭县| 武鸣县| 长治县| 禹州市| 仁寿县| 崇文区| 阿拉善盟| 塔河县| 阜南县| 南京市| 保康县| 淮南市| 梨树县| 胶州市| 宝应县| 丰县| 玛沁县| 昭觉县| 兴城市| 元谋县| 新邵县| 陈巴尔虎旗| 铜鼓县|