1、计算器的例子(手动添加,将结果写到日志文件中) SystemUtil.Run "C:\WINDOWS\system32\calc.exe","","C:\WINDOWS\system32","open" Window("计算器").WinButton("1").Click Window("计算器").WinButton("+").Click Window("计算器").WinButton("2").Click Window("计算器").WinButton("=").Click

'录制状态下Insert-->Output Value-->Standard output Value-->... Window("计算器").WinEdit("Edit").Output CheckPoint("Edit") If datatable("Rusult1",dtglobalsheet)="3. " Then ' print "计算加法成功" ' msgbox "计算加法成功" reporter.ReportEvent micPass,"计算成功","计算1+2,结果正确" Writelog "计算1+2,结果正确" else ' print "计算加法失败" ' msgbox "计算加法成功" reporter.ReportEvent micFail,"计算失败","计算1+2,结果错误" Writelog "计算1+2,结果错误" End If

Window("计算器").Close

Function Writelog(str) Const ForReading=1,ForWriting=2,ForAppending=8 Dim fso,fil,msg ' 创建一个文件系统对象(File System Object) Set fso = CreateObject("Scripting.FileSystemObject") ' 创建一个文件对象,通过fso对象来打开指定的文件 Set fil = fso.OpenTextFile("C:\log.txt",ForAppending) fil.WriteLine now &" "& str ' 关闭这个文件 fil.Close ' 释放这个文件对象 Set fil = Nothing ' 释放这个文件系统对象 Set fso = Nothing End Function

2、计算机的例子(自动添加,F7) SystemUtil.Run "C:\WINDOWS\system32\calc.exe","","C:\WINDOWS\system32","open" Window("计算器").WinButton("1").Click Window("计算器").WinButton("+").Click Window("计算器").WinButton("2").Click Window("计算器").WinButton("=").Click

'非录制或录制状态下Insert-->Step Generator-->...(检查属性,在步骤生成器中) Window("计算器").WinEdit("Edit").CheckProperty "text", 3., 0 Window("计算器").Close

3、检查Tab键焦点顺序的例子 SystemUtil.Run "D:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","D:\Program Files\HP\QuickTest Professional\samples\flight\app\","open" '检查初始焦点是否正确 Dialog("Login").WinEdit("Agent Name:").CheckProperty "focused", "True" Dialog("Login").WinEdit("Agent Name:").Set "mercury" Dialog("Login").WinEdit("Agent Name:").Type  micTab '检查password焦点是否正确 Dialog("Login").WinEdit("Password:").CheckProperty "focused", "True" Dialog("Login").WinEdit("Password:").SetSecure "4c3a898e3c0b42e6cf2be4fa6670bd8f54459890" Dialog("Login").WinEdit("Password:").Type micTab '检查OK焦点是否正确 Dialog("Login").WinButton("OK").CheckProperty "focused", "True" Dialog("Login").WinButton("OK").Type micTab '检查Cancel焦点是否正确 Dialog("Login").WinButton("Cancel").CheckProperty "focused", "True" Dialog("Login").WinButton("Cancel").Type micTab '检查Help焦点是否正确 Dialog("Login").WinButton("Help").CheckProperty "focused", "True" Dialog("Login").WinButton("Help").Type micTab Dialog("Login").WinEdit("Agent Name:").Type  micTab Dialog("Login").WinEdit("Password:").Type micTab Dialog("Login").WinButton("OK").Type  micReturn Window("Flight Reservation").Close

4、插入订单后检查插入后的Order No与传真和传真信息中的Order No是否一致 SystemUtil.Run "D:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","D:\Program Files\HP\QuickTest Professional\samples\flight\app\","open" Dialog("Login").WinEdit("Agent Name:").Set "yezhaohui" Dialog("Login").WinEdit("Agent Name:").Type  micTab Dialog("Login").WinEdit("Password:").SetSecure "4c3ab6c5b987d8082648b4c7a377b5ac00bf30dc" Dialog("Login").WinEdit("Password:").Type  micReturn Window("Flight Reservation").ActiveX("MaskEdBox").Type "11111111" Window("Flight Reservation").WinComboBox("Fly From:").Select "Frankfurt" Window("Flight Reservation").WinComboBox("Fly To:").Select "London" Window("Flight Reservation").WinButton("FLIGHT").Click Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click Window("Flight Reservation").WinEdit("Name:").Set "51test" Window("Flight Reservation").WinRadioButton("Business").Set Window("Flight Reservation").WinButton("Insert Order").Click '步骤同步点 Window("Flight Reservation").ActiveX("Threed Panel Control").WaitProperty "text", "Insert Done...", 10000 Window("Flight Reservation").WinEdit("Order No:").Output CheckPoint("Order No:") Window("Flight Reservation").WinMenu("Menu").Select "File;Fax Order..." Window("Flight Reservation").Dialog("Fax Order No.").WinEdit("Order:").Check CheckPoint("Order:_2") Window("Flight Reservation").Dialog("Fax Order No.").ActiveX("MaskEdBox").Type "111111111111" Window("Flight Reservation").Dialog("Fax Order No.").WinButton("Preview Fax").Click Window("Flight Reservation").Dialog("Fax Order No.").Dialog("Fax Preview").Check CheckPoint("Fax Preview_2") Window("Flight Reservation").Dialog("Fax Order No.").Dialog("Fax Preview").WinButton("Cancel").Click Window("Flight Reservation").Dialog("Fax Order No.").WinButton("Cancel").Click Window("Flight Reservation").Close

