1 Datatable参数化

Global表的数据可以被所有的action访问,Action的数据只能被对应的Action访问

本地表循环的次数设置:Action Call Properties

Global表循环的次数设置:File -> Test Settings -> Run

 

注:

         ① Global全局变量循环一次,本地Action表全部运行一次

② 删除表的内容:Edit -> Delete

③ 修改列名:鼠标右击对应的列

 

Example4Flight程序登录验证

Data Table

 

username

password

errmsg

1

mercury

Please enter agent name

2

mer

mercury

Agent name must be at least 4 characters long

3

mercury

Please enter passwoed

4

mercury

mercury

null

Text

dialog("Login").WinEdit("Agent Name:").Set datatable("username","login")

dialog("Login").WinEdit("Password").Set datatable("password","login")

dialog("Login").WinButton("OK").Click

expected_result = datatable("errmsg","login")

If dialog("Login").Dialog("Flight Reservations").Exist Then

actual_result = dialog("Login").Dialog("Flight Reservations").Static("errmsg").GetROProperty("text")

if expected_result = actual_result Then

reporter.ReportEvent micPass, "登陆验证","输入错误的用户名和密码,弹出正确的提示信息!"

else

reporter.ReportEvent micFail, "登陆验证","输入错误的用户名和密码,弹出错误的提示信息!"

End if

dialog("Login").Dialog("Flight Reservations").WinButton("确定").Click

else

If expected_result = "null" Then

If window("Fight Reservations").Exist Then

Reporter.ReportEvent micPass, "登陆验证","输入正确的用户名和密码,登陆系统成功!"

else

Reporter.ReportEvent micFail, "登陆验证","输入正确的用户名和密码,登陆系统失败!"

End If

else

Reporter.ReportEvent micFail, "登陆验证","输无效的用户名和密码,系统没有任何响应!"

End If

End If

 

Practice2Agileone自动登录验证

Data Table

username

password

errmsg

admin

出错啦: 用户名不能为空 ...

adm

admin

出错啦: 找不到该用户名 ...

admin

adm

出错啦: 密码输入错误 ...

admin

admin

null

Text

Browser("AgileOne - Welcome to").Page("AgileOne - Welcome to").WebEdit("WebEdit").Set  datatable("username","Action1")

Browser("AgileOne - Welcome to").Page("AgileOne - Welcome to").WebEdit("WebEdit_2").Set datatable( "password","Action1")

Browser("AgileOne - Welcome to").Page("AgileOne - Welcome to").Image("loginbt").Click

expected_result = datatable("errmsg","Action1")

If  Browser("AgileOne - Welcome to").Page("AgileOne - Welcome to").WebElement("errmsg").Exist Then

actual_result = Browser("AgileOne - Welcome to").Page("AgileOne - Welcome to").WebElement("errmsg").GetROProperty("innertext")

If  expected_result = actual_result Then

reporter.ReportEvent micPass,"登陆验证","输入错误的用户名和密码,提示正确的提示信息!"

else

reporter.ReportEvent micFail,"登陆验证","输入错误的用户名和密码,提示错误的提示信息!"

End If

else

If expected_result = "null" Then

If  Browser("AgileOne - Welcome to").Page("AgileOne - Power to Agile").WebElement("wellcome").Exist Then

reporter.ReportEvent micPass,"登陆验证","输入正确的用户名和密码,登陆系统成功!"

Browser("AgileOne - Welcome to").Page("AgileOne - Power to Agile").Link("exit").Click

else

reporter.ReportEvent micFail,"登陆验证","输入正确的用户名和密码,系统登陆失败!"

End If

else

reporter.ReportEvent micFail,"登陆验证","输入无效的用户名和密码,系统无响应!"

End If

End If

2 Excle参数化

利用datatable对象导入

Import:将指定的Excle的所有数据导入,第一个sheet导入Global,第二个导入Action1,以此类推

ImportSheet:可将指定的sheet页导入到指定的表中,第一行默认导入为列标题

QTP只支持Excle2003,将Excle另存为Excle2003

Example1datatabe.ImportSheet"C:\123.xls","Sheet1","Action1" (在代码开始前加入)

通过环境变量

环境变量设置:File -> Setting -> Environment -> Variable:User-defined 添加环境变量,用户定义的环境变量,需要自己定义变量名和值,定义好后就可以用这些变量去参数化脚本中的常量。

Example2Dialog("Login").WinEdit("Agent Name:").Set Environment("password")

Example3Excle读取、写入操作(Filith程序)

datatable

username

password

errmsg

actual_result

test_result

mercury

Please enter agent name

mer

mercury

Agent name must be at least 4 characters long

mercury

Please enter passwoed

mercury

mercury

null

Text

datatabe.ImportSheet"C:\123.xls","login","Action1"

For i=1 to datatable.GetSheet("Action1").GetRowCount

dialog("Login").WinEdit("Agent Name:").Set datatable("username","Action1")

