YONGFEIUALL

izheyi.com


  • Home

  • Archives

  • Categories

  • Tags

  • About

  • Search

QTP为脚本自动创建注释(Action 模板)

Posted on 2012-11-05 | In QTP |

当希望在每一个新建action时都增加一些头部说明,比如作者、创建日期、说明等信息,那么用action template 来实现最简单快捷。

方法:用记事本等文本编辑器,输入如下类似的内容:

‘Company: 唐胡璐

‘Date: Date

然后将文件保存为ActionTemplate.mst,并存放到QTP安装目录下的dat目录。

QTP注册开启HOOK(多插件嵌套)

Posted on 2012-10-19 | In QTP |

我们有测试的过程中,可能会碰到这种情况,在C/S的系统中会嵌套Web,这时候QTP根本无法识别此Browser对象,直接是抛了个WinObject出来,title还是Internet Explorer_Server。

解决方法

  1. 进入到QTP的核心目录: 《安装目录》/bin 下找到 mic.ini (此文件是关键文件)

  2. 用记事本打开此INI文件。我们都知道INI格式的都是配置文件,可以直接在里面更改我们需要的配置。

  3. 找到[ie_hook]部分段落。

  4. 在这一栏的最后添加一行应用程序的 文件名+后缀名 = yes后保存。(E.g., Google.exe = yes)

  5. 修改完毕之后,重启QTP,再次重启刚才的应用程序,此时我们再来看一下spy的结果。QTP当然也相当的给力,成功把Browser对象识别为Page对象。包括对象库也可以任意添加。

QTP识别web页面时候结果为winobject

Posted on 2012-10-17 | In QTP |

QTP SPY无法识别此对象,会把所有web对象都识别为winobject。

方法

  1. 把IE和QTP都关掉,然后先打开QTP,再打开IE,这样就能识别了。

  2. 如果这样不行的话:

    • XP下: 查看IE加载项,查看BHOManager Class是否已经被加载,而且状态为Enable.没有做修改,保持现状。(若没有BHOManager Class 加载项,则在QTP安装文件下找到BHOManager.dll(目录为*\QuickTest\MSI\System32,自己搜索下)并复制到C:\WINDOWS\system32下)重新注册此dll,打开命令提示符,运行命令:regsvr32 c:\windows\SysWOW64\BHOManager.dll

    • Win7下:查看IE加载项,查看BHOManager Class是否已经被加载,而且状态为Enable.没有做修改,保持现状。(若没有BHOManager Class 加载项,则在QTP安装文件下找到BHOManager.dll并复制到c:\windows\SysWOW64下)重新注册此dll. 以管理员权限打开命令提示符,运行命令:regsvr32 c:\windows\SysWOW64\BHOManager.dll

  3. 若还不行则在用户账户控制设置里把权限设置到最低。(建议:如果方法1不行,先使用该方法。)

VBS用FSO改变文件属性

Posted on 2012-10-09 | In VBS |

在框架的执行中,我们会碰见这样的情况,从代码库里下来的文件属性都是只读的,在运行的时候就没办法对其操作,我们可以通过以下方式来改变文件的属性:

1
2
3
Set fso = CreateObject( "Scripting.FileSystemObject" )
fso.GetFile(LogFilePath).Attributes = 0
Set fso = Nothing

Attributes
Normal 0 普通文件。没有设置任何属性。
ReadOnly 1 只读文件。可读写。
Hidden 2 隐藏文件。可读写。
System 4 系统文件。可读写。
Directory 16 文件夹或目录。只读。
Archive 32 上次备份后已更改的文件。可读写。
Alias 1024 链接或快捷方式。只读。
Compressed 2048 压缩文件。只读。搜索

如果相应用多种属性,只须把它们的值加起来。

VBS send mail

Posted on 2012-10-09 | In VBS |

2 methods:

Sending Mail with OutLook

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Function SendMail()
Dim objOutlook, Mail, PopupLocate

' Create Email object
Set objOutlook=CreateObject("Outlook.Application")
Set objMail=objOutlook.CreateItem(0)

' Setting receiver
objMail.to= "yongfeiuall@163.com"
objMail.cc= "yongfeiuall@163.com"

' Setting title & content & attached
objMail.Subject="自动化测试结果"
objMail.Body="自动化测试结果"
objMail.Attachments.Add("e:\test.htm")

' Mail send
SystemUtil.Run "..\QTP\OutlookSecurityPopup.vbs"
objMail.Send

' 注销Email对象
objOutlook.Quit
Set objMail = Nothing
Set objOutlook = Nothing
End Function

OutlookSecurityPopup

1
2
3
4
5
6
7
8
9
10
11
12
13
Set fso = CreateObject("WScript.Shell")
if fso.AppActivate("Microsoft Office Outlook") = FALSE then
wscript.Sleep 10000
end if

if fso.AppActivate("Microsoft Office Outlook") = true then
wscript.Sleep 1000
fso.AppActivate("Microsoft Office Outlook")
fso.SendKeys "{tab}"
fso.SendKeys "{tab}"
wscript.sleep 1000
fso.SendKeys "{ENTER}"
end if

