51Testing软件测试论坛

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

QQ登录

只需一步,快速开始

微信登录,快人一步

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

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

[复制链接]

该用户从未签到

1#
发表于 2004-7-6 10:51:37 | 显示全部楼层
SqaGetPropertyArray("Type=TreeView;ObjectIndex=1", "Nodes",Values)

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

使用道具 举报

该用户从未签到

2#
发表于 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 ]
回复 支持 反对

使用道具 举报

该用户从未签到

3#
发表于 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
回复 支持 反对

使用道具 举报

该用户从未签到

4#
发表于 2004-7-6 13:31:28 | 显示全部楼层
龙哥,楼主问的不是读取第一个节点的Text的吗?
你的代码是读取选中的节点的吧?

不明白:|


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

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

使用道具 举报

该用户从未签到

5#
发表于 2004-7-6 16:02:47 | 显示全部楼层
VC 里的TreeView不是ActiveX控件吧,它是 MFC 封装好的类(如果用MFC的话),呵呵,我觉得它们之间还是有区别的

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

使用道具 举报

该用户从未签到

6#
发表于 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 ]
回复 支持 反对

使用道具 举报

该用户从未签到

7#
发表于 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-5-8 13:22 , Processed in 0.073940 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

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