dialog("Login").WinEdit("Password").Set datatable("password","Action1")

dialog("Login").WinButton("OK").Click

If dialog("Login").Dialog("Flight Reservations").Exist Then

expected_result = datatable("errmsg","login")

actual_result = dialog("Login").Dialog("Flight Reservations").Static("errmsg").GetROProperty("text")

if expected_result = actual_result Then

datatable("actual_result", "Action1")=actual_result

datatable("test_result", "Action1")="pass"

else

datatable("actual_result", "Action1")=actual_result

datatable("test_result", "Action1")="Fail"

End If

dialog("Login").Dialog("Flight Reservations").WinButton("确定").Click

End If

datatable.GetSheet("Action1").SetNextRow

Next

datatable.Export"C:\Flight_result.xls"

Practice1Agileone登录读取、写入Excle(window7,需调试)

写入Excle的函数:

Function QTP_WriteExcel(sExcelName,SheetNum,x,y,Content)

Set xlsobj=createobject("excel.application")

Set xlsbook=xlsobj.Workbooks.Open(sExcelName)

Set xlssheet=xlsbook.Sheets(SheetNum)

xlssheet.cells(x,y)=Content

xlsbook.Save

xlsbook.Close

End Function

调用:QTP_WriteExcel"C:\Users\In_october\Desktop\agileone.xls","sheet2",5,5,"abcde"

Text

Function QTP_WriteExcel(sExcelName,SheetNum,x,y,Content)

Set xlsobj=createobject("excel.application")

Set xlsbook=xlsobj.Workbooks.Open(sExcelName)

Set xlssheet=xlsbook.Sheets(SheetNum)

xlssheet.cells(x,y)=Content

xlsbook.Save

xlsbook.Close

End Function

Col=5

Row=2

datatable.ImportSheet"C:\Users\In_october\Desktop\agileone.xls","Sheet1","Action1"

Browser("AgileOne - Welcome to").Page("AgileOne - Welcome to").WebEdit("WebEdit").Set  datatable("username","Action1")

Browser("AgileOne - Welcome to").Page("AgileOne - Welcome to").WebEdit("WebEdit_2").Set datatable( "password","Action1")

Browser("AgileOne - Welcome to").Page("AgileOne - Welcome to").Image("loginbt").Click

expected_result = datatable("errmsg","Action1")

If  Browser("AgileOne - Welcome to").Page("AgileOne - Welcome to").WebElement("errmsg").Exist Then

actual_result = Browser("AgileOne - Welcome to").Page("AgileOne - Welcome to").WebElement("errmsg").GetROProperty("innertext")

QTP_WriteExcel"C:\Users\In_october\Desktop\agileone.xls","sheet2",Row,Col,actual_result

Row=Row+1

If  expected_result = actual_result Then

reporter.ReportEvent micPass,"登陆验证","输入错误的用户名和密码,提示正确的提示信息!"

else

reporter.ReportEvent micFail,"登陆验证","输入错误的用户名和密码,提示错误的提示信息!"

End If

else

If expected_result = "null" Then

If  Browser("AgileOne - Welcome to").Page("AgileOne - Welcome to").WebElement("wellcome").Exist Then

reporter.ReportEvent micPass,"登陆验证","输入正确的用户名和密码,登陆系统成功!"

Browser("AgileOne - Welcome to").Page("AgileOne - Welcome to").Link("exit").Click

else

reporter.ReportEvent micFail,"登陆验证","输入正确的用户名和密码,系统登陆失败!"

End If

else

reporter.ReportEvent micFail,"登陆验证","输入无效的用户名和密码,系统无响应!"

End If

End If

3 对象库管理

保存共享数据库:Action1的对象数据库 -> File -> Export Local Objects -> Save

关联共享数据库:Action2关联Action1的对象数据库:右键点击Action2 –> Association Repository to local -> 选择文件,Open,关联的对象数据库不能修改

关联的对象数据库修改:1.本地修改,加入到本地对象数据库 2.全局修改,在Objict Repository中修改

Action管理:调用Action  增加Action  划分Action  Action管理的原则

Action管理的原则:

1.每个Action其实就是一个用户场景,如登录,订票,退出等

2.每个业务流程由若干个用户场景组成,即由若干个Action组成,在业务流程测试时需要首先分析该流程可以划分为多少个用户场景

3.Action划分的粒度以是否方便作为可复用Action被其他业务流程复用为标准,不能太粗也不能太细

Example1订票业务场景(Flight程序)

订票业务场景,划分为3个业务场景:login,order,logout  Reusable Action打勾才能被其他的调用

1.创建对象库,新建3个Action:login,order,logout

2.-> Record业务流程

3.Save Test

4.新建Action:Call to Copy of Action 选择Test

5.划分Action:定位鼠标,-> Split Action

