如何使用QTP测试Web应用程序?

时间:2013-06-07 06:08:48

标签: qtp

我是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.

4 个答案:

答案 0 :(得分:1)

同时检查您的浏览器是否受QTP版本的支持!

答案 1 :(得分:1)

使用此结构更专业:

你所做的每个模块:

  • 控制操作调用TestCase的函数库
  • TestCase的函数库:调用函数(步骤)库
  • 库中的单独数据库操作
  • 使用ObjectRepository Structure Browser / Page / Objects

并享受。

答案 2 :(得分:0)

错误消息告诉您QTP无法识别您选择的“标题”标识符所指定的浏览器。

假设在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中的“BHOManager类”是否存在并启用。
  • QTP的Web加载项是否已加载并与您的测试相关联?默认情况下,当QTP加载以选择加载项时会出现提示,在测试中,您可以转到文件>设置>属性并选中“关联的加载项”。

答案 3 :(得分:0)

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