亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

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

系統 1633 0

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

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

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

結構: Automation

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

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

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

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

???????? ⑤ Report

???????? ⑥ Log

???????? ⑦ Exception

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

?

注: 業務處理函數在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"

’文件調用函數

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

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

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

???????? ExecuteTestCase datapath

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

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

?

’報告函數

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

?

’業務邏輯流程,業務處理函數在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"

?

'文件調用函數

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

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

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

???????? ExecuteTestCase datapath

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

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

?

'業務邏輯函數

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

?

'報告函數

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

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


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

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

【本文對您有幫助就好】

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

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲欧美日韩专区一 | 男女一级特黄a大片 | 九九热最新视频 | 久久久久久a亚洲欧洲aⅴ | 欧美一级美片在线观看免费 | 日韩欧美色视频 | 农村妇女又色黄一级毛片 | 亚洲精品久久久久久小说 | 国产一区在线视频观看 | 亭亭色| 成人网18免费网站在线 | 日本不卡免费高清一级视频 | 国产高清不卡 | 99热这里只有精品4 99热这里只有精品5 | 欧美日本一区 | 97国产 | 日韩欧美亚洲在线 | 免费爱爱视频网站 | 久久精品久久久久 | 日本在线亚州精品视频在线 | 天天夜天天干 | 欧美在线观看一区 | 午夜亚洲精品久久久久久 | 四虎影院在线免费 | 国产精品成人一区二区三区 | 99久久成人国产精品免费 | 成人毛片18岁女人毛片免费看 | 国产美女免费观看 | 久久亚洲国产午夜精品理论片 | 欧美日韩激情在线一区二区 | 狠狠色丁香久久婷婷 | 成人网视频在线观看免费 | 一道本免费视频 | 亚洲欧洲日本在线 | 亚洲精品久久激情影院 | 欧美日韩成人 | 日本大片免a费观看在线 | 国产色婷婷精品综合在线 | 超级乱淫视频播放日韩 | 亚洲另类 专区 欧美 制服 | 欧美综合色区 |