ni_xh 发表于 2006-1-13 17:44:58

一个测试用户名及密码的登录小程序,请大家指教

用到了datapool


'$Include "sqautil.sbh"

Sub Main

    Dim Result As Integer
   
    Dim dp_id as Long

    Dim dp_Result as Long
   
    Dim strName as String

    Dim strPassWord as String

    'Initially Recorded: 2006-1-1314:26:45
    'Script Name: login
   
    StartApplication """XXXXX"""
   
    dp_id = SQADatapoolOpen ("dp", FALSE, SQA_DP_SEQUENTIAL, FALSE)
   

    dp_Result = SQADatapoolFetch (dp_id)


   while dp_Result <>sqaDpEOF

   
         dp_Result = SQADatapoolValue (dp_id, "name", strName)

         dp_Result = SQADatapoolValue (dp_id, "password", strPassWord)

         dp_Result = SQADatapoolFetch (dp_id)
         
   
    EditBox Click, "Type=Form;Name=FrmLogin;\;Type=Control;Name=txt_userName;\;Type=EditBox;Index=0", "Coords=23,2"
    '输入用户名   
    InputKeys strName
   
    EditBox Click, "Type=Form;Name=FrmLogin;\;Type=Control;Name=txt_password;\;Type=EditBox;Index=0", "Coords=49,0"
'输入用户密码   
InputKeys strPassWord
   
    GenericObject Click, "Type=Form;Name=FrmLogin;\;Type=Control;Name=btn_login", "Coords=57,17"
   
    Window SetContext, "Type=Form;Name=MainForm;VisualText=新港信息系统", ""
   
    Window SetContext, "Type=Form;Name=MainForm", ""
   
'验证是否成功登录
   Result = RegionVP (CompareImage, "", "VP=Region Image;Wait=2,30;Coords=205,392,574,561")
   
    if result = 1 then
   
      '如果成功登录,注销用户,清除用户名及密码   
   GenericObject Click, "Type=Form;Name=MainForm;\;Type=Control;Index=8;\;Type=Control;Index=0", "Coords=24,11"
   
      Window SetContext, "Class=WindowsForms.Window.808", "Activate=0"
      GenericObject Click, "Class=WindowsForms.Window.8;ClassIndex=1", "Coords=46,28"
   
      Window SetContext, "Type=Form;Name=FrmLogin", ""
      EditBox Left_Drag, "Type=Form;Name=FrmLogin;\;Type=Control;Name=txt_userName;\;Type=EditBox;Index=0", "Coords=45,9,-63,9"
      InputKeys "{BKSP}"
      EditBox Left_Drag, "Type=Form;Name=FrmLogin;\;Type=Control;Name=txt_password;\;Type=EditBox;Index=0", "Coords=47,8,-10,8"
      InputKeys "{BKSP}"
      EditBox Click, "Type=Form;Name=FrmLogin;\;Type=Control;Name=txt_userName;\;Type=EditBox;Index=0", "Coords=7,10"

    else
      '如果用户名、密码错误,无法登录,直接清除用户名及密码   
   Window SetContext, "Type=Form;Name=FrmLogin", ""
      EditBox Left_Drag, "Type=Form;Name=FrmLogin;\;Type=Control;Name=txt_userName;\;Type=EditBox;Index=0", "Coords=100,9,-70,9"
      InputKeys "{BKSP}"
      EditBox Left_Drag, "Type=Form;Name=FrmLogin;\;Type=Control;Name=txt_password;\;Type=EditBox;Index=0", "Coords=100,8,-70,8"
      InputKeys "{BKSP}"
      EditBox Click, "Type=Form;Name=FrmLogin;\;Type=Control;Name=txt_userName;\;Type=EditBox;Index=0", "Coords=7,10"
   
   end if
   
   wend

   dp_Result = SQADatapoolClose (dp_id)
End Sub

ilovejolly 发表于 2006-1-13 20:25:41

无法登陆后面应该接着处理,可以直接跳转到再取datapool下一条记录。
脚本里少了最重要的步骤,写log,没有log的脚本对我们是没有价值的。
作为一个完整的脚本,对dp_Result可以每取一次判断一下。

btw,是什么语言开发的winform,怎么那么多控件不认识的,居然连btn都不认识。

ni_xh 发表于 2006-1-16 10:46:38

原帖由 ilovejolly 于 2006-1-13 20:25 发表


btw,是什 ...


.net开发的。

ni_xh 发表于 2006-1-16 10:52:38

增加了几条日志信息

'$Include "sqautil.sbh"



