Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

How to compare 2 dictionary object and report the differences in QTP results

This post discusses how to compare two dictionary objects and display the difference between the values in two dictionary objects in table format in QTP results using Reporter.logevent.


''function to compare two Dictionaries 

Public Function Comfunct_CompareDictionary(ObjDictBase, ObjDictGen)

Comfunct_CompareDictionary = True 
''Check if both dictionary objects have the same number of items
If ObjDictBase.Count <> ObjDictGen.Count Then
Reporter.reportevent micFail,"Data in Dictionary 1 and 2","Data mismatch in the dictionary. there are " & objDictBase.Count & "records in dictionary 1 compared to " & objDictGen.Count & "records in dictionary 2" 
Comfunct_CompareDictionary = False
Exit Function
End If
''Compare keys and values
arrKeys = ObjDictBase.Keys
''Create a table for the differences
strTable = "<table border=""""2""""><tr><td>Key Name</td><td><Value in Dictionary 1</td><td><Value in Dictionary 2</td></tr>"
For i = 0 to uBound(arrKeys)
''Compare key names in both dictionaries and validate keys in one dictionary exists in other dictionary
  If Not ObjDictGen.Exists(arrKeys(i)) Then
''ObjDictBase has a key which ObjDictGen doesn't have, hence exiting the function
Comfunct_CompareDictionary = False
Reporter.ReportEvent micFail, "Key " & arrKeys(i) & " exists in dictionary 1 but not in dictionary 2, " Key difference in both dictionaries"
Exit Function 
  End If
  ''Compare value of each keys in both dictionary and display the difference between 2 dictionary in Qtp results 
  If ObjDictBase(arrKeys(i)) <> ObjDictGen(arrKeys(i)) Then
''ObjDictBase value for arrKeys(i) differs from ObjDictGen, then log the difference in the table created above
Comfunct_CompareDictionary = False
strTable = strTable & "<tr><td>" & arrkeys(i) & "</td><td>" & ObjDictBase(arrKeys(i)) & "</td><td>" & ObjDictGen(arrKeys(i)) & "/td></tr>" 
  End If
Next
If Comfunct_CompareDictionary = True Then
Reporter.ReportEvent micPass, "Comparision of dictionary 1 and dictionary 2","Both dictionary matches"
Else
strTable = strTable & "</Table>"
''Compare value of each keys in both dictionary and display the difference between 2 dictionary in Qtp results 
Call reportinQTPhtmlContent(strTable)
End If 
End Function


''Function to report in QTP result in table format

Public Function reportinQTPhtmlContent(strTable)
Set objdict = CreateObject("Scripting.dictionary")
objdict.Add "Status", micdone
objdict.Add "NodeName", "Table Data"
objdict.Add ("StepHtmlInfo"), strTable
Reporter.LogEvent "User", objdict, Reporter.GetContext
End function


How to Configure Eclipse to work with Selenium

Before starting working with Selenium using Eclipse IDE, we did some configuration that needs to be done for starting and understanding Selenium. This post will explain step wise, how to start working with selenium using Eclipse:


Pre- Conditions: We will require following before beginning the configuration:

1. Java needs to be installed in the machine.

2. Eclipse IDE needs to be installed .

3. Standalone libraries of selenium, at the time of writing this post, I am using selenium-server-standalone-2.33.0.jar

4. Verify in Path variable in User defined variable for machine, is set to the path where standalone libraries is placed as shown below




Configuration Steps: 




Step 1: In eclipse, create a new java project as shown below from File>New Java Project


Create a new Java Project

Step 2: Once a java project is created, right click on project and select option "Build Path>Configure build path

Configure build path of project

Step 3: Click on Add External JAR's and add the selenium standalone jar as shown below.

 Step 4: Now in src for the project, Add a new package, and add a new class as shown below.


Select methods stubs to create as public static void main(String[] args)


                                         

Step 5: Write the code in the class created above and execute. This will open Google in internet explorer . Write selenium in search and click on search.


Code to be placed in void main:


WebDriver ieDriver = new InternetExplorerDriver(); ieDriver.get("http://www.google.com"); WebElement element = ieDriver.findElement(By.name("q")); element.sendKeys("selenium"); element.submit();


Manipulating Array with examples using vbscript in QTP

In this post we discusses examples working with arrays and manipulating them in vbscript:

1.How to count number of elements in an array


intcount = ubound(arrayname)

2. How to join all the values in an array to a string and display the value in messagebox


dl=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
daysinWeek = join(dl, " ")
msgbox "days in weeks " & daysinWeek


3. How to split values in a string in an array based on delimiter


dl="Sunday>Monday>Tuesday>Wednesday>Thursday>Friday>Saturday"
daysinWeek = split(dl, ">")

This method can be used on looping as shown in example below:

On error resume next

Set objDesc= Description.create

'Set of Property values are delimited by "," 

If (instr(1,strDescObj,",") >0) Then

''Split multiple links based on delimiter.

arrDesc = split(strDescObj,",")

intPropSet = Ubound(arrDesc)

''Loop through each of the link and click the required link

for i = 0 to intPropSet

strDesc = split(arrDesc(i),"|")

objDesc(strDesc(0)).value = strDesc(1)

Next

End If