五、脚本编辑和对象改名过程和回放实验
实验内容导航
1.实验步骤
2.实验需求
3.实验目标
4.实验理论
5.操作步骤
6.实验报告模板
7.实验课尾交流
实验步骤
1.理解脚本录制的原理
2.熟悉需要测试的功能的需求
3.认真分析实验需求
4.独立完成实验任务
5.认真填写实验报告,并细致分析与总结本次实验
实验需求
1.成功搭建被测系统crm客户管理平台;
2.成功安装AutoRunner功能自动化测试工具,可以录制回放脚本
3.使用IE浏览器,并且版本不超过IE9
实验目标
1.初步了解功能自动化测试工具的使用
2.掌握录制和回放的基本操作
3.熟悉脚本编辑区域的脚本信息
4.掌握报告结果的分析
实验理论
实验理论:自动化测试工程实际就是一个工具模拟人工的过程,这个
过程可以细分成俩个独立又相互关联的阶段,首先是用自动化测试工
具模拟记录人工的操作过程形成测试脚本,第二个阶段是自动化测试
工具根据及录下的人工的操作步骤和后期设计的输入参数,自动循环
往复执行重复的操作,对被测系统进行全方位立体式的测试,以期找
出系统的所有缺陷。
在很多时候我们会发现录制下来的脚本里面有很多的对象,有些对象
的名称也很奇怪,既不是汉字也不是英文,有的居然是汉语拼音,还
有“TD”、“DIV”,这些肯定不是大家喜闻乐见的,所以我们不妨在遇到
这种问题的时候考虑对录制下来的对象进行改名,那么在实际的测试
过程中也是允许这样操作的。这里以crm客户管理系统的 客户管理模
块下的子模块新增客户为例做下对象重命名:
前情提要:
在对很多被测系统进行测试的时候,都会有这种情况:记录下来的
脚本中有很多对象,例如输入框、按钮、下拉列表、表格等;很多
的对象在被记录成脚本的时候都是英文名或者有些根本就不规范,
这个时候就会出现很多问题,例如无法根据脚本中记录的对象名称
准确判断对象在被测系统中到底是什么,后续的测试人员无法根据
前面的记录快速了解测试过程,进而加快测试过程;面对这样的问
题就需要一个合理的解决方案:对象重命名。
下面要展示得这个脚本看起来会有点内容丰富,这里提前解读下脚
本记录的内容:(我把前面的登录和点击客户管理的操作都在录制
脚本前手动做好了)首先点击新增客户按钮, 然后点击公司名称输
入框输入公司名称、点击申请类型下拉按钮选择申请类型为:代理
、点击公司背景下拉按钮选择公司背景为:研究院所、点击是否上
市下拉按钮选择否、点击注册资本输入框输入注册资本、点击年销
售额输入框输入年销售额、点击企业规模输入框输入企业规模、点
击测试人员输入框输入测试人员个数、点击是否购买下拉按钮选择
否、点击目前软件输入框输入目前软件AR、点击公司网址输入框输
入公司网址、点击公司地址输入框输入公司地址,然后向下翻动网
页在其他信息中点击客户状态下拉按钮选择正式客户、点击确认按
钮添加客户信息。回头看下这操作还真是不少,哈哈哈
//ar.// IE is loading web. Wait ...
//ar.// IE has loaded web.
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").clickControl("A_新增客户", 34, 6, "left");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").clickControl("INPUT_text_Client_Company", 54, 6, "left");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_Company", "");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("SELECT_Client_Class", "企业");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("SELECT_Client_Class", "代理");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("SELECT_Client_beijing", "民营");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("SELECT_Client_beijing", "研究院所");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("SELECT_Client_shangshi", "是");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("SELECT_Client_shangshi", "否");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").clickControl("INPUT_text_Client_ziben", 143, 13, "left");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_ziben", "10038");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").clickControl("INPUT_text_Client_xiaoshou", 49, 11, "left");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_xiaoshou", "10010");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").clickControl("INPUT_text_Client_guimu", 129, 13, "left");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_guimu", "1000");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").clickControl("INPUT_text_Client_ceshiren", 24, 11, "left");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_ceshiren", "200");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("SELECT_Client_goumei", "是");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("SELECT_Client_goumei", "否");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").clickControl("INPUT_text_Client_ruanjian", 35, 11, "left");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_ruanjian", "AR");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").clickControl("INPUT_text_Client_Http", 152, 9, "left");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_Http", "");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_Http", "www.spasvo.com");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").clickControl("INPUT_text_Client_youbian", 44, 11, "left");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_youbian", "237171");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").clickControl("INPUT_text_Client_Address", 126, 13, "left");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_Address", "上海市");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("SELECT_Client_Follow", "潜在客户");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("SELECT_Client_Follow", "正式客户");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").clickControl("INPUT_submit_确 认", 58, 8, "left");
再看看这脚本内容也是蛮多的,我把截图也放到下面吧这样在AR里面脚本看起
来相对清晰些:
一段放不下了都,只好把脚本分成上下俩段来截图了,看到这种密密麻麻的脚本
首先要做的就是脚本最简化,第一步:删除注释、点击输入框的操作后脚本可以简
化成如下:
这个时候脚本还有冗余,可以把点击下拉按钮时留下的脚本去掉,留下选择后
的脚本:
留下的脚本内容如下:
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").clickControl("A_新增客户", 34, 6, "left");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_Company", "spasvo_991023");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("SELECT_Client_Class", "代理");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("SELECT_Client_beijing", "研究院所");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("SELECT_Client_shangshi", "否");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_ziben", "10038");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_xiaoshou", "10010");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_guimu", "1000");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_ceshiren", "200");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("SELECT_Client_goumei", "否");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_ruanjian", "AR");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_Http", "www.spasvo.com");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_youbian", "237171");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("INPUT_text_Client_Address", "上海市");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("SELECT_Client_Follow", "正式客户");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").clickControl("INPUT_submit_确 认", 58, 8, "left");
接下来就可以进行对象改名操作了,注意在这一系列的操作过程中不要点击保
存按钮,等修改完对象名之后再点击保存按钮保存所有的编辑,不然对象改名
会失败:
点击对象库按钮,打开对象库:
红框内的对象可以一一改名,改名的时候我们可以参阅对象截图:
选中一个对象之后就可以看到对象截图,双击截图可以放大:
原来是公司地址,改名吧,右键这个对象名称,选择重命名对象,之后在输入
框内输入汉字名称:公司地址:
依次修改所有对象的名称后关闭对象库,回到脚本编辑区会发现,脚本中的对
象名称都修改成在对象库里面修改后的名称了:
脚本内容如下:
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").clickControl("A_新增客户", 34, 6, "left");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("公司名称", "spasvo_991023");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("申请类型", "代理");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("公司背景", "研究院所");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("是否上市", "否");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("注册资本", "10038");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("年销售额", "10010");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("企业规模", "1000");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("测试人员", "200");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("购买正版", "否");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("当前软件", "AR");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("公司网址", "www.spasvo.com");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("邮编编码", "237171");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("公司地址", "上海市");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("客户状态", "正式客户");
ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").clickControl("INPUT_submit_确 认", 58, 8, "left");
做到这里脚本的最简化和对象重命名就做好了,讲了这样一个对象重命名之
后希望对家所产生的的作用或者可以美其名曰启发是要大家能够知道我们为
什么做了这件事?这个是我一直强调的东西,就是想法或者叫思想;然后我
再讲怎么做,可能有的人觉得我啰嗦,但事实摆在我眼前的是很多时候思想
被忽视了,只剩下了怎么做!往往有很多时候我们都陷进去了,出不来了!
再强调下对象的重命名是为了我们后面再去识读脚本的时候能够很快地根据
脚本内容判断脚本中所处理的交易流程,在自动化的基础上提高脚本的可分
别率,进一步提升自动化测试的效率。
下面我们保存下之前处理好的脚本,然后执行脚本:
脚本执行结果:
日志信息:
脚本详细:
行号 | 脚本内容 |
1 | ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").clickControl("A_新增客户", 34, 6, "left"); |
2 | ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("公司名称", "spasvo_991023"); |
3 | ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("申请类型", "代理"); |
4 | ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("公司背景", "研究院所"); |
5 | ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("是否上市", "否"); |
6 | ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("注册资本", "10038"); |
7 | ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("年销售额", "10010"); |
8 | ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("企业规模", "1000"); |
9 | ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("测试人员", "200"); |
10 | ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("购买正版", "否"); |
11 | ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("当前软件", "AR"); |
12 | ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("公司网址", "www.spasvo.com"); |
13 | ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("邮编编码", "237171"); |
14 | ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").setValue("公司地址", "上海市"); |
15 | ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").select("客户状态", "正式客户"); |
16 | ar.window("IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer").clickControl("INPUT_submit_确 认", 58, 8, "left"); |
|
|
记录详细:
行号 | 对象 | 详细 | 结果 | 时间 | 备注 |
1 | IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer | window | Successed | 2019-11-09 17:01:18 |
|
1 | A_新增客户 | clickControl | Successed | 2019-11-09 17:01:19 |
|
2 | IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer | window | Successed | 2019-11-09 17:01:20 |
|
2 | 公司名称 | setValue | Successed | 2019-11-09 17:01:21 |
|
3 | IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer | window | Successed | 2019-11-09 17:01:21 |
|
3 | 申请类型 | select | Successed | 2019-11-09 17:01:22 |
|
4 | IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer | window | Successed | 2019-11-09 17:01:23 |
|
4 | 公司背景 | select | Successed | 2019-11-09 17:01:24 |
|
5 | IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer | window | Successed | 2019-11-09 17:01:25 |
|
5 | 是否上市 | select | Successed | 2019-11-09 17:01:26 |
|
6 | IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer | window | Successed | 2019-11-09 17:01:26 |
|
6 | 注册资本 | setValue | Successed | 2019-11-09 17:01:27 |
|
7 | IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer | window | Successed | 2019-11-09 17:01:28 |
|
7 | 年销售额 | setValue | Successed | 2019-11-09 17:01:29 |
|
8 | IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer | window | Successed | 2019-11-09 17:01:29 |
|
8 | 企业规模 | setValue | Successed | 2019-11-09 17:01:30 |
|
9 | IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer | window | Successed | 2019-11-09 17:01:31 |
|
9 | 测试人员 | setValue | Successed | 2019-11-09 17:01:32 |
|
10 | IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer | window | Successed | 2019-11-09 17:01:32 |
|
10 | 购买正版 | select | Successed | 2019-11-09 17:01:33 |
|
11 | IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer | window | Successed | 2019-11-09 17:01:34 |
|
11 | 当前软件 | setValue | Successed | 2019-11-09 17:01:35 |
|
12 | IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer | window | Successed | 2019-11-09 17:01:35 |
|
12 | 公司网址 | setValue | Successed | 2019-11-09 17:01:36 |
|
13 | IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer | window | Successed | 2019-11-09 17:01:37 |
|
13 | 邮编编码 | setValue | Successed | 2019-11-09 17:01:38 |
|
14 | IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer | window | Successed | 2019-11-09 17:01:38 |
|
14 | 公司地址 | setValue | Successed | 2019-11-09 17:01:39 |
|
15 | IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer | window | Successed | 2019-11-09 17:01:40 |
|
15 | 客户状态 | select | Successed | 2019-11-09 17:01:41 |
|
16 | IEFrame_上海泽众软件科技有限公司客户管理系统 - Windows Internet Explorer | window | Successed | 2019-11-09 17:01:41 |
|
16 | INPUT_submit_确 认 | clickControl | Successed | 2019-11-09 17:01:42 |
|
|
|
|
|
|
|
结果总结:
名称 | 值 |
脚本名称: | add_clilent_1.bsh |
录像文件: |
|
开始执行时间: | 2019-11-09 17:01:17 |
执行结束时间: | 2019-11-09 17:01:43 |
执行耗时(秒): | 25 |
脚本执行结果: | 执行成功! |
脚本执行输出结果:
哈哈哈,接下来可以分析下学这个干嘛,或者说学这个都是一个一个的知识点
,有没有串起来的?回答是有而且是必须有,但是目前这个阶段做这个教材主
要是为了让大家先熟悉操作,然后学会其中的知识点,等到我们把这些基础课
讲完了,后面会出视屏课,在视屏课里面我们来详细分析案例,如何将知识融
会贯通,那么善于思考的你现在就可以行动了,结合我们之前讲的内容如何将
对新增客户这个模块的功能测试,逻辑判断,对象改名等等结合到一个脚本中
去处理?