自动化测试(三):QTP参数化的更多相关文章

  1. 【Jmeter基础知识】Jmeter的三种参数化方式

    JMeter的三种参数化方式包括: 1.用户参数 2.函数助手 3.CSV Data Set Config 一.用户参数 位置:添加-前置处理器-用户参数 操作:可添加多个变量或者参数 二.函数助手 ...

  2. jmeter的三种参数化方法

    JMeter的三种参数化方式包括: 1.用户参数 2.函数助手 3.CSV Data Set Config 一.用户参数 位置:添加-前置处理器-用户参数 操作:可添加多个变量或者参数 二.函数助手 ...

  3. python接口自动化测试三十六:数据驱动参数化之paramunittest

    官方文档1.官方文档地址:https://pypi.python.org/pypi/ParamUnittest/2.github源码下载地址:https://github.com/rik0/Param ...

  4. 自动化测试工具QTP和SilkTest横向PK(转)

    转自:http://www.uml.org.cn/Test/201405212.asp?artid=1686 众所周知,自动化测试工具曾几何时三足鼎立,Mercury QTP/WinRunner系.I ...

  5. QTP 参数化

    PS:方法内容是转的别人的,我们项目中只用到了方法三,主要用于将测试数据与业务分离,增强测试数据的可维护性. 方法一.DataTable方法 这是QTP提供的一种方法,也是最容易实现参数化的一种方式. ...

  6. 自动化测试工具QTP的使用实例 分类: 软件测试 2015-06-17 00:23 185人阅读 评论(0) 收藏

    1. QTP简介 1.1QTP功能与特点 QTP是QuickTest Professional的简称,是一种自动化软件测试工具.在软件的测试过程中,QTP主要来用来通过已有的测试脚本执行重复的手动测试 ...

  7. QTP参数化

    使用QTP可以通过将固定值替换为参数,扩展测试范围,可以提高测试的灵活性. 在QTP中,我们可以对以下部分进行参数化: 1.对象属性参数化 2.对象名称的参数化 3.对象方法的参数的参数化

  8. jmeter的三种参数化

    以FTP请求(用户.密码)为例:(其他都相同) 1.文件参数化 使用配置元件中的CSV Data Set Config 配置CSV Data Set Config: 文件中存储ftp登录的用户名和密码 ...

  9. Jmeter5.2.1 三种参数化

    Jmeter的相关操作,一定要会参数化,常见的参数化方法有如下几种: 一.用户定义的变量 常应用于设置一些全局变量,包括url.host.port等等 线程组--添加--配置元件--用户定义的变量,添 ...

随机推荐

  1. Xcode 合并分支报错

    原理和操作步骤见如下转载的两篇文章, 我所使用的 svn 客户端软件是 Mac 下面的 Versions.app v1.06 这个版本包含一个多人开发的bug bug 的解决方案见我之前转载的两篇文章 ...

  2. WinForm 控件库

    1:Telerik 介绍: Telerik 是保加利亚的一个软件公司,专注于微软.Net平台的表示层与内容管理控件.Telerik 提供高度稳定性和丰富性能的组件产品,并可应用在非常严格的环境中. 现 ...

  3. C#实现IDispose模式

    .net的GC机制有两个问题:首先GC并不能释放所有资源,它更不能释放非托管资源.其次,GC也不是实时的,所有GC存在不确定性.为了解决这个问题.NET提供了析构函数 public class Dis ...

  4. Nginx 的启动、停止、平滑重启、信号控制和平滑升级

    Nginx 的启动         假设 nginx 安装在 /usr/local/nginx 目录中,那么启动 nginx 的命令就是: [root@localhost ~]# /usr/local ...

  5. jsp的静态包含与动态包含:<%@ include file="" %>和<jsp:include page=""></jsp:include>区别与分析

    <%@ include file="" %>是将文件原封不动的copy进现有的文件中,像是拼接好后,再编译成为servlet运行. <jsp:include pa ...

  6. XML 创建

    using unityEngine; using System.Collections; using System.Linq; using System.Xml.Linq; using System; ...

  7. ***phpredis扩展安装总结

    phpredis扩展安装总结:PHP扩展安装在[root@iZ254lfyd6nZ lampp]# cd include 目录下创建一个目录phpredis下载扩展:wget https://gith ...

  8. HDU4612+Tarjan缩点+BFS求树的直径

    tarjan+缩点+树的直径题意:给出n个点和m条边的图,存在重边,问加一条边以后,剩下的桥的数量最少为多少.先tarjan缩点,再在这棵树上求直径.加的边即是连接这条直径的两端. /* tarjan ...

  9. ibatis的there is no statement named xxx in this SqlMap

    报错情况如下: com.ibatis.sqlmap.client.SqlMapException: There is no statement named Control.insert-control ...

  10. altium designer 13 学习之添加汉字

    在altium desginer中如果你是想添加英文还是比较方便的,基本直接就可以输入了,但是添加中文就不是那么简单了,下面不介绍下如何在altium designer中快速的添加自己想要的中文 工具 ...