5、检查订单号逐个加1 方法一:使用DataTable SystemUtil.Run "D:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","D:\Program Files\HP\QuickTest Professional\samples\flight\app\","open" Dialog("Login").WinEdit("Agent Name:").Set "yezhaohui" Dialog("Login").WinEdit("Agent Name:").Type  micTab Dialog("Login").WinEdit("Password:").SetSecure "4c3ac0c99f0d6cd69a0e8680e411e95f405990e5" Dialog("Login").WinEdit("Password:").Type  micReturn Window("Flight Reservation").ActiveX("MaskEdBox").Type "111111111" Window("Flight Reservation").WinComboBox("Fly From:").Select "Denver" Window("Flight Reservation").WinComboBox("Fly To:").Select "London" Window("Flight Reservation").WinButton("FLIGHT").Click Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click Window("Flight Reservation").WinEdit("Name:").Set "51testing" Window("Flight Reservation").WinRadioButton("Business").Set '获得数据库中的值到DataTable中 DbTable("DbTable").Output CheckPoint("DbTable") '改变DataTable中的值 DataTable("Db_qiwang_order",dtglobalsheet) = DataTable("Db_qiwang_order",dtglobalsheet) +1 Window("Flight Reservation").WinButton("Insert Order").Click '步骤同步点 Window("Flight Reservation").ActiveX("Threed Panel Control").WaitProperty "text", "Insert Done...", 10000 '检查界面上的数据,标准检查点 Window("Flight Reservation").WinEdit("Order No:").Check CheckPoint("Order No:") '检查数据库中的数据,数据库检查点 DbTable("DbTable_2").Check CheckPoint("DbTable_2") Window("Flight Reservation").Close

方法二:使用环境变量 SystemUtil.Run "D:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","D:\Program Files\HP\QuickTest Professional\samples\flight\app\","open" Dialog("Login").WinEdit("Agent Name:").Set "yezhaohui" Dialog("Login").WinEdit("Agent Name:").Type  micTab Dialog("Login").WinEdit("Password:").SetSecure "4c3d5bf18b8c162cfb5ba3de4ca8840bdf75f89a" Dialog("Login").WinEdit("Password:").Type  micReturn Window("Flight Reservation").ActiveX("MaskEdBox").Type "111111" Window("Flight Reservation").WinComboBox("Fly From:").Select "Frankfurt" Window("Flight Reservation").WinComboBox("Fly To:").Select "London" Window("Flight Reservation").WinButton("FLIGHT").Click Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select "13540   FRA   10:24 AM   LON   11:09 AM   SR     $167.10" Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click Window("Flight Reservation").WinEdit("Name:").Set "51testing" Window("Flight Reservation").WinRadioButton("Business").Set ''获得数据库中的值到Env..d环境变量中 DbTable("DbTable").Output CheckPoint("DbTable") '改变这个环境变量的值 environment.Value("Env_Data") =  environment.Value("Env_Data") + 1 Window("Flight Reservation").WinButton("Insert Order").Click '步骤同步点 Window("Flight Reservation").ActiveX("Threed Panel Control").WaitProperty "text", "Insert Done...", 10000 '检查界面上的数据,标准检查点 Window("Flight Reservation").WinEdit("Order No:").Check CheckPoint("Order No:") '检查数据库中的数据,数据库检查点 DbTable("DbTable_2").Output CheckPoint("DbTable_2") Window("Flight Reservation").Close