Sending mail without a security popup

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Const SMTPSERVER = "xxxxxx"
Const MailFrom = "xxxxxx" '发件人邮箱
Const MailPWD = "xxxxxx" '发件人邮箱密码
Const SendTo = "yongfeiuall@163.com" '收件人邮箱
Const Body = "<a href=""http://www.izheyi.com"" >Click Here</a>"

Dim objMail, UseHTML

'Create Email object
Set objMail = CreateObject("CDO.Message")

'Setting sender & receiver
objMail.From = MailFrom
objMail.To = SendTo
'objMail.CC = CC

'Setting title & content & attached
objMail.Subject = "Subject"
objMail.AddAttachment(ExcelReport)
objMail.HTMLBody = "<H5>Below is the example of email with Hyperlink</H5><br>" + Body

'Define mail configuration
Const schema = "http://schemas.microsoft.com/cdo/configuration/"
With objMail.Configuration.Fields
.Item(schema & "sendusing") = 2
.Item(schema & "smtpserver") = SMTPSERVER
.Item(schema & "smtpauthenticate") = 1
.Item(schema & "sendusername") = MailFrom
.Item(schema & "sendpassword") = MailPWD
.Item(schema & "smtpconnectiontimeout") = 60
.Update
End With

'Send mail
objMail.Send

Pad Number String with Zeroes(在字符串左侧补0)

Posted on 2012-08-08 | In VBS |

例如,在设计框架或写脚本的时候,总会碰见日期格式的问题,需要在不够十位的月份上补0,等等。。

实现方法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 '******************************************************************************* 
'Description : Pads a number with zeroes on the left, according to the expected maximum length of the numbers in the list. ' 

'Purpose : To keep a number list sorted properly, as with a file list (001, 002,..., 010, and not 1, 10, 11,..., 2, 20). ' 

'Arguments : intCurrentNum (the current number to be padded) 
            'intMaxNumInList (the top number in the list) 

'Note: The arguments are always taken in absolute values 

'Returns : The padded intCurrentNum (for example, If 1 and 9999 are sent to the function, the result will be 0001) ' 

'*******************************************************************************  
Public Function PadNumber(ByVal intCurrentNum, ByVal intMaxNumInList) 
   
'Validates the arguments - if invalid then it returns the value as is     
    If (Not IsNumeric(intCurrentNum) Or Not IsNumeric(intMaxNumInList)) Then         
        PadNumber = intCurrentNum         
        Exit Function     
    End If    
     
    If (Abs(intCurrentNum) >= Abs(intMaxNumInList)) Then         
        PadNumber = intCurrentNum         
        Exit Function     
    End If     
    
    PadNumber = String(len(CStr(Abs(intMaxNumInList)))-len(CStr(Abs(intCurrentNum))), "0") _  
                 & CStr(Abs(intCurrentNum)) 
                   
End Function 


'*******************************************************************************  
'Msgbox PadNumber(4, 34567)    'Returns 00004 
'Msgbox PadNumber(-4, 34567)   'Returns 00004  
'Msgbox PadNumber(4, -34567)   'Returns 00004 
'Msgbox PadNumber(34567, 4)    'Returns 34567 
'Msgbox PadNumber(4, 9)        'Returns 4 
'Msgbox PadNumber("Hello", 9999) 'Returns Hello

Generate Random String(产生随机数)

Posted on 2012-07-20 | In VBS |
1
2
3
4
5
6
7
8
9
10
Function RandomString( ByVal strLen )     
    Dim str     
    Const LETTERS = "abcdefghijklmnopqrstuvwxyz0123456789"

    For i = 1 to strLen      
        str = str & Mid( LETTERS, RandomNumber( 1, Len( LETTERS ) ), 1 )     
    Next     

    RandomString = str 
End Function

vbs引用(include)外部函数库

Posted on 2012-06-09 | In VBS |

我们经常会碰见这样的情况,脚本A中想引用脚本B中的方法,VBS中可能通过以下方法来实现:

1
2
3
4
5
6
     Function Include(strFileName)
        Dim objFileContent
        Set objFileContent = CreateObject("Scripting.FileSystemObject").OpenTextFile(strFileName,1,False) 
        ExecuteGlobal objFileContent.ReadAll
        Set objFileContent = Nothing   
    End Function

在脚本A中加入这个Function,调用此Function:

1
Call Include(ProjectPath + "脚本B.vbs")

这样即可实现外部函数的调用。

QTP工具的一些小技巧

Posted on 2012-05-15 | In QTP |

在使用QTP的过程中总结了以下几点小技巧,以备查询:

Read more »

最小化QTP窗口

Posted on 2012-04-25 | In QTP |

AOM自动化模型方式

1
2
3
Set qtp = CreateObject( "QuickTest.Application" )
qtp.WindowState = "Minimized"
Set qtp = Nothing

直接获取QTP窗口对象进行最小化

1
2
3
Set qtpWindow = Window("title:=QuickTest.*")
qtpWindow.highlight
qtpWindow.Minimize
1…383940
唐胡璐

唐胡璐

i just wanna live while i am alive

393 posts
42 categories
74 tags
RSS
LinkedIn Weibo GitHub E-Mail
Creative Commons
© 2022 唐胡璐
Powered by Hexo
|
Theme — NexT.Pisces v5.1.4