使用webpagetest测试不同国家登录响应

使用webpageTest模拟不同国家进行登录操作

产品boss提了个从不同国家测试系统访问响应时间的需求,目前完成的是不同国家登录操作。

先来个套话:网站的打开速度直接影响用户体验,据悉,网站若没有在4秒内读取出来,大多数的访客就会选择离开,而且网页的载入速度也会影响网站的排名,因此,网站的打开速度极其重要。根据不同的需求去分析网站的加载速度,有助于促进网站高效运行

工具

拿到需求之后,上网搜过很多工具,接触了的有:

Pingdom
sucuri

以及正在使用的:

webpagetest

webpagetest

其他的就不介绍了,只介绍怎么使用webpagetest进行不同国家的登录操作。
说实话,刚开始接触时候有点懵,webpagetest自己有个Auth模块,原以为可以直接通过这个来进行登录鉴权,结果可以预料,压根没用,后来就开始琢磨Script模块。看了n久官方文档之后,实验出来了,鼓励大家看官方文档啊。。。上链接:

script模块

webpagetest提供脚本的形式,帮助用户使用脚本来填充表单,达到登录的目的。这点看下来有点类似于自动化测试时候,先看页面源码,找到用户名/密码源码的唯一标识,在script代码框中使用该唯一标识来指代需要用到的元素,例如:登录页面源码展示的用户名:

1
<input name="username" class="ant-input ng-not-empty ng-dirty ng-valid-parse userInput ng-touched" id="username" type="text" placeholder="用户名或邮箱" ng-model="model.username" ng-change="onChange()">

从上面的源码可以看出,使用id可以唯一标志该字段,在自动化测试中使用find_element_by_id('username')即可获得该页面元素,类比到webpagetest的script,也是如此:

1
setValue id=username yourusername

即可完成定位到用户名并且完成用户名输入,同样的,密码:
源码为:

1
<input id="password" name="password" type="password" class="ant-input ant-input-lg ng-not-empty ng-dirty ng-valid-parse userInput ng-touched" placeholder="密码" ng-model="model.password" autocomplete="off" focus-if="model.username" ng-change="pwdOnChange()">

webpagetest定位:

1
setValue id=password yourpassword

当然,点击登录按钮也类似:

1
clickAndWait innerText=Login

以上演示的只是一种定位方式,更多的使用,还是去看官方文档吧,有各种情况可供选择~~

登录

直接上我的登录脚本:

1
2
3
4
5
6
logData 0
navigate https://test-login.com
logData 1
setValue name=username yourusername
setValue name=password yourpassword
clickAndWait type=submit

说明

logData个人理解是是否开启数据记录的标志,类似开启缓存(可能理解不对),0为关闭,1为开启,对于登录之后的操作,可以在登录前设置logData为1,打开数据记录,这样在后续的操作中就可以使用登录之后的用户信息。

官方示例

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
// load the account name and password
loadVariables accounts.txt

// bring up the login screen
setEventName launch
navigate http://webmail.aol.com

// ignore any errors from here on (in case the mailbox is empty or we get image challenged)
ignoreErrors 1

// log in
setValue name=loginId %AOLSN%
setValue name=password %AOLPW%
setEventName load
submitForm name=AOLLoginForm

// only read and send a mail once an hour
minInterval AOLMail 60

// close the today curtain
click className=backdrop
sleep 5

// Open the first message with a subject of "test"
setEventName read
clickAndWait innerText=test

// delete the message
click title=Delete (del)
sleep 5

// open the compose mail form
setEventName compose
clickAndWait title=Write mail (Alt + w)

// send a test message to myself
sleep 1
setValue tabindex=100 %AOLSN%
setValue name=Subject test
loadFile msg.txt %MSG%
setInnerText contentEditable=true %MSG%
sleep 1
setDOMElement className=confirmMessage
setEventName send
clickAndWait innerText=Send

endInterval

// sign off
setEventName logout
clickAndWait className=signOutLink
文章目录
  1. 工具
  2. webpagetest
  3. 登录
    1. 说明
  4. 官方示例
|