6、对象名称参数化 ''SystemUtil.Run "C:\WINDOWS\system32\calc.exe","","C:\WINDOWS\system32","open" 'Window("计算器").WinButton(datatable("nu1",dtglobalsheet)).Click 'Window("计算器").WinButton("+").Click 'Window("计算器").WinButton(datatable("nu2",dtglobalsheet)).Click 'Window("计算器").WinButton("=").Click 'Window("计算器").WinEdit("Edit").Check CheckPoint("Edit") ''Window("计算器").Close

7、属性参数化 SystemUtil.Run "C:\WINDOWS\system32\calc.exe","","C:\WINDOWS\system32","open" Window("计算器").WinButton("one").Click Window("计算器").WinButton("+").Click Window("计算器").WinButton("two").Click Window("计算器").WinButton("=").Click Window("计算器").WinEdit("Edit").Check CheckPoint("Edit") Window("计算器").Close

8、对对象的数据参数化 SystemUtil.Run "D:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","D:\Program Files\HP\QuickTest Professional\samples\flight\app\","open" Dialog("Login").WinEdit("Agent Name:").Set datatable("name",dtglobalsheet) Dialog("Login").WinEdit("Agent Name:").Type  micTab Dialog("Login").WinEdit("Password:").Set datatable("secure",dtglobalsheet) Dialog("Login").WinEdit("Password:").Type  micReturn Window("Flight Reservation").Close

9、对登录页面进行GUI自动化测试页面 SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open" Dialog("Login").WinEdit("Agent Name:").Set datatable("name",dtglobalsheet) Dialog("Login").WinEdit("Agent Name:").Type  micTab Dialog("Login").WinEdit("Password:").Set datatable("passwd",dtglobalsheet) Dialog("Login").WinEdit("Password:").Type  micReturn If  Dialog("Login").Dialog("Flight Reservations").Exist  Then

Dialog("Login").Dialog("Flight Reservations").Check CheckPoint("Flight Reservations_4") Dialog("Login").Dialog("Flight Reservations").WinButton("确定").Click     Dialog("Login").WinButton("Cancel").Click elseif  Window("Flight Reservation").Exist Then If datatable("result",dtglobalsheet)="登陆成功"  Then reporter.ReportEvent micPass,"登陆成功","登陆成功" else     reporter.ReportEvent micFail," 错误登陆"," 错误登陆" End If         Window("Flight Reservation").Close End If

DataTable Globalsheet中的数据如下: name            passwd          result---列名 mercury Please enter agent name jiangguang Please enter password wan mercury Agent name must be at least 4 characters long. yezhaohui yezhaihui Incorrect password. Please try again Please enter agent name yezhaohui mercury 登陆成功

老师答案: SystemUtil.Run "D:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","D:\Program Files\HP\QuickTest Professional\samples\flight\app\","open" Dialog("Login").WinEdit("Agent Name:").Set DataTable("UserName", dtGlobalSheet) Dialog("Login").WinEdit("Agent Name:").Type  micTab Dialog("Login").WinEdit("Password:").Set DataTable("Password", dtGlobalSheet) Dialog("Login").WinEdit("Password:").Type micReturn     '检查界面是否存在的语句通过录制激活界面来实现 If  Dialog("Login").Dialog("Flight Reservations").Exist Then

Dialog("Login").Dialog("Flight Reservations").Static("Tipcontent").Check CheckPoint("CheckTipContent")         Dialog("Login").Dialog("Flight Reservations").WinButton("确定").Click         Dialog("Login").WinButton("Cancel").Click        '检查界面是否存在的语句通过F7生成 elseif Window("Flight Reservation").Exist then         If datatable("ExpectResult")="登录成功" Then                 reporter.ReportEvent micPass,"测试登录功能","登录功能正确" else                 reporter.ReportEvent micFail,"测试登录功能","登录功能错误" End If

Window("Flight Reservation").Activate         Window("Flight Reservation").Close else         reporter.ReportEvent micWarning,"测试登录功能","未知路径" '关闭系统进程 systemutil.CloseProcessByName "flight4a.exe" End If
10、计算器参数化 SystemUtil.Run "C:\WINDOWS\system32\calc.exe","","C:\WINDOWS\system32","open" ButtonClick(datatable("num1",dtglobalsheet)) ButtonClick(datatable("operate",dtglobalsheet)) ButtonClick(datatable("num2",dtglobalsheet)) Window("计算器").WinButton("=").Click Window("计算器").WinEdit("Edit").Check CheckPoint("Edit_3") Window("计算器").Close

Function ButtonClick(ButtonNum)    Dim ilen    ilen = len(ButtonNum)    'print ilen    For i=1 to ilen str = mid(ButtonNum,i,1)         Window("计算器").WinButton(str).Click    Next End Function

