loadrunner程序编写

性能测试流程

需求调研(性能的测试指标

设计性能测试场景(频繁使用的功能 核心业务 接口 混合

搭建环境(模拟真实的用户

开发脚本

  检查点:对结束事务进行判断,默认结束状态是LR_AUTO

  参数化:模拟真实用户使用

  关联:服务器返回的动态参数

  集合点:做并发测试

场景设计:单业务开发。核心业务并发、第三方接口、混合场景,监控服务器资源(cpu.内存,磁盘网络)

执行场景:发现问题,挑有

性能测试报告

一.脚本编写

案例一(登录注册手写脚本)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

Action()

{

    //请求1

    web_custom_request("WebTours"//可以自定义

    "URL=http://127.0.0.1:1080/WebTours/", //Get请求的地址

    "Method=GET"//方式GET

    "Resource=0"//说明URL是否是一个资源,0代表不是资源,1代表是资源

    "RecContentType=text/html"//录制时响应报头文本类型

    "Snapshot=t1.inf"//录制快照保存到t1.inf中

    "Mode=HTTP"//录制的模式HTTP

    LAST);

    //请求2

    web_custom_request("header.html"//可以自定义

    "URL=http://127.0.0.1:1080/WebTours/header.html", //Get请求的地址

    "Method=GET"//方式GET

    "Resource=0"//说明URL是否是一个资源,0代表不是资源,1代表是资源

    "RecContentType=text/html"//录制时响应报头文本类型

    "Snapshot=t2.inf"//录制快照保存到t2.inf中

    "Mode=HTTP"//录制的模式HTTP

    LAST);

 

    //请求3

    web_custom_request("signOff=true"//可以自定义

    "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true", //Get请求的地址

    "Method=GET"//方式GET

    "Resource=0"//说明URL是否是一个资源,0代表不是资源,1代表是资源

    "RecContentType=text/html"//录制时响应报头文本类型

    "Snapshot=t3.inf"//录制快照保存到t3.inf中

    "Mode=HTTP"//录制的模式HTTP

    LAST);

    //关联函数

    web_reg_save_param_ex("Paramname=userSession",

    "LB=name=userSession value=",

    "RB=>",

    LAST);

 

    //请求4

    web_custom_request("in=home"//可以自定义

    "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home", //Get请求的地址

    "Method=POST"//方式GET

    "Resource=0"//说明URL是否是一个资源,0代表不是资源,1代表是资源

    "RecContentType=text/html"//录制时响应报头文本类型

    "Snapshot=t4.inf"//录制快照保存到t4.inf中

    "Mode=HTTP"//录制的模式HTTP

    LAST);

 

    //请求5

    web_custom_request("home.html"//可以自定义

    "URL=http://127.0.0.1:1080/WebTours/home.html", //Get请求的地址

    "Method=GET"//方式GET

    "Resource=0"//说明URL是否是一个资源,0代表不是资源,1代表是资源

    "RecContentType=text/html"//录制时响应报头文本类型

    "Snapshot=t5.inf"//录制快照保存到t5.inf中

    "Mode=HTTP"//录制的模式HTTP

    LAST);

     

    lr_start_transaction("登录");

 

    //POST

    web_custom_request("login.pl"//可以自定义

    "URL=http://127.0.0.1:1080/WebTours/login.pl", //Get请求的地址

    "Method=POST"//方式GET

    "Resource=0"//说明URL是否是一个资源,0代表不是资源,1代表是资源

    "RecContentType=text/html"//录制时响应报头文本类型

    "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home", //请求的页面,在URL写明后,该属性无效可省略

    "Snapshot=t6.inf"//录制快照保存到t6.inf中

    "Mode=HTTP"//录制的模式HTTP

        "Body=userSession={userSession}&username=test001&password=123456",

    LAST);

 

 

    //请求7

    web_custom_request("in=home"//可以自定义

    "URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home", //Get请求的地址

    "Method=GET"//方式GET

    "Resource=0"//说明URL是否是一个资源,0代表不是资源,1代表是资源

    "RecContentType=text/html"//录制时响应报头文本类型

    "Snapshot=t7.inf"//录制快照保存到t7.inf中

    "Mode=HTTP"//录制的模式HTTP

    LAST);

 

    //检查点

    web_reg_find("Text=Welcome, <b>test001</b>,",

                   "Savecount=登录计数",

                   LAST);

 

    //请求8

    web_custom_request("tro=true"//可以自定义

    "URL=http://127.0.0.1:1080/WebTours/login.pl?intro=true", //Get请求的地址

    "Method=GET"//方式GET

    "Resource=0"//说明URL是否是一个资源,0代表不是资源,1代表是资源

    "RecContentType=text/html"//录制时响应报头文本类型

    "Snapshot=t8.inf"//录制快照保存到t8.inf中

    "Mode=HTTP"//录制的模式HTTP

    LAST);<br>

    //判断登录成功与否

      if(atoi(lr_eval_string("{登录计数}")) >0){

            lr_end_transaction("登录", LR_PASS);

      }else{

            lr_end_transaction("登录", LR_FAIL);

      }

 

    //请求9

    web_custom_request("signOff=1"//可以自定义

    "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1", //Get请求的地址

    "Method=GET"//方式GET

    "Resource=0"//说明URL是否是一个资源,0代表不是资源,1代表是资源

    "RecContentType=text/html"//录制时响应报头文本类型

    "Snapshot=t9.inf"//录制快照保存到t9.inf中

    "Mode=HTTP"//录制的模式HTTP

    LAST);

 

    //请求10

    web_custom_request("in=home"//可以自定义

    "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home", //Get请求的地址

    "Method=GET"//方式GET

    "Resource=0"//说明URL是否是一个资源,0代表不是资源,1代表是资源

    "RecContentType=text/html"//录制时响应报头文本类型

    "Snapshot=t10.inf"//录制快照保存到t10.inf中

    "Mode=HTTP"//录制的模式HTTP

    LAST);<br>

    //请求11

    web_custom_request("home.html"//可以自定义

    "URL=http://127.0.0.1:1080/WebTours/home.html", //Get请求的地址

    "Method=GET"//方式GET

    "Resource=0"//说明URL是否是一个资源,0代表不是资源,1代表是资源

    "RecContentType=text/html"//录制时响应报头文本类型

    "Snapshot=t11.inf"//录制快照保存到t11.inf中

    "Mode=HTTP"//录制的模式HTTP

    LAST);

 

    return 0;

}

案例二(登录注册手写脚本使用web_custom_request)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

Action()

{

//请求1

    web_url("WebTours",

    "URL=http://127.0.0.1:1080/WebTours/",

    //"TargetFrame=",

    //"TargetBrowser=Mercury Technologies",

    "Resource=0",

    "RecContentType=text/html",

    "Snapshot=t1.inf",

    "Mode=HTTP",

    LAST );

//请求2

  web_url("header.html",

    "URL=http://127.0.0.1:1080/WebTours/header.html",

    //"TargetFrame=",

    //"TargetBrowser=Mercury Technologies",

    "Resource=0",

    "RecContentType=text/html",

    "Snapshot=t2.inf",

    "Mode=HTTP",

    LAST );<br>//请求3

  web_url("welcome.pl?signOff=true",

    "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true",

    //"TargetFrame=",

    //"TargetBrowser=Mercury Technologies",

    "Resource=0",

    "RecContentType=text/html",

    "Snapshot=t3.inf",

    "Mode=HTTP",

    LAST );

 

//插入关联函数<input type=hidden name=userSession value=119191.457108141zVDAQVApfHfDzHifptzDtf>

  web_reg_save_param_ex("Paramname=userSession",

  "LB=name=userSession value=",

  "RB=>",

  LAST);<br>

//请求4

  web_url("in=home",

    "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home",

    //"TargetFrame=",

    //"TargetBrowser=Mercury Technologies",

    "Resource=0",

    "RecContentType=text/html",

    "Snapshot=t4.inf",

    "Mode=HTTP",

    LAST );

//请求5

   web_url("home.html",

    "URL=http://127.0.0.1:1080/WebTours/home.html",

    //"TargetFrame=",

    //"TargetBrowser=Mercury Technologies",

    "Resource=0",

    "RecContentType=text/html",

    "Snapshot=t5.inf",

    "Mode=HTTP",

    LAST );

  lr_start_transaction("登录");

//post提交<br>

   web_submit_data("login.pl",

    "Action=http://127.0.0.1:1080/WebTours/login.pl",

    "Method=POST",

    "RecContentType=text/html",

    "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",

    "Snapshot=t6.inf",

    "Mode=HTTP",

    ITEMDATA,

    "Name=username""Value=test001", ENDITEM,

    "Name=password""Value=123456", ENDITEM,

    "Name=userSession""Value={userSession}", ENDITEM,

    LAST ); <br>

//请求7

  web_url("nav.pl?page=menu&in=home",

    "URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",

    //"TargetFrame=",

    //"TargetBrowser=Mercury Technologies",

    "Resource=0",

    "RecContentType=text/html",

    "Snapshot=t7.inf",

    "Mode=HTTP",

    LAST );

 

//检查点 Welcome, <b>test001</b>,

    web_reg_find("Text=Welcome, <b>test001</b>,",

                 "Savecount=登录计数",

                 LAST);

//请求8

  web_url("login.pl?intro=true",

    "URL=http://127.0.0.1:1080/WebTours/login.pl?intro=true",

    //"TargetFrame=",

    //"TargetBrowser=Mercury Technologies",

    "Resource=0",

    "RecContentType=text/html",

    "Snapshot=t8.inf",

    "Mode=HTTP",

    LAST );<br>//判断登录成功与否

    if(atoi(lr_eval_string("{登录计数}")) >0){

            lr_end_transaction("登录", LR_PASS);

    }else{

            lr_end_transaction("登录", LR_FAIL);

    }

    //lr_end_transaction("登录", LR_AUTO);

 

//请求9

  web_url("welcome.pl?signOff=1",

    "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1",

    //"TargetFrame=",

    //"TargetBrowser=Mercury Technologies",

    "Resource=0",

    "RecContentType=text/html",

    "Snapshot=t9.inf",

    "Mode=HTTP",

    LAST );

 

//请求10

  web_url("nav.pl?in=home",

    "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home",

    //"TargetFrame=",

    //"TargetBrowser=Mercury Technologies",

    "Resource=0",

    "RecContentType=text/html",

    "Snapshot=t10.inf",

    "Mode=HTTP",

    LAST );

 

//请求11

  web_url("home.html",

    "URL=http://127.0.0.1:1080/WebTours/home.html",

    //"TargetFrame=",

    //"TargetBrowser=Mercury Technologies",

    "Resource=0",

    "RecContentType=text/html",

    "Snapshot=t11.inf",

    "Mode=HTTP",

    LAST );

 

    return 0;

}

案例三(随机订票方法一——选项固定)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

Action()

{

 

    web_url("WebTours",

        "URL=http://127.0.0.1:1080/WebTours/",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=",

        "Snapshot=t1.inf",

        "Mode=HTTP",

        LAST);

 

    web_url("header.html",

        "URL=http://127.0.0.1:1080/WebTours/header.html",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/",

        "Snapshot=t2.inf",

        "Mode=HTTP",

        LAST);

 

    web_url("welcome.pl",

        "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/",

        "Snapshot=t5.inf",

        "Mode=HTTP",

        LAST);

 

    web_url("home.html",

        "URL=http://127.0.0.1:1080/WebTours/home.html",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true",

        "Snapshot=t6.inf",

        "Mode=HTTP",

        LAST);

 

//关联usersession

    web_reg_save_param_ex(

        "ParamName=usersession",

        "LB=userSession value=",

        "RB=>\n<table border",

        SEARCH_FILTERS,

        "Scope=All",

        LAST);

    web_url("nav.pl",

        "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true",

        "Snapshot=t7.inf",

        "Mode=HTTP",

        LAST);

 

    lr_start_transaction("登录");

 

    web_submit_data("login.pl",

        "Action=http://127.0.0.1:1080/WebTours/login.pl",

        "Method=POST",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",

        "Snapshot=t9.inf",

        "Mode=HTTP",

        ITEMDATA,

        "Name=userSession""Value={usersession}", ENDITEM,

        "Name=username""Value=test002", ENDITEM,

        "Name=password""Value=123456", ENDITEM,

        "Name=JSFormSubmit""Value=off", ENDITEM,

        "Name=login.x""Value=53", ENDITEM,

        "Name=login.y""Value=11", ENDITEM,

        LAST);

 

 

    web_url("nav.pl_2",

        "URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/login.pl",

        "Snapshot=t10.inf",

        "Mode=HTTP",

        LAST);

 

    web_reg_find("Text=Welcome, <b>test002</b>, ",

        "Fail=NotFound",

        "SaveCount=登录次数",

        "Search=Body",

        LAST);

    web_url("login.pl_2",

        "URL=http://127.0.0.1:1080/WebTours/login.pl?intro=true",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/login.pl",

        "Snapshot=t14.inf",

        "Mode=HTTP",

        LAST);

 

    if(atoi(lr_eval_string("{登录次数}")) >0){

    lr_end_transaction("登录", LR_PASS);

    }else{

    lr_end_transaction("登录", LR_FAIL);

    };

 

    lr_start_transaction("订票");

 

    lr_think_time(12);

 

 

 

//关联地址

 

    web_reg_save_param_ex(

        "ParamName=目的地",

        "LB=option value=\"",

        "RB=\">",

        "Ordinal={randomnumber}",

        SEARCH_FILTERS,

        "Scope=All",

         

        LAST);

lr_output_message("目的地的值是: ",lr_eval_string("目的地"));

    web_url("reservations.pl",

        "URL=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?page=search",

        "Snapshot=t17.inf",

        "Mode=HTTP",

        LAST);

 

    web_url("Search Flights Button",

        "URL=http://127.0.0.1:1080/WebTours/welcome.pl?page=search",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",

        "Snapshot=t16.inf",

        "Mode=HTTP",

        LAST);

    web_url("nav.pl_3",

        "URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?page=search",

        "Snapshot=t18.inf",

        "Mode=HTTP",

        LAST);

 

    web_submit_data("reservations.pl_2",

        "Action=http://127.0.0.1:1080/WebTours/reservations.pl",

        "Method=POST",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome",

        "Snapshot=t22.inf",

        "Mode=HTTP",

        ITEMDATA,

        "Name=advanceDiscount""Value=0", ENDITEM,

        "Name=depart""Value=Denver", ENDITEM,

        "Name=departDate""Value=08/20/2016", ENDITEM,

        "Name=arrive""Value={目的地}", ENDITEM,

        "Name=returnDate""Value=08/21/2016", ENDITEM,

        "Name=numPassengers""Value=1", ENDITEM,

        "Name=seatPref""Value=None", ENDITEM,

        "Name=seatType""Value=Coach", ENDITEM,

        "Name=.cgifields""Value=roundtrip", ENDITEM,

        "Name=.cgifields""Value=seatType", ENDITEM,

        "Name=.cgifields""Value=seatPref", ENDITEM,

        "Name=findFlights.x""Value=55", ENDITEM,

        "Name=findFlights.y""Value=5", ENDITEM,

        LAST);

 

 

    web_submit_data("reservations.pl_3",

        "Action=http://127.0.0.1:1080/WebTours/reservations.pl",

        "Method=POST",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/reservations.pl",

        "Snapshot=t24.inf",

        "Mode=HTTP",

        ITEMDATA,

        "Name=outboundFlight""Value=031;224;08/20/2016", ENDITEM,

        "Name=numPassengers""Value=1", ENDITEM,

        "Name=advanceDiscount""Value=0", ENDITEM,

        "Name=seatType""Value=Coach", ENDITEM,

        "Name=seatPref""Value=None", ENDITEM,

        "Name=reserveFlights.x""Value=75", ENDITEM,

        "Name=reserveFlights.y""Value=4", ENDITEM,

        LAST);

 

    web_submit_data("reservations.pl_4",

        "Action=http://127.0.0.1:1080/WebTours/reservations.pl",

        "Method=POST",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/reservations.pl",

        "Snapshot=t25.inf",

        "Mode=HTTP",

        ITEMDATA,

        "Name=firstName""Value=m", ENDITEM,

        "Name=lastName""Value=m", ENDITEM,

        "Name=address1""Value=m", ENDITEM,

        "Name=address2""Value=m", ENDITEM,

        "Name=pass1""Value=m m", ENDITEM,

        "Name=creditCard""Value=", ENDITEM,

        "Name=expDate""Value=", ENDITEM,

        "Name=oldCCOption""Value=", ENDITEM,

        "Name=numPassengers""Value=1", ENDITEM,

        "Name=seatType""Value=Coach", ENDITEM,

        "Name=seatPref""Value=None", ENDITEM,

        "Name=outboundFlight""Value=031;224;08/20/2016", ENDITEM,

        "Name=advanceDiscount""Value=0", ENDITEM,

        "Name=returnFlight""Value=", ENDITEM,

        "Name=JSFormSubmit""Value=off", ENDITEM,

        "Name=.cgifields""Value=saveCC", ENDITEM,

        "Name=buyFlights.x""Value=42", ENDITEM,

        "Name=buyFlights.y""Value=16", ENDITEM,

        LAST);

 

 

 

    lr_end_transaction("订票", LR_AUTO);

 

    lr_start_transaction("退出");

 

    web_url("welcome.pl_2",

        "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights",

        "Snapshot=t27.inf",

        "Mode=HTTP",

        LAST);

 

    web_url("home.html_2",

        "URL=http://127.0.0.1:1080/WebTours/home.html",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1",

        "Snapshot=t28.inf",

        "Mode=HTTP",

        LAST);

 

    web_url("nav.pl_4",

        "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1",

        "Snapshot=t29.inf",

        "Mode=HTTP",

        LAST);

 

 

    lr_end_transaction("退出", LR_AUTO);

 

return 0;

}

  

案例四(随机订票方法二——选项固定)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

Action()

{

int num;

char str1[20];

    web_url("WebTours",

        "URL=http://127.0.0.1:1080/WebTours/",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=",

        "Snapshot=t1.inf",

        "Mode=HTTP",

        LAST);

 

    web_url("header.html",

        "URL=http://127.0.0.1:1080/WebTours/header.html",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/",

        "Snapshot=t2.inf",

        "Mode=HTTP",

        LAST);

 

    web_url("welcome.pl",

        "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/",

        "Snapshot=t5.inf",

        "Mode=HTTP",

        LAST);

 

    web_url("home.html",

        "URL=http://127.0.0.1:1080/WebTours/home.html",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true",

        "Snapshot=t6.inf",

        "Mode=HTTP",

        LAST);

 

//关联usersession

    web_reg_save_param_ex(

        "ParamName=usersession",

        "LB=userSession value=",

        "RB=>\n<table border",

        SEARCH_FILTERS,

        "Scope=All",

        LAST);

    web_url("nav.pl",

        "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=true",

        "Snapshot=t7.inf",

        "Mode=HTTP",

        LAST);

 

    lr_start_transaction("登录");

 

    web_submit_data("login.pl",

        "Action=http://127.0.0.1:1080/WebTours/login.pl",

        "Method=POST",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/nav.pl?in=home",

        "Snapshot=t9.inf",

        "Mode=HTTP",

        ITEMDATA,

        "Name=userSession""Value={usersession}", ENDITEM,

        "Name=username""Value=test002", ENDITEM,

        "Name=password""Value=123456", ENDITEM,

        "Name=JSFormSubmit""Value=off", ENDITEM,

        "Name=login.x""Value=53", ENDITEM,

        "Name=login.y""Value=11", ENDITEM,

        LAST);

 

 

    web_url("nav.pl_2",

        "URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/login.pl",

        "Snapshot=t10.inf",

        "Mode=HTTP",

        LAST);

 

    web_reg_find("Text=Welcome, <b>test002</b>, ",

        "Fail=NotFound",

        "SaveCount=登录次数",

        "Search=Body",

        LAST);

    web_url("login.pl_2",

        "URL=http://127.0.0.1:1080/WebTours/login.pl?intro=true",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/login.pl",

        "Snapshot=t14.inf",

        "Mode=HTTP",

        LAST);

 

    if(atoi(lr_eval_string("{登录次数}")) >0){

    lr_end_transaction("登录", LR_PASS);

    }else{

    lr_end_transaction("登录", LR_FAIL);

    };

 

    lr_start_transaction("订票");

 

//关联地址

 

    web_reg_save_param_ex(

        "ParamName=所有目的地",

        "LB=option value=\"",

        "RB=\">",

        "Ordinal=ALL",

        SEARCH_FILTERS,

        "Scope=All",

        LAST);

 

     

    lr_output_message("--------目的地的值为:%s",lr_eval_string("{目的地}"));

    web_url("reservations.pl",

        "URL=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?page=search",

        "Snapshot=t17.inf",

        "Mode=HTTP",

        LAST);

 

    web_url("Search Flights Button",

        "URL=http://127.0.0.1:1080/WebTours/welcome.pl?page=search",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=home",

        "Snapshot=t16.inf",

        "Mode=HTTP",

        LAST);

    web_url("nav.pl_3",

        "URL=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?page=search",

        "Snapshot=t18.inf",

        "Mode=HTTP",

        LAST);

 

    num=rand()%9 + 10;

    sprintf(str1,"{所有目的地_%d}",num);//拼接字符   因为地址是参数所以用{}

    lr_save_string(lr_eval_string(str1),"目的地");//赋值

    lr_think_time(7);

 

    web_submit_data("reservations.pl_2",

        "Action=http://127.0.0.1:1080/WebTours/reservations.pl",

        "Method=POST",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/reservations.pl?page=welcome",

        "Snapshot=t22.inf",

        "Mode=HTTP",

        ITEMDATA,

        "Name=advanceDiscount""Value=0", ENDITEM,

        "Name=depart""Value=Denver", ENDITEM,

        "Name=departDate""Value=08/20/2016", ENDITEM,

        "Name=arrive""Value={目的地}", ENDITEM,

        "Name=returnDate""Value=08/21/2016", ENDITEM,

        "Name=numPassengers""Value=1", ENDITEM,

        "Name=seatPref""Value=None", ENDITEM,

        "Name=seatType""Value=Coach", ENDITEM,

        "Name=.cgifields""Value=roundtrip", ENDITEM,

        "Name=.cgifields""Value=seatType", ENDITEM,

        "Name=.cgifields""Value=seatPref", ENDITEM,

        "Name=findFlights.x""Value=55", ENDITEM,

        "Name=findFlights.y""Value=5", ENDITEM,

        LAST);

    //lr_output_message("------arrive的值为:%s",lr_eval_string("arrive"));

 

    lr_think_time(12);

 

    web_submit_data("reservations.pl_3",

        "Action=http://127.0.0.1:1080/WebTours/reservations.pl",

        "Method=POST",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/reservations.pl",

        "Snapshot=t24.inf",

        "Mode=HTTP",

        ITEMDATA,

        "Name=outboundFlight""Value=031;224;08/20/2016", ENDITEM,

        "Name=numPassengers""Value=1", ENDITEM,

        "Name=advanceDiscount""Value=0", ENDITEM,

        "Name=seatType""Value=Coach", ENDITEM,

        "Name=seatPref""Value=None", ENDITEM,

        "Name=reserveFlights.x""Value=75", ENDITEM,

        "Name=reserveFlights.y""Value=4", ENDITEM,

        LAST);

 

    web_submit_data("reservations.pl_4",

        "Action=http://127.0.0.1:1080/WebTours/reservations.pl",

        "Method=POST",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/reservations.pl",

        "Snapshot=t25.inf",

        "Mode=HTTP",

        ITEMDATA,

        "Name=firstName""Value=m", ENDITEM,

        "Name=lastName""Value=m", ENDITEM,

        "Name=address1""Value=m", ENDITEM,

        "Name=address2""Value=m", ENDITEM,

        "Name=pass1""Value=m m", ENDITEM,

        "Name=creditCard""Value=", ENDITEM,

        "Name=expDate""Value=", ENDITEM,

        "Name=oldCCOption""Value=", ENDITEM,

        "Name=numPassengers""Value=1", ENDITEM,

        "Name=seatType""Value=Coach", ENDITEM,

        "Name=seatPref""Value=None", ENDITEM,

        "Name=outboundFlight""Value=031;224;08/20/2016", ENDITEM,

        "Name=advanceDiscount""Value=0", ENDITEM,

        "Name=returnFlight""Value=", ENDITEM,

        "Name=JSFormSubmit""Value=off", ENDITEM,

        "Name=.cgifields""Value=saveCC", ENDITEM,

        "Name=buyFlights.x""Value=42", ENDITEM,

        "Name=buyFlights.y""Value=16", ENDITEM,

        LAST);

 

    lr_end_transaction("订票", LR_AUTO);

 

    lr_start_transaction("退出");

 

    lr_think_time(11);

 

    web_url("welcome.pl_2",

        "URL=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/nav.pl?page=menu&in=flights",

        "Snapshot=t27.inf",

        "Mode=HTTP",

        LAST);

 

 

    web_url("home.html_2",

        "URL=http://127.0.0.1:1080/WebTours/home.html",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1",

        "Snapshot=t28.inf",

        "Mode=HTTP",

        LAST);

 

    web_url("nav.pl_4",

        "URL=http://127.0.0.1:1080/WebTours/nav.pl?in=home",

        "Resource=0",

        "RecContentType=text/html",

        "Referer=http://127.0.0.1:1080/WebTours/welcome.pl?signOff=1",

        "Snapshot=t29.inf",

        "Mode=HTTP",

        LAST);

 

 

    lr_end_transaction("退出", LR_AUTO);

 

return 0;

}

 

 

案例五 (选项随机化——使用指针)

 View Code

案例六 (选项随机化——使用字符串)

 

1

2

3

4

5

6

//与案例五中使用指针的方法不同,这用的是字符数组存储变量

    int num;

    char str1[20];//用来存储取出的值

    num=rand()%9 + 10;//随机产生0-8的数字,加10后则随机产生10-18的数字

    sprintf( str1,"{所有目的地_%d}",num );//拼接字符,

    lr_save_string( lr_eval_string(str1),"目的地" );//变量不能直接使用必须用函数存储  

  

二.登录脚本编写流程及注意事项

1.流程

  编写方式:录制和手写(下面记录手写方式)

  需要工具:httpwatch 或者是 fiddler

具体流程:

  执行一次登录,将请求通过抓包工具记录下来

  筛选请求:如果没有特别要求,图片等格式需求可以忽略

  将get请求写入脚本

  将post请求写入脚本  

  

  寻找检查点——登录成功的网页>查看源码>复制成功登录判断点

  插入检查点函数——放到请求登录成功网页的前面()

1

2

3

web_reg_find("Text=Welcome, <b>test001</b>,",

                "Savecount=登录计数",

                LAST); 

  插入关联函数从服务器获得的动态参数

  位置:放在第一次出现session值的网页前

1

2

3

4

web_reg_save_param_ex("Paramname=userSession",

            "LB=name=userSession value=",

             "RB=>",

              LAST); 

  添加if语句判断事务是否成功

  (必须先有一个开始事物

  (将结束事物替换为判断条件

1

2

3

4

5

if(atoi(lr_eval_string("{登录计数}")) >0){

            lr_end_transaction("登录", LR_PASS);

    }else{

            lr_end_transaction("登录", LR_FAIL);

    }

 2.注意事项

参数列表中设置选项选择312——唯一值,每次迭代更新

三.执行

工具——〉创建controler场景 如果出现错误检查是否注册码失效,或者用管理员运行LR

开启windows服务 ——〉services.msc——〉Remote Registry改为手动,然后启动

场景——〉集合(没有亮的话,回脚本界面 插入——〉集合 ,场景界面点击路径再重加载脚本 )

运行——〉可用图——〉windonws资源图——〉右键添加度量——〉添加——〉输入自己电脑的ip

四.分析结果

 

 未完待续。。

 备注:

web_get_int_property(HTTP_INFO_RETURN_CODE); // HTTP_INFO_RETURN_CODE : HTTP返回的状态码,获取状态码值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值