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

Creating First Test in Selenium IDE using FireFox

Starting working with Selenium IDE:

1. Before Working with Selenium IDE, we will need to have mozilla firefox installed in the machine.
2. Also plugins and add-ons for using Selenium needs to be installed from selenium official webSite.
3. Once the add-ons are properly installed, To Open Selenium IDE, go to Web Developer>Selenium IDE or Press "Ctrl+Alt+S"


Understanding Selenium IDE

Below Figure explains various components of Selenium IDE



File Menu - File Menu provides the options to create a new test case, test suite, and the test suite can be exported to Ruby/Java/c# Web Driver or Remote Control.
Recording - Recording starts automatically on launching the IDE.
Test Run - Icon to run  all tests or individual tests is available on Selenium IDE
Test Execution Speed - Test execution script can be set as fast or slow as shown  in figure 1.


Creating First Test in Selenium IDE

Recording starts automatically once we launch Selenium IDE, and perform some action on the Firefox browser.Once some action is performed, the action is displayed is command , e.g : Click , Open, etc. Target displays the property of object on which command is to executed and value is value to be set in input.

Assertions and Verification can not be done during recording and needs to be added manually.Difference between assert and verify Commands is test execution stops once assert statement fails but test execution continues to next step if we execute the Verify command, although the test status fails in both cases.

Tips for adding command: 
User is provided with all the possible commands on a object when Selenium IDE is open. 

Steps:
1. Right Click on an object in Firefox browser.
2. Click on Show All Available Commands>Select the required Command.
3. Command will be added in the test.


Adding command to selenium test

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();