Tuesday, June 10, 2014

Automation of Silverlight application using QTP - typical object identification issue

I am trying to consolidate the typical issues I have faced during Microsoft Silverlight v5.1 using QTP 11. I have tried to write generic functions so that it can be used as part of automation framework.

1. Scenario: Dropdown list having checkboxex in it is defined in usign SLVTable object where rows of the table contains the checkboxes and the name of the checkbox in the row. This object is not directly being identified by the tool. To handle this issue I wrote the following function and register it with SlvTable object to select specific check box:

'desc: it is the parameter which contains name of the checkbox. In my application name is given in second column. Index can be updated based on the application.

Sub ClickSLVTableDropDown(obj, desc)
rows=obj.RowCount
index=0
For cnt=0 to rows-1
var=obj.GetCellData(cnt,1)
If strcomp(var,desc,1)=0 Then
index=cnt
Exit for
End If
Next

set obj=obj.GetCellChildObjects(index,0)
obj(0).click
End Sub

RegisterUserFunc "SlvTable", "ClickSLVTableDropDown", "ClickSLVTableDropDown"




2. Scenario: SlvTable is used to have values in the dropdown but does not have checkboxes. Apart from only the values in the dropdown visible on the screen are counted as number of rows in the SlvTable not all the values it contains. So if you want to loop in the table, the option is not a feasible option.

Organization of the object: Dropdown object is defined as combination of textbox and a button. Clicking on either of these two objects individually the dropdown will come up from which values needs to be selected. Directly entering the value in the text box does not help as the object is organized in such a ways that the value needs to be selected from the table values.

Solution: Click on the SlvTextbox object which would open the drop down. Then use the below code for clicking on the specific value from the dropdown:

Sub SelectValueFromDowpdown(obj, desc)
obj.Click
wait 2
set wsh=createobject("WScript.Shell")
wsh.SendKeys desc
wait 1
wsh.SendKeys "{ENTER}"
End Sub

RegisterUserFunc "SlvEdit", "SelectValueFromDowpdown", "SelectValueFromDowpdown"




3. Scenario:On the page in for navigation to different options for a the navigation options are organized in the way that SlvObject element is embedded in SlvTable object. The scenario may be in such a way that based on certain previous selection the order of appearance of SlvObject may change.

Solution: Get the rows from the SlvTable and find out the order of SlvObject appearance in the table and click the object accordingly.

Sub SelectValue(obj, val)
rows= obj.GetItemsCount
For counter=0 to rows-1
set child=obj.GetItemChildObjects(counter)
child_name=child(0).getRoproperty("text")
If strcomp(child_name,val,1)=0 Then
obj.Select counter
Exit for
End If
Next
End Sub

RegisterUserFunc "SlvList", "SelectValue", "SelectValue"




4. Scenario: Item needs to be selected from SlvComboBox but items are not added to Item property and hence 'Select' method does not work.

Solution: In this scenario loop thru all the elements in the combo box and find out the index of the item you want to select. Then based on this index select the item from the combo box. 

Sub SelectComboOption(obj, combo_option)
total_items=obj.GetItemsCount
For counter=0 to total_items-1
set child= obj.GetItemChildObjects(counter)
item_name=child(0).getRoproperty("text")
If strcomp(item_name,combo_option,1)=0 Then
obj.Select counter
Exit for
End If
Next
End Sub

RegisterUserFunc "SlvComboBox", "SelectComboOption", "SelectComboOption"



5. Scenario: In SLVComboBox select method is able to select the items from the combo box but accordingly changes are not getting reflected. However, while performing similar action manually or using the sendkeys function, the functionality was working. While doing the root cause analysis I found out that in the items collection the items were not added by their name and only class of the item was added in the array.

Solution:  While using object spy I noticed that the dropdown options were being displayed as text block and as child object of the SlvComboBox. Below code shows how the problem is being solved using descriptive programming. A description object is created which represents the item to be selected from the combo box and using childobjects method of the combobox the reference to that object is used to click and select the required item in the combo box.

Browser("").Page("").SlvWindow("").SlvComboBox("").Click
Set  childObj=Description.Create
childObj("classname").value="System.Windows.Controls.TextBlock"
childObj("parent text").value="Filter Name"
set cObj=Browser("").Page("").SlvWindow("").SlvComboBox("").ChildObjects(childObj)
cObj(0).click



Please share if you have alternate ways to resolve these object identification problems. Thanks.

3 comments:

  1. HI ,

    Am fcaing the same as Scenario 5 .
    Can you please provide the complete code for that?

    Regards,
    Shiv

    ReplyDelete
  2. Hi Shiv,

    The code mentioned above is all I have used to resolve this issue - nothing more than this. You just need to add the combobox object to your OR and then identify the kind of object object spy is showing which are used to create combobox item. In my application, they were text blocks, in your application they may be different.

    Hope it helps to resolve the issue.

    Shailendra

    ReplyDelete
  3. Hi,

    Is there any sample silverlight application which can be used for practicing at home?

    Thanks,
    Sumaiya

    ReplyDelete