上面的程序,我分别录制了百度、谷歌、有道访问三个网的首页的代码,我想在运行脚本时,随机的去访问其中一个网站,如何做呢?我们通过随机函数,随机出1~3之间的整数,根据随机来的结果,然后执行switch语句中的代码。
下面来看我的结果
为了查看脚本结果更清晰,我在每一段脚本前面加了一个集合点“lr_rendezvous”函数。
Starting iteration 1. Starting action Action. Action.c(57): Rendezvous 访问有道集合点 Action.c(59): Downloading resource "http://shared.ydstatic.com/oxo/p/pic.gif" (specified by argument number 9) [MsgId: MMSG-26577] Action.c(59): Downloading resource "http://shared.ydstatic.com/oxo/p/logo.png?1" (specified by argument number 11) [MsgId: MMSG-26577] Action.c(59): Downloading resource "http://shared.ydstatic.com/oxo/p/nv_line.gif" (specified by argument number 13) [MsgId: MMSG-26577] Action.c(59): Downloading resource "http://shared.ydstatic.com/r/2.0/p/pic.gif" (specified by argument number 15) [MsgId: MMSG-26577] Action.c(59): Found resource "http://shared.ydstatic.com/dao/search/outweb/js/yd.js?201207131" in HTML "http://www.youdao.com/" [MsgId: MMSG-26659] Action.c(59): Found resource "http://shared.ydstatic.com/dao/search/outweb/js/nav.js?201207131" in HTML "http://www.youdao.com/" [MsgId: MMSG-26659] Action.c(59): Found resource "http://shared.ydstatic.com/dao/search/outweb/js/suggest.js?201207131" in HTML "http://www.youdao.com/" [MsgId: MMSG-26659] Action.c(59): web_url("www.youdao.com") was successful, 30006 body bytes, 3347 header bytes, 39 chunking overhead bytes [MsgId: MMSG-26385] Ending action Action. Ending iteration 1. |
通过脚本读取文件
为了增加语言的强大,高级语言不可以把一个程序的实现从头到尾写到文件里,这样可读性和维护很差,也无法实现团队发,肯定会相互调用接口函数库等。当然,读取文件也是常用的操作,下面我们来看一个读取文件的例子。
我们事先准备一个文件test.txt ,里面随便你输入些什么内容吧!
Action() int count,total=0; //判断是否可以读取文件 return -1; while(!feof(file_stream)) } |
上面的代码中我加了注释,这里没必须再做解释。
下面来看我的运行结果:
Starting iteration 1. Starting action Action. Action.c(24): 文件的前50字符:01234567890123456789012345678901234567890123456789 Ending action Action. Ending iteration 1. |
LoadRunner难么?对于有编程基础的一点都不都。我们所要做的就是熟悉LoadRunner的常用函数罢了。
一篇看不够?你需要的是这门系统专业课程: