51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 7194|回复: 12
打印 上一主题 下一主题

[Robot] How to get a tree node's property using Robot?

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2004-7-5 17:11:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
For instance,  a treeView control contains 3 nodes.  The first node's text is "Apple".  How to get this node text?  
TreeView control is VS.NET's.

OS: win2k sever + VS.NET2003 + Robot 2003
Log: I tried to user SqaGetPropertyArray("Type=TreeView;ObjectIndex=1", "Nodes",Values)  Failed

:,(
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏

该用户从未签到

2#
发表于 2004-7-6 10:51:37 | 只看该作者
SqaGetPropertyArray("Type=TreeView;ObjectIndex=1", "Nodes",Values)

是用来取得对象的属性的,而你要得到的 节点的 Text 应该属于对象的Data
所以不行
回复 支持 反对

使用道具 举报

该用户从未签到

3#
发表于 2004-7-6 10:54:15 | 只看该作者

有一个比较笨的办法

Robot 能不能识别.net树呢?如果可以的话,可以先得到Tree的data
Robot里对所有对象的Data都是以table的形式来存储的(个人看法)
例如有这样的一棵树

中国
┣北京
┗江苏
  ┣南京
  ┗苏州

在Robot里就是这样的一个Table形式来表示的

┏━━┳━━┳━━┓
┃中国┃      ┃      ┃
┣━━╋━━╋━━┫
┃      ┃北京┃      ┃
┣━━╋━━╋━━┫
┃      ┃江苏┃      ┃
┣━━╋━━╋━━┫
┃      ┃      ┃南京┃
┣━━╋━━╋━━┫
┃      ┃      ┃苏州┃
┗━━┻━━┻━━┛

那么我们就能从Robot里读取一个3×5的二维数组,解析二维数组

[ Last edited by oiwenwen on 2004-7-6 at 11:04 ]
回复 支持 反对

使用道具 举报

该用户从未签到

4#
发表于 2004-7-6 10:57:53 | 只看该作者

对于如何读取一个对象的Data,RRAFS里有一个函数

Function DDGGetGUIObjectData (guiID As String, values() As Variant, Optional dataTest As Variant) As Integer

    Const OBJECT_DATA_VP = "objectdata"
    Const VPTYPE        = "grd"
    Const VPEXT         = ".grd"
    Const VPBASEEXT     = ".base.grd"
    Const VPEXPEXT      = ".exp.grd"
    Const VPACTUAL      = ".act*"
    CONST VPMEXT        = ".vpm"

    Const DEFAULT_DATA_TEST = "Contents"
   
    Dim status As Integer
    Dim vpbase As String
    Dim vpvpm as String
    Dim vpvpm2 as String
    Dim vpexp As String
    Dim vpact as String
    Dim tpath As String
    Dim actual as Integer
    Dim vpDataTest As String
   
    ' what object data to capture?
    If IsMissing(dataTest) Then
        vpDataTest = DEFAULT_DATA_TEST
    Else
        vpDataTest = dataTest
    End If

    Dim aTemp() as String
    Dim aTemp2() as String
    Dim record as String
    Dim aNull As Integer
    Dim row AS Integer, rows as Integer
    Dim col AS Integer, cols as Integer, tcols as Integer
   
    On Error Resume Next
    DDGGetGUIObjectData = -1
   
    'have SQA give us a valid VP ACTUAL name to use for our dummy VP   
    vpbase = SQAVpGetCurrentBaselineFileName (OBJECT_DATA_VP, VPTYPE)
    'SQACONSOLEWRITE "DEBUG: vpbase = "& vpbase
   
    'delete any pre-existing file of same name
    Kill vpbase
    DoEvents
   
    'copy our objectdata.grd dummy VP to this new ACTUAL filename and location
    FileCopy GetDDERuntimeRepo() & OBJECT_DATA_VP & VPEXT, vpbase
   
    'create an appropriate VPM ACTUAL filename from our given filename
    vpvpm = FindAndReplace(vpbase, VPBASEEXT, VPMEXT)
    'SQACONSOLEWRITE "DEBUG: vpvpm = "& vpvpm

    'delete any pre-existing file of same name
    Kill vpvpm
    DoEvents
   
    'copy our dummy VPM file to this new filename and location
    FileCopy GetDDERuntimeRepo() & OBJECT_DATA_VP & VPMEXT, vpvpm

    ' out dummy VPM file contains the default Data Test value "Contents"
    ' change that if different data test is specified
    If vpDataTest <> DEFAULT_DATA_TEST Then

        Dim fin As Integer
        fin = FreeFile
        Open GetDDERuntimeRepo() & OBJECT_DATA_VP & VPMEXT For Input As #fin

        Dim fout As Integer
        fout = FreeFile
        Open vpvpm For Output As #fout

        Dim inline As String
        Do While Not EOF(fin)
            Line Input #fin, inline
            If InStr(inline, "Data Test=") > 0 Then
                Print #fout, "Data Test=" & vpDataTest
            Else
                Print #fout, inline
            End If
        Loop
        Close #fin, #fout

    End If
   
    'get a valid VP BENCH filename based on our dummy VP
    vpexp= SQAVpGetBaselineFileName (OBJECT_DATA_VP, VPTYPE)
    'SQACONSOLEWRITE "DEBUG: vpexp = "& vpexp
   
    'extract the directory information out of the filename
    tpath = Mid$(vpexp, 1, LastInStr(vpexp, "\", 1))
    'SQACONSOLEWRITE "DEBUG: tpath = "& tpath

    'delete any pre-existing file of same name
    Kill vpexp
    DoEvents
   
    'copy our dummy VPM file to this new BENCH filename and location
    FileCopy GetDDERuntimeRepo() & OBJECT_DATA_VP & VPEXT, vpexp

    'DEBUG might not need this section at all
    vpvpm2 = tpath & GetShortFileName(vpvpm)
    if StrComp(vpvpm2, tpath, 1) <> 0 then Kill vpvpm2
   
    DoEvents
   
    'perform the ObjectDataVP to capture the data. ListViewVP should work for all or most
    SQASuspendLogOutput
    'Window SetContext, winguiID, "Activate=0"  'CANAGL: winguiID parameter removed
    status = ListViewVP (CompareData, GUIID, "VP="& OBJECT_DATA_VP)
    SQAResumeLogOutput
   
    DoEvents
   
    'delete all our temporary files as quickly as possible
    Kill vpbase
    Kill vpvpm
    Kill vpexp
    if StrComp(tpath, vpvpm2, 1) <> 0 then Kill vpvpm2

    DoEvents
   
    'determine the path to the ACTUAL filename that was captured
    vpact = FindAndReplace(vpexp, VPEXPEXT, VPACTUAL)
    'SQACONSOLEWRITE "DEBUG: vpact = "& vpact

    'if no actual was created? No error? Or bigger problem?
    'we should ALWAYS have an actual because we ALWAYS should fail
    'unless a really big problem like "could not even attempt VP" occurs
    vpact = Dir$(vpact)
    if vpact = "" then EXIT FUNCTION 'with failure
    'SQACONSOLEWRITE "DEBUG: DIR(vpact) = "& vpact
   
    vpact = tpath & vpact

    'now we need to extract the data and fill the array
    actual = FreeFile
    Open vpact for Input as #actual

    'loop through the ACTUAL file to extract the records
    rows = 0
    Do Until EOF(actual)

        Line Input #actual, record
        aNull = Instr(record, Chr(0))
        
        'remove string terminators
        If aNull > 0 Then record = Left(record, aNull -1)

        If Len(record) > 0 Then
            ReDim Preserve aTemp(0 to rows)
            aTemp(rows) = record
            rows = rows +1
        End If
    Loop

    'close the ACTUAL file
    Close #actual
   
    'delete our temporary file
    if StrComp(tpath, vpact, 1) <> 0 then Kill vpact  'what if it isn't a filename? only the directory?  YIKES!

    if rows < 1 then exit function
   
    'determine how wide a 2D array we need
    cols = 0
    For row = 0 to rows -1
        tcols = GetFieldCount(aTemp(row), 1, Chr(9))
        if tcols > cols then cols = tcols
    Next

    Redim values( 1 to rows, 1 to cols)

    'extract the data into the array
    For row = 1 to rows
        record = aTemp(row -1)
        tcols = GetFieldArray(record, 1, Chr(9), aTemp2)
        For col = 1 to tcols
            values(row, col) = aTemp2(col)
        Next
    Next
   
    On error goto 0   
              
    DDGGetGUIObjectData = rows
   
End Function
回复 支持 反对

使用道具 举报

该用户从未签到

5#
发表于 2004-7-6 13:14:41 | 只看该作者
今天刚把环境配好, 经过调试成功(vb.net c#上成功运行)

   
Function treGetSelectNodeIndexTxt(sRecogStr as String) as string
     
     Dim Result as Integer
     Dim vValue as Variant
     Dim sLogMessage as String
    Dim sErrorMessage as String
    Dim Nodetxt as String
   
    Result = SQAGetProperty(sRecogStr, "SelectedNode", vValue)
        
    If Result <> sqaSuccess Then
        sLogMessage = "FUNCTION treGetSelectedNodeIndex - Could not detect current selected node in TreeView: " & sRecogStr
        sErrorMessage = "[" & CStr(Result) & " = " & Error(Result) &"]"
        treGetSelectNodeIndexTxt = "Error"
        Exit Function
    Else
        vValue = Trim(vValue)
        Nodetxt = mid(vValue,11,Len(vValue) - 9 )

        treGetSelectNodeIndexTxt = Nodetxt
    End If   
   
End Function   
   
  可以扩展成库!自己研究吧!
  针对不同语言的处理办法是不一样的!
  在整个过程中需要对比编程环境中该控件的属性还有其他robot可以得到的属性,才能有好的解决方法
回复 支持 反对

使用道具 举报

该用户从未签到

6#
发表于 2004-7-6 13:31:28 | 只看该作者
龙哥,楼主问的不是读取第一个节点的Text的吗?
你的代码是读取选中的节点的吧?

不明白:|


并且我的TreeView没有 SelectedNode 的属性(我的TreeView是VC6.0的)

[ Last edited by oiwenwen on 2004-7-6 at 13:35 ]
回复 支持 反对

使用道具 举报

该用户从未签到

7#
发表于 2004-7-6 14:44:03 | 只看该作者
首先我在vb,delphi,vb.net,c#都试验了。vc我没有试验,是因为他和vb应该是一样的,treeview应该是个activex控件,需要其他的处理方法。

  楼主的问题描述为The first node's text is "Apple".  How to get this node text?
  但是实际中他肯定需要的是任意的nodes的属性text,当你添加一个treeview的时候,控件默认根节点为选择状态。

   用这个属性来得到,你可以很自由,不用处理大量的代码。

  指那打那,而且我给你自己留了一个发挥的余地,难道你没有想到!




  如果你想得到那个用什么函数可以设置属性? 想到了吧?
  实际工作中千差万别,我们要用最短的时间解决问题,而且要高效,自动化开发是个特殊的过程,所以你要考虑的方法比较特殊。
回复 支持 反对

使用道具 举报

该用户从未签到

8#
发表于 2004-7-6 16:02:47 | 只看该作者
VC 里的TreeView不是ActiveX控件吧,它是 MFC 封装好的类(如果用MFC的话),呵呵,我觉得它们之间还是有区别的

你的意思是说要想得到不同节点的Text,可以通过把设置为选中状态来实现?
还是其它的意思?( 恕小弟愚昧,没太明白)
回复 支持 反对

使用道具 举报

该用户从未签到

9#
发表于 2004-7-7 12:23:34 | 只看该作者
不好意思!对于vc的treeview问题,有点相当然而。没有经过试验,昨天我自己试验了一下。确实有区别。  我把他认为是activex了,不过也可以有方法!
     
    我的意思确实是通过选择节点来获得text,这么做一是因为程序中提供给我可利用的属性是这个,其他属性我们很难得到text。我说的特殊的开发方式,就是这个意思,不要孤立的看实现脚本,要被测试程序联系起来看。

  对于vc的,我正研究是否可以得到,不过这个看来大家也未必需要结果!
回复 支持 反对

使用道具 举报

该用户从未签到

10#
 楼主| 发表于 2004-7-7 13:27:42 | 只看该作者

Thanks a million.

I tried using SelectedNode property.  Succeed.  

Thanks.  Suppose I can handle the coming requirements against this issue.  :d
回复 支持 反对

使用道具 举报

该用户从未签到

11#
发表于 2004-7-7 15:39:40 | 只看该作者
不过要通过什么来设置当前选中的节点呢?

ItemText 肯定不行了,因为这是需要得到的,ItemIndex可以吗?
试图通过 ItemIndex 来  recognise VC的 TreeView 的 Item 对象是不成功的,不过或许在别的地方可以 :p

另外,我的那个笨方法也绝对可行哦,
虽然笨了点,但是代码别人都已经写好了;)

[ Last edited by oiwenwen on 2004-7-7 at 15:43 ]
回复 支持 反对

使用道具 举报

该用户从未签到

12#
发表于 2004-7-8 09:10:52 | 只看该作者
你针对的是vc的treeview?
  如果是,它的属性成为关键。而且这里treeview的属性为mfc封装的类库!
  有些得到属性必须要通过ctreectrl的方法。
  那么这个对robot来说就有点困难,所以需要研究对比其中的属性。
  
  对于你提供的代码,哥们,看看是否可以优化!然后给出来,我想大家更愿意看到这样的结果!
  
回复 支持 反对

使用道具 举报

该用户从未签到

13#
发表于 2004-7-8 10:43:32 | 只看该作者
我不是针对VC里的Tree(虽然我身边只有VC的tree)
我只是想知道如何设置 当前 SelectedNode

这是我在VC里录制的选中某个节点的脚本
TreeView Click, "ObjectIndex=1;\;ItemText=农业废物", ""

我的意思是这里通过 ItemText 来识别(recognise)那个“农业废物”的Item,而 ItemText 就是我们想要得到的,当然不可以用
我试图用 ItemIndex 来识别时,是不成功的,也许在其它地方是可以的,或者还有别的方法(我想知道就是这个!呵呵)


另外:那个代码我也只是大概的看了一下(个人认为,如果只是拿过来用,没必要去研究它),只是那个自动化测试框架里的一个函数,我用过,完全可以用

虽然只是大概看了一下,我觉得代码写得很好,我现在还没有能力去优化它:p
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-4-27 10:28 , Processed in 0.079106 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表