Sub Main

    Dim Result As Integer
   
    Dim dp_id as Long

    Dim dp_Result as Long
   
    Dim strName as String

    Dim strPassWord as String

    'Initially Recorded: 2006-1-1314:26:45
    'Script Name: login
    sqalogmessage sqanone,"启动应用程序",""
   
    StartApplication """D:\Program Files\plt\OilportSetup\oilport.exe"""
   
    dp_id = SQADatapoolOpen ("dp", FALSE, SQA_DP_SEQUENTIAL, FALSE)
   

    dp_Result = SQADatapoolFetch (dp_id)


   while dp_Result <>sqaDpEOF

   
         dp_Result = SQADatapoolValue (dp_id, "name", strName)

         dp_Result = SQADatapoolValue (dp_id, "password", strPassWord)

         dp_Result = SQADatapoolFetch (dp_id)
         
   
    EditBox Click, "Type=Form;Name=FrmLogin;\;Type=Control;Name=txt_userName;\;Type=EditBox;Index=0", "Coords=23,2"
   '输入用户名   
    InputKeys strName
   
    EditBox Click, "Type=Form;Name=FrmLogin;\;Type=Control;Name=txt_password;\;Type=EditBox;Index=0", "Coords=49,0"
    '输入用户密码
    InputKeys strPassWord
   
    GenericObject Click, "Type=Form;Name=FrmLogin;\;Type=Control;Name=btn_login", "Coords=57,17"
   
    Window SetContext, "Type=Form;Name=MainForm;VisualText=新港信息系统", ""
   
    Window SetContext, "Type=Form;Name=MainForm", ""
   
   '验证是否成功登录
   Result = RegionVP (CompareImage, "", "VP=Region Image;Wait=2,30;Coords=205,392,574,561")
   
    if result = 1 then
   
      '如果成功登录,注销用户,清除用户名及密码,取datapool的下一条数据
      GenericObject Click, "Type=Form;Name=MainForm;\;Type=Control;Index=8;\;Type=Control;Index=0", "Coords=24,11"
   
      Window SetContext, "Class=WindowsForms.Window.808", "Activate=0"
      GenericObject Click, "Class=WindowsForms.Window.8;ClassIndex=1", "Coords=46,28"
   
      Window SetContext, "Type=Form;Name=FrmLogin", ""
      EditBox Left_Drag, "Type=Form;Name=FrmLogin;\;Type=Control;Name=txt_userName;\;Type=EditBox;Index=0", "Coords=45,9,-63,9"
      InputKeys "{BKSP}"
      EditBox Left_Drag, "Type=Form;Name=FrmLogin;\;Type=Control;Name=txt_password;\;Type=EditBox;Index=0", "Coords=47,8,-10,8"
      InputKeys "{BKSP}"
      EditBox Click, "Type=Form;Name=FrmLogin;\;Type=Control;Name=txt_userName;\;Type=EditBox;Index=0", "Coords=7,10"

      sqalogmessage sqapass,"正确的用户名及密码","该用户成功登录"
    else
      '如果用户名、密码错误,无法登录,直接清除用户名及密码,取datapool的下一条数据

      sqalogmessage sqapass,"错误的用户名及密码","该用户不能登录"

      Window SetContext, "Type=Form;Name=FrmLogin", ""
      EditBox Left_Drag, "Type=Form;Name=FrmLogin;\;Type=Control;Name=txt_userName;\;Type=EditBox;Index=0", "Coords=100,9,-70,9"
      InputKeys "{BKSP}"
      EditBox Left_Drag, "Type=Form;Name=FrmLogin;\;Type=Control;Name=txt_password;\;Type=EditBox;Index=0", "Coords=100,8,-70,8"
      InputKeys "{BKSP}"
      EditBox Click, "Type=Form;Name=FrmLogin;\;Type=Control;Name=txt_userName;\;Type=EditBox;Index=0", "Coords=7,10"
   
      
   end if
   
   wend

   dp_Result = SQADatapoolClose (dp_id)
End Sub

ni_xh 发表于 2006-1-16 10:53:44

日志的应用

test log信息中的details,其中有个column“failure reason”,这列的信息是否可以通过logmessage写入?用什么命令?

ilovejolly 发表于 2006-1-16 11:26:33

SQAVpLog,具体用法可以参考帮助

脚本里这么多不能识别的,回放没问题?.net的winform我没试过

ni_xh 发表于 2006-1-16 15:01:26

使用SQAVPlog,回放脚本之后,在日志文件中增加了custom的日志信息。查看日志的property,增加了failure discriptation ,但是failure reason仍是空的。
还需要继续查找哦。


.net的winform 脚本里不识别的确实很多,但回放没问题。

fancylee 发表于 2006-1-23 14:24:11

原帖由 ilovejolly 于 2006-1-16 11:26 发表

脚本里这么多不能识别的,回放没问题?

别人的脚本拿到自己的机器上能直接回放吗??
我的同事们,一个人在自己的机器上录制后,在另一个人的机器上就不能回放,这是怎么回事呢??

ilovejolly 发表于 2006-1-26 09:39:02

你看一下在什么地方卡住了
页: [1]
查看完整版本: 一个测试用户名及密码的登录小程序,请大家指教