여러 개의 하위 객체를 동시에 조작하기 위해 QTP 자체 방법을 재정의하는 방법
The usual way to do it in Descriptive Programming (DP) is to create a Description object and then use ChildObjects method to get all objects matching this description. The code shown below demonstrate the same
'Create a description for web checkbox
Dim oWebChkDesc
Set oWebChkDesc = Description.Create
oWebChkDesc("micclass").value = "WebCheckBox"
oWebChkDesc("html tag").Value = "INPUT"
'Get all objects matching this description
Dim allCheck, oCheckBox
Set allCheck = Browser("KnowledgeInbox").Page("KnowledgeInbox").ChildObjects(oWebChkDesc)
Dim i
For i = 0 to allCheck.Count - 1
Set oCheckBox = allCheck(i)
oCheckBox.Set "ON"
Next
The problem with above approach is the re-usability factor. The code we wrote is not elegant when such operations need to done in number of scripts or multiple no. of times in a script. It is nice to have something within the framework which allows re-usable way of performing such operation. The code shown below can achieve the same
'Description: The function calls a method on a object by it's name
'Parameters:
'@Obj - The object on which the methods needs to be called
'@MethodName - The name of the method to be called
'@Params - Parameter to be passed to the Method. In case of mulitiple
' parameters use Array
Function CallAllByName(Obj, MethodName, Params)
'If the Params is not an Array we make it an Array
'This makes it flexible to pass a single parameter without
'creating an array for the same
If VarType(Params) < vbArray Then Params = Array(Params)
Dim objDesc
'Try to Extract the description from the object
Set objDesc = Obj.GetTOProperties()
'Generate the call statement parameters
Dim i
Dim paramCallText
paramCallText = " "
For i = 0 to UBound(Params)
paramCallText = paramCallText & "Params(" & i & "),"
Next
'Removed the trailing ","
If Right(paramCallText,1) = "," Then paramCallText = Left(paramCallText, Len(paramCallText)-1)
If objDesc.Count = 0 Then
'The object is an derived object returned from ChildObjects
'We Can't do anything special with this. Just try to execute the method
'on the Object passed to this function
Execute "Obj." & MethodName & paramCallText
Else
Dim oParent
'Get the Test Object's parent
Set oParent = Obj.GetTOProperty("parent")
'Get all childs matching current object description
Dim allChilds
Set allChilds = oParent.ChildObjects(objDesc)
If allChilds.Count = 0 Then
'No matching objects were found. So let us just try to Set the value
Execute "Obj." & MethodName & paramCallText
Else
'We now have multiple objects matching this description
'Peform set operation for all childs
For i = 0 to allChilds.Count - 1
Execute "allChilds(i)." & MethodName & paramCallText
Next
End If
End If
End Function
The function CallAllByName shown extract the description from the object passed to it. GetTOProperties method returns a description from the current object. There is once exception where this method doesn’t work, when the objects have been retrieved from the ChildObjects. The function can be used in the following manner
Function SetAll(Obj, Text)
CallMultiObjectMethod Obj, "Set", Text
End Function
RegisterUserFunc "WebCheckBox", "SetAll", "SetAll"
RegisterUserFunc "WebEdit", "SetAll", "SetAll"
Note: In case the method being called takes multiple parameter we need to pass them using Array
Function SetAll(Obj, Text1, Text2)
CallMultiObjectMethod Obj, "Set", Array(Text1, Text2)
End Function
We can use the SetAll method as shown in above code in two ways
Method 1
Browser("KnowledgeInbox").Page("KnowledgeInbox").WebCheckBox("CheckBoxes").SetAll "ON"
In this method we change the properties of the “CheckBoxes” object in the Object Repository to match all the objects we want to operate
Method 2
In this method we again create a description object and then used it inside the TestObject to call the SetAll method
'Create a description for web checkbox
Dim oWebChkDesc
Set oWebChkDesc = Description.Create
oWebChkDesc("micclass").value = "WebCheckBox"
oWebChkDesc("html tag").Value = "INPUT"
Browser("KnowledgeInbox").Page("KnowledgeInbox").WebCheckBox(oWebChkDesc).SetAll "ON"
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
localStorage에 객체를 추가하는 방법은 무엇입니까?이 노트에서는 localStorage에 객체를 삽입하는 방법을 보여드리겠습니다. 경우에 따라 로컬 스토리지 또는 세션 스토리지에 데이터를 개체로 저장해야 할 수 있습니다. 어떻게 이것을 달성할 수 있습니까? 객체가 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.