11、取得Insert Order所用时间 SystemUtil.Run "D:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","D:\Program Files\HP\QuickTest Professional\samples\flight\app\","open" Dialog("Login").WinEdit("Agent Name:").Set "yezhaohui" Dialog("Login").WinEdit("Agent Name:").Type  micTab Dialog("Login").WinEdit("Password:").SetSecure "4c3d2fa62695127f452a2b119abce9c48ade1c9b" Dialog("Login").WinEdit("Password:").Type  micReturn Window("Flight Reservation").ActiveX("MaskEdBox").Type "1111111" Window("Flight Reservation").WinComboBox("Fly From:").Select "Denver" Window("Flight Reservation").WinComboBox("Fly To:").Select "London" Window("Flight Reservation").WinButton("FLIGHT").Click Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select "20260   DEN   08:12 AM   LON   03:23 PM   AA     $112.20" Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click Window("Flight Reservation").WinEdit("Name:").Type "51testing" '开始事务 Services.StartTransaction "Insertorder" Window("Flight Reservation").WinButton("Insert Order").Click Do '获得插入进度条上的值 yn_jieshu = Window("Flight Reservation").ActiveX("Threed Panel Control").GetVisibleText() Loop until yn_jieshu="Insert Done..." '结束事务 Services.EndTransaction "Insertorder"

Window("Flight Reservation").Close

12、验证删除订单功能 SystemUtil.Run "D:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","D:\Program Files\HP\QuickTest Professional\samples\flight\app\","open" Dialog("Login").WinEdit("Agent Name:").Set "yezhaohui" Dialog("Login").WinEdit("Agent Name:").Type  micTab Dialog("Login").WinEdit("Password:").SetSecure "4c3d62b0651a6971f298b22525cb0e2fe375bc75" Dialog("Login").WinEdit("Password:").Type  micReturn Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..." Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON" Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set datatable("ordernum",dtglobalsheet) Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click '获得数据库总记录数到环境变量中 DbTable("DbTable").Output CheckPoint("DbTable") print environment.Value("Count1") '删除操作 Window("Flight Reservation").WinButton("Delete Order").Click Window("Flight Reservation").Dialog("Flight Reservations").WinButton("是(Y)").Click '改变环境变量的值 environment.Value("Count1") =  Cint(environment.Value("Count1")) - 1 '检查数据库中记录条数是否少了一条 DbTable("DbTable_2").Check CheckPoint("DbTable_2") '另一种检查方法精确验证,使用TO的SetTOProperty方法使SQL语句中的订单号也跟着变 DbTable("DbTable_3").SetTOProperty "source","select count(*) from Orders where order_number =" & datatable("ordernum",dtglobalsheet) DbTable("DbTable_3").Check CheckPoint("DbTable_3")

Window("Flight Reservation").Close

13、验证更新功能(有老师答案) '************************************************** '作者:yezhaohui '日期:2010/7/14 '描述:验证更新订单的功能 '************************************************** DbTable("DbTable").SetTOProperty "source","select class from Orders where order_number="&datatable("ordernum",dtglobalsheet) DbTable("DbTable").Output CheckPoint("DbTable") If datatable("classnum",dtglobalsheet)<>environment.Value("befordata") Then SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe" Dialog("Login").WinEdit("Agent Name:").Set "yezhaohui" Dialog("Login").WinEdit("Agent Name:").Type  micTab Dialog("Login").WinEdit("Password:").SetSecure "4c3d726c4f68c03a68cd0d2ce7c8052acbab14c3" Dialog("Login").WinEdit("Password:").Type  micReturn Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..." Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON" Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit_2").Set datatable("ordernum",dtglobalsheet) Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit_2").Type  micReturn Select case  datatable("classnum",dtglobalsheet) Case "1" Window("Flight Reservation").WinRadioButton("First").Set Case "2" Window("Flight Reservation").WinRadioButton("Business").Set Case "3" Window("Flight Reservation").WinRadioButton("Economy").Set Case Else reporter.ReportEvent micWarning,"订单class的有效性","无效!"

End Select Window("Flight Reservation").WinButton("Update Order").Click Window("Flight Reservation").ActiveX("Threed Panel Control").WaitProperty "text", "Update Done...", 10000 '检查数据库中是否更新了 DbTable("DbTable_2").SetTOProperty "source","select class from Orders where order_number="&datatable("ordernum",dtglobalsheet) DbTable("DbTable_2").Check CheckPoint("DbTable_2") Window("Flight Reservation").Close else reporter.ReportEvent micWarning,"数据是否有变化","数据没变无需更新!" End If

