如何使用QTP测试web应用程序



我是QTP的新手。

我需要使用QTP测试Web应用程序。出于学习目的,我使用Gmail登录页面,使用下面的脚本

Systemutil.Run "http://www.gmail.com"
Browser("Title:=Gmail.*").Page("title:=Gmail.*").WebEdit("name:=Email").Set "xxxxxx"
Browser("Title:=Gmail.*").Page("title:=Gmail.*").WebEdit("name:=Passwd").Set "yyyyyy"
Browser("Title:=Gmail.*").Page("title:=Gmail.*").WebButton("name:=Sign in").click

Gmail页面打开后什么也没发生,最后出现一个错误

Cannot find the "[ WebEdit ]" object's parent "[ Browser ]" (class Browser). Verify that parent properties match an object currently displayed in your application.
Line (2): "Browser("Title:=Gmail.*").Page("title:=Gmail.*").WebEdit("name:=Email").Set "xxxxxx"". 
Tip: If the objects in your application have changed, the Maintenance Run Mode can 
help you identify and update your steps and/or the objects in your repository.

还要检查您的浏览器是否支持您的QTP版本!

使用这个结构会更专业:

为每个模块创建:

  • 控制动作调用TestCase的函数库
  • TestCase的函数库:Call Functions(Steps)库
  • 在库中单独的数据库操作
  • 使用objectrerepository Structure Browser/Page/Objects

和享受。

您使用的描述看起来不错(我试过了,它适用于我)。我建议尝试使用Object Spy工具来确认QTP被正确注入到浏览器中,并且您的描述与现有浏览器的描述相匹配。

QTP无法识别您所选择的"title"标识符所指定的浏览器。

假设在GMail时浏览器的识别属性是正确的,最可能的原因是在你尝试执行。set之前页面还没有完成加载(因此浏览器标题不会是" GMail:…")。

以这种方式识别浏览器不是很灵活。请尝试这样做来代替浏览器标识:

Browser("application version:=internet explorer 8") 'though I don't really recommend this way of identifying either.

使用与页面无关的方式来识别浏览器,那么您可以在打开浏览器后添加Sync语句:

Systemutil.Run "http://www.gmail.com"
Browser("application version:=internet explorer 8").Sync
Browser("application version:=internet explorer 8").Page("title:=Gmail.*").WebEdit("name:=Email").Set "xxxxxx" 'If you want to use "title" as an identifier here it'll probably work fine after the sync.

检查是否真的不是同步问题:

  • 您使用的是哪个浏览器?IE ?转到工具>管理附加项,检查HP的"bhommanager类"是否存在并启用。
  • QTP的Web外接程序是否已加载并与您的测试相关联?默认情况下,当QTP加载时,会提示您选择加载项,在您的测试中,您可以进入文件>设置>属性并选中"关联加载项"。

最新更新