查看完整版本: 实用函数贴大集合,把大家自己的常用的功能函数贴进来

guirongb 2004-12-9 13:07

实用函数贴大集合,把大家自己的常用的功能函数贴进来

我先来一段。。。。。。

出处:网上下载的,略作修改。

功能说明:出现一个提示对话框,N秒后消失,比如说:提示等待一个窗口阿,有时候这个窗口没了,我也不知道脚本运行到什么地方了,提示一下挺好,也方便其他的测试员修改,而且,也不影响无人值守的操作

例子:SQAMsgbox "test","title",5

Global iTime as Integer

Declare Function TimedDlgFunc(id As String, Action As Integer, SuppValue As Long) As Integer

Declare Function SQAMsgBox(sMsgText as String, Optional vMsgCaption as Variant, Optional vTimeOut as Variant) as Integer


Function TimedDlgFunc(id As String, Action As Integer, SuppValue As Long) As Integer
    Static StartTime
    Dim EndTime
    Dim vTimeoutValue as Variant

    Select Case Action
        Case 1      'Dialog box Initialization
                StartTime = Timer

                If StartTime + iTime >= 86400 Then
                        StartTime = 86400 - StartTime - iTime
                End If
                TimedDlgFunc = 1

        Case 2      'Button pushed or any control changed (except typing in text or combo box)
            Select Case SuppValue
                Case 1
                    DlgEnd -1
                Case 2
                    DlgEnd 0
                Case Else
                    TimedDlgFunc = 0
            End Select

        Case 3      'Change in text or combo box contents
                TimedDlgFunc = 1

        Case 4      'Change of control focus
                TimedDlgFunc = 1

        Case 5      'Idle state (return 0 to prevent this being continually called)
                EndTime = Timer
                If (EndTime - StartTime) >= iTime Then
                        DlgEnd -1
                End If
                vTimeoutValue = Format(iTime - (EndTime - StartTime), "#.#")
                DlgText DlgControlID("txtTimeValue"), CStr(vTimeoutValue)
                TimedDlgFunc = 1
    End Select

End Function


Function SQAMsgBox(sMsgText as String, Optional vMsgCaption as Variant, Optional vTimeOut as Variant) as Integer
    Dim Result as Integer
    Dim TotalTime As Integer
    Dim sCmdText as String   
    Dim sTimeoutText as String
    Dim vValue as Variant

   
    If IsMissing(vMsgCaption) Then
        vMsgCaption = "SQAMsgBox"
    End If
    If IsMissing(vTimeOut) Then
        vTimeOut = 20       'seconds
    End If

    sTimeoutText = "Timeout: "
   
'-----
    Begin Dialog dlgMsgBox 200, 80, vMsgCaption, .TimedDlgFunc
        GroupBox 5, 2, 190, 40, "", .grpMsgTxt
        Text 15, 11, 175, 25, sMsgText, .txtMsgText
        Text 15, 47, 180, 20, sCmdText, .txtCmdText
'--------------
        Button 20, 60, 40, 14, "&OK", .btnOK
        Button 140, 60, 40, 14, "&Cancel", .btnCancel
        Text 78, 63, 30, 10, sTimeoutText, .txtTimeText
        Text 108, 63, 20, 10, vTimeout, .txtTimeValue
    End Dialog
'-----

    Dim TimedDlg As dlgMsgBox
    iTime = CInt(vTimeOut)
    Result = Dialog(TimedDlg)
   
    If Result = 2 Then
        SQAMsgBox = sqaFail
    Else
        SQAMsgBox = sqaPass
    End If   
   
End Function


大家踊跃参加阿,这样我们就会有一大堆实用函数了。使用的朋友请回贴帮顶,谢谢。

[[i] Last edited by guirongb on 2004-12-9 at 13:28 [/i]]

guirongb 2004-12-9 13:08

晕,怎么出现表情符号了??

guirongb 2004-12-9 13:31

没人么?我再来

WIN32 API函数声明下载。直接可以在Robot里面调用。

[[i] Last edited by guirongb on 2004-12-9 at 13:33 [/i]]

duancj_1982 2004-12-9 15:17

顶!!!

guirongb 2004-12-9 16:00

再贴一个,这是我自己写的.....

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

'向目标计算机发送消息
'例如:sendmsg "rsgui","test complete!"
Declare Function SendMsg(computer as string,txt as string)
Function SendMsg(computer as string,txt as string)
dim operate as string
operate="/c net send " & computer & " " & txt
shellexecute 0,"open","cmd.exe",operate,"c:\",0
End Function

alfra 2004-12-10 12:14

最好加上功能说明,以及注释。
这样看起来比较容易懂~建议建议
继续看各位大虾发实用的功能函数,加油加油,非常有用啊~~~~

yuanlj 2004-12-10 12:53

我还不太会用,麻烦各位加上注释哦!

guirongb 2004-12-10 14:49

没劲,就我一个人在发,好吧,再来一个拉

