标题: How to get a tree node's property using Robot? [打印本页] 作者: yy903 时间: 2004-7-5 17:11 标题: How to get a tree node's property using Robot? 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
[ Last edited by oiwenwen on 2004-7-6 at 11:04 ]作者: oiwenwen 时间: 2004-7-6 10:57 标题: 对于如何读取一个对象的Data,RRAFS里有一个函数 Function DDGGetGUIObjectData (guiID As String, values() As Variant, Optional dataTest As Variant) As Integer
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作者: pcl2004_27 时间: 2004-7-6 13:14
今天刚把环境配好, 经过调试成功(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 )
[ Last edited by oiwenwen on 2004-7-6 at 13:35 ]作者: pcl2004_27 时间: 2004-7-6 14:44
首先我在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的时候,控件默认根节点为选择状态。
[ Last edited by oiwenwen on 2004-7-7 at 15:43 ]作者: pcl2004_27 时间: 2004-7-8 09:10
你针对的是vc的treeview?
如果是,它的属性成为关键。而且这里treeview的属性为mfc封装的类库!
有些得到属性必须要通过ctreectrl的方法。
那么这个对robot来说就有点困难,所以需要研究对比其中的属性。