QTP执行过程对抛出窗口录入的密码的加密和录入的数据的获得

有这样一种需求,就是在QTP回放的过程中需要抛出一个录入框,操作者录入的密码显示是加密的(*****的样子),但是要能在后面的脚本获取操作者输入的数据。

可能很多人要问,自动化的过程为什么要人去输入操作。

 

这里先把这个问题的前提阐述一下:

我们的脚本是全球共享的,每个tester都有自己的用户名密码 去访问那个脚本 所以在access脚本的前面就需要QTP 弹出一个交互的对话框让tester去登陆才能access到 脚本的专署的信息,却又不能看到其他人的信息。

经过核查QTP 目前没有发现可以加密的函数,vbs也没有内置的function来提供这种功能。

所以结决方案的思路就是调用IE来create masked对话框

代码如下: 只需要copy到QTP的专家视图,直接run就可以了(也可单独保存为VBS文件运行)

strPw = GetPassword( “Please enter your password:” )51Testing软件测试网:z d P7]J
msgbox strPw

51Testing软件测试网.o/wtxrp2X(f4O7l
Function GetPassword( myPrompt )

Dim objIE51Testing软件测试网4x,j? v8S^
‘ Create an IE object51Testing软件测试网,eghGE1x
Set ōbjIE = CreateObject( “InternetExplorer.Application” )51Testing软件测试网w!\’M”N8\Y VSd
‘ specify some of the IE window’s settings51Testing软件测试网$Hx^Vu_
objIE.Navigate “about:blank”51Testing软件测试网8v/d8S ](@^7~
objIE.Document.Title = “Password”51Testing软件测试网3@4^#{.}#hT,v*vp
objIE.ToolBar = False
+j3~.X6Y5H21468objIE.Resizable = False51Testing软件测试网E iX _ {4X n/~w”L
objIE.StatusBar = False
$~Y7w9d,h4~21468objIE.Width = 320
A7p(~j5PW%h+X21468objIE.Height = 180

Do While objIE.Busy51Testing软件测试网 OqM%d\%h
51Testing软件测试网A*Y,o!H]m%y
Loop51Testing软件测试网Ctt/p*Q+U4F_
‘ Insert the HTML code to prompt for a password
!~*H%yEh21468objIE.Document.Body.InnerHTML = “<DIV align=”"center”"><P>” & myPrompt _51Testing软件测试网;hTg3}Z.o2N
& “</P>” & vbCrLf _51Testing软件测试网8?d%s E(G+d8K9|j8?
& “<P><INPUT TYPE=”"password”" SIZE=”"20″” ” _
O?W9{9q2o Pm*@B21468& “ID=”"Password”"></P>” & vbCrLf _51Testing软件测试网j{sj+E:c6b
& “<P><INPUT TYPE=”"hidden”" ID=”"OK”" ” _
0t,jR ]n”[:j21468& "NAME=""OK"" VALUE=""0"">" _
r+uOi/H'B5t/Xh@a8X21468& "<INPUT TYPE=""submit"" VALUE="" OK "" " _
\+t0q-~o(R-t21468& "OnClick=""VBscrīpt:OK.Value=1""></P></DIV>"51Testing软件测试网\%@LH/I"~3^EY&]
‘ Make the window visible
+R` `s(P L+P5l_21468objIE.Visible = True
eRIS}L-ckn21468‘ Wait till the OK button has been clicked51Testing软件测试网8b~S s*I^ qu%v
Do While objIE.Document.All.OK.Value = 0

Loop51Testing软件测试网3D{8C2] wN$v5o
‘ Read the password from the dialog window
,Zp&Um@7?e?A21468GetPassword = objIE.Document.All.Password.Value51Testing软件测试网0~N6nc&`”N%t J(Cs(T
‘ Close and release the object51Testing软件测试网~5u B3F.Ef
objIE.Quit
o-GXZkl#El21468Set ōbjIE = Nothing
Owl.m9| H9e21468End Function

 

 

参考信息:

http://www.microsoft.com/technet/scrīptcenter/resources/qanda/feb05/hey0204.mspx

———————————————

另外

(1)如果在正常的情况下需要加密密码,QTP提供password encoder 可以generate 出加密后的string。

(2) 显示密码信息

 抓取密码

  getROProperty(<Object Property the Stores the Password>) …ie try getROProperty(“Password”)

显示信息
       MsgBox
(3)对某些列进行掩盖:
Browser(“Browser”).Page(“Webpage”).WebEdit(“txtPassword”).SetSecure (“User password”)
 

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Add to favorites
  • email
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • StumbleUpon
  • Twitter
  • Yahoo! Buzz
  • 豆瓣
  • 豆瓣九点

Tags: , ,

Leave a Comment