由于刚学习QTP,对其中的一些语法、规范等不是很清楚,于是常常犯错。希望我记录的这些错误可以帮助那些初学者
错误一:
If hadlogin Then Browser("AONE").Page("AONE").Frame("Frame").Link("注销").Click
讲解:
属于语法错误,QTP中似乎规定“then”后不能直接跟执行语句,必须换行。
正确的表示应该是
If hadlogin Then
Browser("AONE").Page("AONE").Frame("Frame").Link("注销").Click
----------------------------------------------------------------
错误二:
未设置前后传递的参数,报错信息如下
You specified more parameters in your RunAction statement than the number of parameters defined for the action.
讲解:
在写第一个登录脚本时报了上面的错误,那是我一直查不到原因,后来才发现虽然在脚本上对参数传递做了描述,但在action properties内并没有任何记录。正确的做法是
keyword view中选择action右击->action properties->parameters,增加input parameters
----------------------------------------------------------------
错误三:
QTP9.2和IE7.0的兼容问题,报错信息如下
This run was performed on Internet Explorer 7.x without the required 'Enable Tabbed Browsing' option cleared. Therefore, steps performed on this browser may have unexpected results. It is recommended to clear the 'Tools > Internet Options > Advanced > Enable Tabbed Browsing' option in Internet Explorer and then run this test again. 讲解:
可以做如下三个操作来避免
1.把IE7.0设为默认浏览器
2.清理IE插件(QTP录制时打开IE后,IE关闭信息提示中的插件)
3.Internet选项——常规选项卡中“选项卡”的设置取消勾选“启用选项卡式浏览”
----------------------------------------------------------------
错误四:
将action移植过来时,无法进行相对路径引用
讲解:
Tools->options->folders 增加D:\perth_ta路径
----------------------------------------------------------------
错误五:
从另一个action中传值调用该function,如调用loginperth(url, login_name),出现无法打开指定URL的网页
讲解:
在function所在action内加
url= Parameter("url")
login_name= Parameter("login_name")
错误六:QTP报告自动跳出,如何设置?答:在Options>Run>View results when run session ends。
七 : index的用法 !
以前一直不理解为什么用index 后来看到网上一篇文章感觉很好 , 这里引用一下“有一天,一家学校的校长在典礼上叫了Tom 的名字,这时候有8 位学生都 站了出来。校长事先已经记住了排队顺序中第3 个班的Tom 就是他要叫的。但
由于今天班级顺序都打乱了,校长看了,只能再次叫道,父亲是Jack,出列。幸
运的是,这个时候学生只有2 位。校长再加了个条件,爷爷叫William,父亲是Jack
的出列.最后,就只剩下一个学生出列。
在做Web 的QTP 自动化测试时候,不免会出现这样几种情况:
?? QTP 中相同属性的对象,通过添加Index 去区别;
?? 页面元素动态变化,难以通过Index 去识别; “ 有些意思哦 !
那么index在那里看到值呢 ?当然是objext spy 了 !
(please noted that :index means that the order that such object appeared in code ! )
8.Parameter Question !
1)How to parameter a drop_down list !
e.g. : Browser(browser).page(".....").weblist("......").select"....."
If weblist have 5 list you can use "randomNumber"
indexnum=randomNumber(1,5)
1 is lBound and 5 is uBound
Browser(browser).page(".....").weblist("......").select"#"&indexnum !
2) You must set a parameter in "action properties" when you call a function with some parameters !
9)You can use description pragram , you can use test -object properties and method ! and you can use run-time object properties and method , when you use run-time object properties , you can use object.xx and so on , so you must learn more about dom properties and method !