51Testing软件测试论坛

标题: 请教一下嵌套action的全局变量问题 [打印本页]

作者: 论坛守护神    时间: 2009-9-30 18:41
标题: 请教一下嵌套action的全局变量问题
我有两个action,一个是main action,控制的,一个是登陆操作action1。一个vbs文件test.vbs作为存放全局变量的地方,里面就两句
public abc
abc = 3
想法是:
在main action里面
ExecuteFile ("D:\test.vbs")
变量abc正常导入。
开始call action1.
action1里面先使用abc,结束前再更新abc。
main action根据abc的结果继续下面的操作

实际结果是
在调用action1时,abc传不进去也出不来。

求教一下,谢谢各位。
作者: 论坛守护神    时间: 2009-10-5 21:54
顶,顺便祝大家佳节愉快
作者: dabeixiong    时间: 2009-10-7 01:35
实际结果是
在调用action1时,abc传不进去也出不来。


你的实际结果令我很吃惊啊,因为根据你的描述我这里能够输出vbs脚本中的Public变量abc-.-!

据我个人分析...你一定是忘记把VBS脚本和你的QTP Test关联起来...

关联步骤:
->Select File on your QTP menu
->Select Settings..
->Select "Resources" Tab
->Associated function libraries(click the + button)
->choose your vbs script
作者: 论坛守护神    时间: 2009-10-7 15:38
我自己也是相当的奇怪呢,把代码贴到这里。麻烦给位给看看
为了避免混淆,test.vbs里面改为一句
public abc

主action
ExecuteFile ("D:\test.vbs")                                              '导入vbs文件
RunAction "Regulus_View2_Logon [Logon]", oneIteration, Outputvalue       '调用登陆action

If abc = 1 Then                                                      
        msgbox("successful")
else
   msgbox("fail")
End If

登陆action
On error resume next

SystemUtil.Run "iexplore.exe","http://192.168.3.96:7777/view2/Login.html"

Browser("Browser").Page("Page").Sync
     If Browser("Browser").Page("Regulus View&sup2;").WebEdit("userName").Object.value <>  "" Then
         Browser("Browser").Page("Regulus View&sup2;").WebEdit("password").Object.value = "Test"
         Browser("Browser").Page("Regulus View&sup2;").Link("Login").Click
         else
         Browser("Browser").Page("Regulus View&sup2;").WebEdit("username").Set  "all"
         Browser("Browser").Page("Regulus View&sup2;").WebEdit("password").SetSecure "4ac1bf21be03113115da983ae60af208e303a8cb386c"
         Browser("Browser").Page("Regulus View&sup2;").Link("Login").Click
         End If
Browser("Browser").Page("Page").Sync

'判断logout的值,如果成功则修改abc为1,标示登陆成功
If Browser("Browser").Page("Regulus View&sup2; - Home").WebElement("LOGOUT").GetROProperty("value") = "LOGOUT" then
Reporter.ReportEvent micFail,"Logon","Logon failed"
Parameter("FlaLogon") = false
Else
Reporter.ReportEvent micPass,"Logon","Logon successful"
abc = 1                                                                                                
Parameter("FlaLogon") = true
End if


跟踪看了一下,1是赋给了abc的,但是出来以后就没值了。

[ 本帖最后由 论坛守护神 于 2009-10-7 15:42 编辑 ]
作者: Haereticus    时间: 2009-10-7 15:44
When you run an ExecuteFile statement within an action, you can call the functions in the file only from the current action. To make the functions in a VBScript file available to your entire test, add the file name to the associated function libraries list in the Resources tab of the Test Settings dialog box. For more information, see Working with Associated Function Libraries.
作者: Haereticus    时间: 2009-10-7 15:45
When you run an ExecuteFile statement within an action, you can call the functions in the file only from the current action. To make the functions in a VBScript file available to your entire test, add the file name to the associated function libraries list in the Resources tab of the Test Settings dialog box. For more information, see Working with Associated Function Libraries.
作者: 论坛守护神    时间: 2009-10-7 23:28
To Haereticus
我已经把test.vbs作为resource添加进主action和logon action了。。
作者: Haereticus    时间: 2009-10-8 14:07
在你脚本里修改的值只是临时修改了abc的值,类似于一个局部变量,要修改abc的值你必须修改test.vbs文件里abc的值,然后重新执行ExecuteFile ("D:\test.vbs"),才会生效。其实全局变量的通常方法,一般是把变量保存在一个xml文件,这样可随时修改变量的值,然后再加载进来就OK了
作者: dabeixiong    时间: 2009-10-8 23:04
恩~楼上说的在理...
我也看了下帮助:
If you decide not to associate a function library (any VBScript file) with a test, but do want to be able to call its functions, subroutines, and so forth from an action in your test or from another function library, you can do so by inserting an ExecuteFile statement in your action.

看来ExecuteFile是在你不想分配给Test函数库的时候才用呢...所以你的用法有问题-.-!

你把ExecuteFile去掉试试,附上我的试验脚本,你可以瞄一眼...
作者: sunhao88    时间: 2009-10-9 10:20
你需要在登陆action中把abc的值传出去,然后在主action中 把RunAction "Regulus_View2_Logon [Logon]", oneIteration, Outputvalue  中的Outputvalue,使abc=Outputvalue  你需要在 登陆action中  设置  输出变量,并把 abc的值传给输出变量

[ 本帖最后由 sunhao88 于 2009-10-9 10:23 编辑 ]
作者: 论坛守护神    时间: 2009-10-9 18:41
谢谢各位,重新试了一下。问题解决。我原来设想的方式是
1.通过写和读这个vbs来传变量
2. 不手工加载resource vbs(方便自动化)

上面朋友提供的直接加resource和传统的传参数都是可以用的,继续研究一下xml方法看能用不。谢谢again




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2