LoadRunner中的常用函數(shù)整理-新_第1頁
LoadRunner中的常用函數(shù)整理-新_第2頁
LoadRunner中的常用函數(shù)整理-新_第3頁
LoadRunner中的常用函數(shù)整理-新_第4頁
LoadRunner中的常用函數(shù)整理-新_第5頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

LoadRunner 中的常用函數(shù)整理中的常用函數(shù)整理 參考資料 參考資料 LoadRunner 函數(shù)大全之中文解釋 pdf 前言 前言 在使用 Loadrunner 做性能測試的過程中 發(fā)現(xiàn) Loadrunner 的函數(shù)庫真的很強大 很多 時候遇到的問題 只需要通過某一個 Loadrunner 自帶的函數(shù)就可以解決 就跟很多編程 語言自帶的庫一樣 Loadrunner 也有這么一個龐大的庫 而且在 Loadrunner 中可以直 接調(diào)用 不需事先加載 這里就對一些常用的函數(shù)進行了整理 部分函數(shù)也是 C 語言自帶的函數(shù) 但用處和 Loadrunner 的函數(shù)一樣廣泛 熟練使用這些函數(shù) 既能簡化腳本代碼 同時也可以有效 地監(jiān)控腳本運行的過程和結(jié)果 與操作有關(guān)的函數(shù)與操作有關(guān)的函數(shù) 1 web url web url 函數(shù)是一個操作函數(shù) 它可以加載指定的網(wǎng)頁 GET 請求 函數(shù) web url 可以加載 URL 屬性指定的 URL 函數(shù) web url 不需要上下文 該函數(shù)是應用最廣泛的一個函數(shù) 一般不需要手寫 通過 LR 使用瀏覽器錄制 HTTP 協(xié)議的 腳本基本上都是使用該函數(shù)與 http 服務(wù)器進行交互 定義 int web url const char Name const char url EXTRARES LAST 例子 web url favicon ico URL Resource 0 RecContentType text html Referer Snapshot t2 inf Mode HTML LAST 2 web custom request web custom request 函數(shù)是一個操作函數(shù) 通過它可以使用任意方法創(chuàng)建自定義 HTTP 請求或創(chuàng)建正文 默認情況下 VuGen 只為無法用其他 Web 函數(shù)解釋的請求生 成該函數(shù) 這個函數(shù)通常是手工編寫腳本用的 當與 http 服務(wù)器交互不是通過瀏覽器進行交互 就會用到該函數(shù) 比如基于 soap 協(xié)議的 xml 格式或者 json 格式的消息交互 定義 int web custom request const char RequestName EXTRARES LAST 例子 基于 xml 格式的消息交互 web custom request services4 URL http 172 16 91 251 8080 web tr069 Method POST Resource 0 RecContentType text xml Mode HTML EncType text xml charset utf 8 Body 3 PicUpdate 9010 DATE T begin time1 DATE T TIME Snapshot t1402309446 inf LAST 基于 json 格式的消息交互 web custom request BOOT URL http 172 16 37 201 8080 Qcs acs boot Method POST TargetFrame Resource 0 RecContentType text xml Referer Mode HTTP Body eventType eventCode 1 subEvent 0 deviceId serviceUser service user mac mac manufacturer Manufacturer oui 00D0D0 productClass STB serialNumber 00100199007011400002D0154AD783F2 errorcode 1 currentTime 2013 11 06 01 47 07 baseParameterList connectionURL http 172 16 18 203 7070 pppoeUser not used version 2 06 05 07 epgServerUrl http 58 223 255 211 8080 FEC 0 hardwareVersion ZXB600V4A STBSD ST5205 000 softwareVersion V40232961 LAST 使用 web custom request 發(fā)送一個空消息 web custom request nullmessage Method POST URL http 172 16 37 151 8080 web tr069 RecContentType text xml Snapshot t4 inf LAST soap request soap request 函數(shù)執(zhí)行一個 SOAP 請求 它向指定的 URL 發(fā)送 SOAP 包 并接收服 務(wù)器響應 除了上面可以使用 web custom request 函數(shù)模擬 soap 消息發(fā)送以外 通過 soap request 函數(shù)也可以模擬 soap 消息發(fā)送 該函數(shù)只有在協(xié)議選擇 Web Services 的腳本里面才可以使用 它區(qū)別于 Web HTTP HTML 協(xié)議 如果選擇 Web HTTP HTML 協(xié) 議 則需要使用 web custom request 函數(shù) 使用 Web Services 協(xié)議的一個好處是可 以直接將 xml 文件導入到腳本當中 而 Web HTTP HTML 協(xié)議不支持導入 xml 格式文件 但壞處是使用 Web Services 協(xié)議的 Vuser 屬于 Global 的 Vuser 默認的 Global Vuser 的 license 只有 100 而使用 Web HTTP HTML 的 Web User 則可以達到 10000 因此 對于 soap 協(xié)議消息交互 還是建議使用 Web HTTP HTML 協(xié)議 手工編寫腳本 定義 int soap request const char StepName URL LAST 例子 soap request StepName SOAP Request URL http 172 16 37 151 8080 web tr069 SOAPEnvelope 1234 0 SOAPAction ResponseParam response Snapshot t1400577097 inf LAST 3 web link web link 函數(shù)是一個操作函數(shù) 它模擬鼠標單擊由屬性定義的鏈接 web link 只能在上 一個操作的上下文中執(zhí)行 該函數(shù)可以通過腳本錄制自動生成 對于 web 頁面鏈接性質(zhì)的頁面元素 就可以使用該 函數(shù) 比如一個下載鏈接 定義 int web link const char StepName EXTRARES LAST 例子 web link update zip Text update zip LAST 4 web cleanup cookies web cleanup cookies 函數(shù)刪除腳本使用的所有當前存儲的 Cookie 定義 int web cleanup cookies 與日志有關(guān)的函數(shù)與日志有關(guān)的函數(shù) 5 lr message lr message 函數(shù)將消息發(fā)送到日志文件和輸出窗口 在 VuGen 中運行時 輸出文件為 output txt 定義 int lr message const char format exp1 exp2 expn 例子 lr message The begin time is s begin time 6 lr output message lr output message 函數(shù)將帶有腳本部分和行號的消息發(fā)送到輸出窗口和日志文件 定義 int lr output message const char format exp1 exp2 expn 例子 lr output message The begin time is s begin time 7 lr error message lr error message 函數(shù)將錯誤消息發(fā)送到輸出窗口和 Vuser 日志文件 要發(fā)送不是特定 錯誤消息的特殊通知 請使用 lr output message 定義 int lr error message const char format exp1 exp2 expn 例子 lr error message Error 2 The response is not null before updating 8 lr log message lr log message 函數(shù)將消息發(fā)送到 Vuser 或代理日志文件 取決于應用程序 通過向 日志文件發(fā)送錯誤消息或其他信息性消息 可以將該函數(shù)用于調(diào)試 定義 int lr log message const char format exp1 exp2 expn 例子 lr log message The begin time is s begin time 四者的關(guān)系和區(qū)別 四個日志函數(shù)都會記錄日志到 mdrv log 和 output txt 文件當中 所不同的是 lr log message 由日志開關(guān)控制 其他三個不由日志開關(guān)控制 只有在 Run time Setting 中選中 enable logging 才會日志 lr log message 的日志 lr error log 除了 日志錯誤日志以外 還會在 controller 中生成響應的 error 記錄 因此 當需要記錄某個 異常的時候 建議使用 lr error message lr message 與 lr output message 的區(qū)別在 于后者會顯示腳本信息和行數(shù) 前者則不會顯示 如 The begin time is 09 44 12 對應 lr message before update c 19 The begin time is 09 44 12 對應 lr output message 與事務(wù)有關(guān)的函數(shù)與事務(wù)有關(guān)的函數(shù) 9 lr start transaction lr start transaction 函數(shù)標記事務(wù)的開始 要指明要分析的事務(wù) 請使用函數(shù) lr start transaction 和 lr end transaction 應緊接事務(wù)前后插入這些函數(shù) 定義 int lr start transaction const char transaction name 例子 lr start transaction download 10 lr end transaction lr end transaction 函數(shù)標記事務(wù)的結(jié)束 并錄制執(zhí)行事務(wù)所用的時間量 要指明希望分 析的事務(wù) 請在事務(wù)之前放置 lr start transaction 函數(shù) 并在事務(wù)之后放置 lr end transaction 函數(shù) 定義 int lr end transaction const char transaction name int status 例子 lr end transaction download LR PASS lr end transaction download LR FAIL lr end transaction download LR AUTO 自動錄制的腳本是不會生成該函數(shù)的 如果不添加該函數(shù) 可以在 Run time Setting 中的 miscellaneous 中選擇 define each action as a transaction 但不建議這樣做 添 加事務(wù)函數(shù)可以更加精確的定義某個事務(wù)的起始結(jié)束時間點 這個時間點不一定是某個 action 的起始結(jié)束時間 還可以配合 if 條件語句有效控制該事務(wù)是成功還是失敗 與返回消息有關(guān)的函數(shù)與返回消息有關(guān)的函數(shù) 11 web reg save param web reg save param 是一個注冊類型的函數(shù) 它注冊一個請求 以在檢索到的響應消 息中查找并保存一個文本字符串 只有在執(zhí)行了下一個操作函數(shù) 如 web url 后才會執(zhí) 行該操作 其主要作用是將返回消息中的某個字符串存入一個參數(shù) 用來做后續(xù)使用 比如發(fā)送下一 條消息必須攜帶上一條消息中返回的 session id 這個函數(shù)就能派上用場 或者對返回的消 息的某個字段進行校驗 定義 int web reg save param const char ParamName LAST 例子 web reg save param return length2 LB Content Length RB r n Ord ALL LAST 其中 LR 為左邊界 RB 為右邊界 Ord 為查找到匹配值的順序 默認為 1 如果 Ord ALL 表示會將所有查找到的匹配值保存到一個 list 當中 比如返回消息如下 HTTP 1 1 200 OK r n Server Apache Coyote 1 1 r n X Powered By Servlet 3 0 JBossAS 6 r n Content Length 0 r n Date Fri 18 Jul 2014 02 35 47 GMT r n r n 則上述函數(shù)會將 Content Length 的長度 0 存到 return length2 這個參數(shù)當中 12 web get int property web get int property 函數(shù)返回關(guān)于最后一個 HTTP 請求的指定信息 如果一個操作函 數(shù)返回所條響應消息 則只取最后一個響應詳細的結(jié)果 該函數(shù)可以指定的返回消息類型 HTTP INFO RETURN CODE HTTP 請求響應碼 如 200 404 HTTP INFO DOWNLOAD SIZE HTTP 請求響應大小 包含消息頭和消息體 HTTP INFO DOWNLOAD TIME 最后一個 http 請求返回的下載時長 單位為毫秒 定義 int web get int property const int HttpInfoType 例子 int flen flen web get int property HTTP INFO DOWNLOAD SIZE 13 web reg find web reg find 函數(shù)注冊一個請求 以在下一個操作函數(shù) 如 web url 檢索到的網(wǎng)頁上 搜索一個文本字符串 這個與 web reg save param 有些類似 也是從下一個操作函數(shù)中從返回中取出一個文 本字符串 所不同的是從返回的消息當中查找某個字符串 而并不需要該字符串位于某個 特定位置 也就是存在固定的左右邊界 而且可以將查找到的次數(shù)保存在相應的參數(shù)當中 需要注意的是 如果查詢的字符為中文字符 在錄制前 需要在 option 中選擇編碼格式 為 UTF 8 定義 int web reg find const char attribute list LAST 例子 web reg find Text 知道 SaveCount para count LAST 與參數(shù)有關(guān)的函數(shù)與參數(shù)有關(guān)的函數(shù) 14 lr eval string lr eval string 函數(shù)在評估任何嵌入的參數(shù)之后返回輸入字符串 如果字符串實參 argument 只包含一個形參 parameter 該函數(shù)返回形參的當前值 這個函數(shù)主要用來取出某個參數(shù)的值 在 Loadrunner 中 對于參數(shù)替換 是無法在除了 操作函數(shù)以外直接使用參數(shù)的 必須將參數(shù)放入這個函數(shù)才能表示該參數(shù)的值 定義 char lr eval string const char instring 例子 begin time lr eval string TIME 取出時間參數(shù)在本次迭代的值 并存入 begin time lr vuser status message before iteration s MAC is s lr eval string iteration lr eval string MAC 取出當前迭代次數(shù)并打印在消 息中 15 lr save string lr save string 函數(shù)將指定的以 null 終止的字符串賦給參數(shù) 該函數(shù)可用于關(guān)聯(lián)查詢 要 確定參數(shù)值 請使用函數(shù) lr eval string 這個參數(shù)跟 lr eval string 正好相反 是將某個值存入?yún)?shù)當中 以在消息中使用該參數(shù) 定義 int lr save string const char param value const char param name 例子 begin time lr eval string TIME lr save string begin time begin time1 這里需要解釋下 這樣用的原因 因為 TIME 參數(shù)設(shè)置的是每次出現(xiàn)都做一次更新 每次 調(diào)用 TIME 參數(shù)都會返回不同的值 為了使用最初的 TIME 值 則必須將 TIME 參數(shù)值取出 來以后保存在另一個參數(shù)當中 16 lr save int lr save int 函數(shù)將指定的數(shù)值型變量賦給字符串參數(shù) 定義 int lr save int int value const char param name 例子 lr save int time 上述函數(shù)的意義是將當前時間距離 1970 01 01 的秒數(shù)存入 times 參數(shù)當中 與時間有關(guān)的函數(shù)與時間有關(guān)的函數(shù) 17 lr save datetime lr save datetime 函數(shù)將當前日期和時間 或具有指定偏移的日期和時間保存在參數(shù)中 如果達到 MAX DATETIME LEN 個字符 結(jié)果字符串將截斷 定義 void lr save datetime const char format int offset const char name 例子 lr save datetime Y m d H M S DATE NOW TIME NOW times 上述例子中的函數(shù)將當前時間以固定格式存儲在字符串變量 times 中 18 time 為 C 語言自帶函數(shù) 根據(jù)系統(tǒng)時鐘 time 函數(shù)返回從世界標準時間 1970 年 1 月 1 日 子夜 00 00 00 作為開始所經(jīng)過的秒數(shù) 返回值存儲在 timeptr 所給出的位置 如果 timeptr 為 NULL 則該值不會被存儲 定義 time t time time t timeptr 例子 typedef long time t time t t Get system time and display as number and string lr message Time in seconds since 1 1 70 ld n time lr message Formatted time and date s ctime 19 ctime 為 C 語言自帶函數(shù) 在 Unix 下 ctime 不是線程級安全函數(shù) 所以 請使用 ctime r 有關(guān)詳細信息 請參閱平臺相關(guān)文檔 定義 char ctime const time t time 例子 typedef long time t time t t Get system time and display as number and string lr message Time in seconds since 1 1 70 ld n time lr message Formatted t

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論