【转】qtp-learn的更多相关文章

  1. 如何成为QTP专家

    关键字:QTP 自动化测试 专家地址:http://www.cnblogs.com/txw1958/archive/2012/11/20/how-to-become-qtp-guru.html Wou ...

  2. Qtp常见问题

    (1)Qtp不能识别对象 插件加载错误 IE内未加载BHOManager加载项

  3. Atitit learn by need 需要的时候学与预先学习知识图谱路线图

    Atitit learn by need 需要的时候学与预先学习知识图谱路线图 1. 体系化是什么 架构 知识图谱路线图思维导图的重要性11.1. 体系就是架构21.2. 只见树木不见森林21.3. ...

  4. Python 爬取所有51VOA网站的Learn a words文本及mp3音频

    Python 爬取所有51VOA网站的Learn a words文本及mp3音频 #!/usr/bin/env python # -*- coding: utf-8 -*- #Python 爬取所有5 ...

  5. Selenium VS QTP

      Selenium系列 QTP 适用结构  B/S结构  C/S.B/S结构 适用人员 有一定代码基础(Java.C#.Python.Ruby) 对编程不是很熟悉的.厌烦了做手工功能测试的.想快速进 ...

  6. QTP对象识别tips

    1.已添加的对象无法再次识别成功,编辑对象存储库中测试对象详细信息.子对象无法识别成功时,先检查父对象是否可成功识别. 2.使用.NET Windows Forms 侦测器检测后再使用object s ...

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

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

  8. [转载]VIM 教程:Learn Vim Progressively

    文章来源:http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/   Learn Vim Progressively   TL ...

  9. QTP操作txt文档

    QTP可以在txt文件(文本文件中读取数据) 首先创造一个文档对象 set fso = createObject("scripting.filesystemobject") 然后用 ...

  10. QTP处理各类鼠标事件fireEvent

    在做web测试时,页面上的HTML标签会包含各类事件:单击(onclick).双击(onDblClick).光标聚集(OnBlur).onchange.onfocus.onmousedown.onmo ...

随机推荐

  1. PHP学习笔记(五)

    关于Response header 的一些小知识: Host :address url,  host 是浏览器给服务器提供的address标识.由于http协议是无状态的,服务器需要根据host的这个 ...

  2. == 和 equals()的区别

    package com.liaojianya.chapter1; /** * This program demonstrates the difference between == and equal ...

  3. Java内存模型JMM与可见性

    Java内存模型JMM与可见性 标签(空格分隔): java 1 何为JMM JMM:通俗地讲,就是描述Java中各种变量(线程共享变量)的访问规则,以及在JVM中将变量存储到内存和从内存中读取变量这 ...

  4. Asp.net创建伪静态页面

    下面是我研究了好几天和同事一起才研究出来的,原创. 1伪静态的定义: 伪静态是相对真实静态来讲的,通常我们为了增强搜索引擎的友好面,都将文章内容生成静态页面,但是有的朋友为了实时的显示一些信息.或者还 ...

  5. http 和 Tcp 的区别

    http 和 tcp 的区别: Http在每一次请求结束后都会主动释放连接,因此HTTP连接是一种“短链接”,要保持客户端程序的在线状态,需要不断地向服务器端发起连接请求. TCP连接时一种“长连接” ...

  6. session阻塞机制,解决方法

    session从生成到读取,或从生成到写入都出现锁定的情况. 1.session_start();session_commit(); 2.session_start();session_write_c ...

  7. 在ECSHOP首页今日特价(促销商品)增加倒计时效果

    看到不少朋友在找首页特价商品倒计时的修改方法,写了这篇文章希望能帮到有此需要的朋友们 1.首先修改程序部分 打开includes/lib_goods.php 找到get_promote_goods() ...

  8. Mysql 与 php动态网站开发 入门教程

    这个系列的教程由表单开始写,因为表单可以把数据库和web 之间的交互表现得很明显.提交表单 ,数据库记录注册信息. 本教程属于基础教程.大神请略过.        对于php和mysql之间的稳固性很 ...

  9. xcopy总是询问是文件名还是目录名

    我需要运行类似xcopy /y a.xml .\pics\b.xml很多次,但xcopy总是问我“文件名还是目录名” 可以这样通过管道来做echo f | xcopy /y a.xml .\pics\ ...

  10. 如何在django的filter中传递字符串变量作为查询条件(动态改变查询条件)

    一般来说在需要查询数据的时候都是以下形式 ret=Articles.objects.filter(id=1) 然而如果要动态的改变查询的条件怎么办呢? 如下代码 def getModelResult( ...