'得到控件的属性,并保留到文件中
function SaveAllPropertyValues (ObjectRec As String, Filename As String)
Dim Result As Integer
Dim Properties() As String
Dim Value As Variant
Dim n As Integer
Open Filename For Output As #1
Result = SQAGetPropertyNames(ObjectRec, Properties)
If Result <> sqaSuccess Then
SQALogMessage sqaWarning, "Unable to capture """ + ObjectRec + """ properties", "Error" + Str$(Result) + ": " + Error$(Result)
Exit function
End If
For n = 0 to UBound(Properties)
Result = SQAGetPropertyAsString(ObjectRec, Properties(n), Value)
If Result = sqaSuccess Then
Write #1, Properties(n), Value
End If
    Next n
    Close #1
SQALogMessage sqaNone, "Properties of " + ObjectRec + " saved in " + Filename, ""
End function

guirongb 2004-12-10 14:50

还有的继续调试好了再发.这几个是用了很多次,也比较有用的,怎么没人呢

z517testing 2004-12-10 15:18

先看一看

高山来客 2004-12-10 22:31

不错,还没使用过,最好加点注释?

jwzvic 2004-12-14 09:45

老大有 抓 控间 属性  值 的代码吗?谢谢

viviana_wdy 2004-12-14 10:37

谢谢阿,这样的帖子实用性很高呢

Aaron 2004-12-21 21:17

顶一个。不过能给出调用说明就好了。SaveAllPropertyValues 我就调不成功

BlueDream811027 2004-12-21 23:09

我才刚接触Robot,
guirongb你能不能给我点指点?

Aaron 2004-12-22 09:44

那个函数SaveAllPropertyValues调成功了,不错。可惜我得到一个控件的属性Value,它的值 为文本(比方说,pls select an item),但在我的函数中用Getproperty时得到的却为数值1

jyxuan 2005-1-19 17:00

我来顶啦

archonwang 2005-2-16 08:53

东西很好啊,建议版主考虑下加精吧?

baitest 2005-2-16 09:07

好东西,顶一下!

zhuyw01 2006-2-7 14:08

好东西啊,可怎么没有几个人呢?可惜偶还不会,要不一定也发几个上来!

fazi1223 2006-2-8 12:23

俺是新手,刚装上ROBOT,我想在录入内容时加入一点时间信息,应该怎么写呢?如下所示我想在倒数第二行末加上录当前数据时的时间?
EditBox Left_Drag, "Name=InputSum", "Coords=8,8,-9,9"
    InputKeys "80"
    EditBox Click, "Name=Summary", "Coords=27,15"
    InputKeys "robot"
    HTMLImage Click, "Index=3", "Coords=30,16"

caesarqth 2006-2-11 11:34

很好用,多谢楼主了

还有比较使用的函数吗,希望多发点 谢谢楼住

wonderswan 2006-2-13 10:23

那么好的东西!·~~支持你!~~

testman 2006-2-23 09:19

学习学习

dliwenzi 2006-3-2 17:30

实用,好东西

weiping2000 2006-3-27 19:40

支持,好东西,学习中

xiao* 2006-4-5 16:44

谢谢!继续

非常好

閒逛 2006-4-20 22:26

先学着点!

joyruan@126.com 2006-4-28 18:01

好,支持。继续

a995147 2006-5-7 15:46

thanks

ax2004 2006-6-5 20:59

我不觉得,楼主 所写的 获得控件属性值 ,并写入文件 有什么太大用处,就我个人使用而言, 我觉得,大家 多用用
SQAgetPropertyValue 和 SQAWaitforPropertyValue ,SQAlogMessage以及 Msgbox这几个常用函数就构了, 第一个函数,我们常用来获取一些对象 某个属性值,用它进行判断,或者于预期值进行比较.

我们不需要得到控件的所有属性值,事实上,某些没有太大的用处,所以用第一个函数,就构了.

第二个函数,主要用来判断某个对象(控件)存不存在,或者说在指定时间内存在时,作者希望 作些什么其它操作.

第三个函数,常用来,将作者认为 有必要的信息,写进 结果日志里.(当一个脚本很长的时候,通常可以判断脚本执行到何处)

最后一个函数, 常用来调试脚本,当对脚本进行参数化后,希望运行时得到某些参数值的时候,经常用到.sdlkfj5

kylixlu 2007-4-20 13:43

顶一下:)

chaotiancaitl 2007-6-4 16:42

学习一下,很有用

monkey_hou 2007-6-6 10:55

函数集合呀  谢谢大家无私奉献

cshwjj 2007-6-7 14:15

集合,不集怎么能合?

yglg0003 2007-8-24 10:21

看不懂,搬到家里去研究

haiqin 2007-9-3 15:51

俺 只是个新手,刚看这个,没东西 啊

liujihui226 2007-9-14 11:04

什么时候用努力力学习中

xiangxiang1999 2008-3-7 17:59

3Q

感动了,顶一下,共同学习,共同进步!!

tt2008 2008-8-2 00:20

hhhhhhhhhhhhhhhh
页: [1] 2
查看完整版本: 实用函数贴大集合,把大家自己的常用的功能函数贴进来