Friday 26 December 2014

Document Object Model (DOM) in QTP



Quickest provides direct access to the Internet Explorer's Document Object Model (DOM) through which you can access the HTML tags directly. Access to the DOM is performed using the .Object notation. With DOM, QTP can access the Source of a Webpage.

DOM Samples Examples:

Set IE=CreateObject("internetexplorer.application")
IE.Visible=True
IE.Navigate "http://google.com"
BrowserSync(IE)

Set PageObject=IE.Document

'Set Value in Google Search Edit Box
SetValueinEditBox PageObject,"q","qtp Kumar"
'Click on Google Search Button
ClickButton PageObject,"Google Search"
BrowserSync(IE)
'Click on Result Link
ClickLink PageObject,"http://testingmasters.com/"

MsgBox "Completed"

'********************************************************
'Functions
'********************************************************

Function SetValueinEditBox(PageObject,EditName,Value2Set)

    Dim EditObjects
    Dim Edit

    set EditObjects=PageObject.getElementsByTagName("INPUT")
       
    For each Edit in EditObjects

        If lcase(Edit.name)=lcase(EditName) and lcase(Edit.type)="text" then
            Edit.value=Value2Set
            Exit for
        End If

    Next

    Set EditObjects= Nothing
    Set Edit=Nothing

End Function
'********************************************************
'********************************************************
Function ClickButton(PageObject,ButtonValue)

    Dim ButtonObjects
    Dim button
    Dim ButtonClicked
    set ButtonObjects=PageObject.getElementsByTagName("INPUT")
       
    For each button in ButtonObjects

        If lcase(button.type)="button" Or lcase(button.type)="submit" Then
            If LCase(button.value)=LCase(ButtonValue) Then
                button.click
                ButtonClicked=true
            Exit For
            End if
        End If

    Next

    If Not ButtonClicked=True Then
   
    set ButtonObjects=PageObject.getElementsByTagName("button")
       
    For each button in ButtonObjects

        If lcase(button.type)="button" Or lcase(button.type)="submit" Then
            If LCase(button.value)=LCase(ButtonValue) Then
                button.click
                ButtonClicked=true
            Exit For
            End if
        End If

    Next
   
    End if
    Set ButtonObjects= Nothing
    Set button=Nothing

End Function
'********************************************************
'********************************************************
Function ClickLink(PageObject,LnkURL)

    Dim lnkObjects
    Dim lnk

    set lnkObjects=PageObject.getElementsByTagName("a")
      
    For each lnk in lnkObjects

        If lcase(lnk.href)=lcase(LnkURL) then
            lnk.click
            Exit for
        End If

    Next

    Set lnkObjects= Nothing
    Set lnk=Nothing

End Function
'********************************************************
'********************************************************
Function BrowserSync(BrowserObj)

Dim oTimeout,oTime
oTimeout=10
WScript.Sleep 1000
For oTime=1 to oTimeout
    If BrowserObj.ReadyState=4 Then
        Exit For
    Else
        WScript.Sleep 1000
    End If
Next

End Function

'********************************************************
'********************************************************

'Print All Link Names From a Page

Function fnGetAllLinkNames(oParentObject)

    Dim lnkObjects
    Dim lnk   
   
    set lnkObjects=oParentObject.Object.getElementsByTagName("a")   
' A is the tag name to create  Links in HTML
    print "Total Number of links in the Page :- "&lnkObjects.length
   
    For each lnk in lnkObjects
        print lnk.outerText
    Next

    Set lnkObjects= Nothing
    Set lnk=Nothing

End Function
'Calling the Function with a parent object
Set oParentObject=Browser("Google").Page("Google")
fnGetAllLinkNames(oParentObject)
'*********************************************************
'*********************************************************

'Click on a specified Link

Function fnClickLink(oParentObject,LnkName)

    Dim lnkObjects
    Dim lnk

    set lnkObjects=oParentObject.Object.getElementsByTagName("a")
       
    For each lnk in lnkObjects

        If lcase(lnk.outerText)=lcase(LnkName) then
            lnk.click
            Exit for
        End If

    Next

    Set lnkObjects= Nothing
    Set lnk=Nothing

End Function
'Calling the Function with Parent and with link name Images

Set oParentObject=Browser("Google").Page("Google")
fnClickLink oParentObject,"Images"

ph: 8790002007

What is ETL Testing?

ETL stands for extract, transform, and load. It can consolidate the scattered data for any
organization while working with different departments. It can very well handle the data
coming from different departments.
For example, a health insurance organization might have information on a customer in
several departments and each department might have that customer's information listed in
a different way. The membership department might list the customer by name, whereas
the claims department might list the customer by number. ETL can bundle all this data
and consolidate it into a uniform presentation, such as for storing in a database or data
warehouse.
ETL can transform not only data from different departments but also data from different
sources altogether. For example, any organization is running its business on different
environments like SAP and Oracle Apps for their businesses. If the higher management
wants to take discussion on their business, they want to make the data integrated and used
it for their reporting purposes. ETL can take these two source system data and make it
integrated in to single format and load it into the tables.

Generally the normal testing steps are:
• Requirements Analysis
• Testing Methodologies
• Test Plans and approach
• Test Cases
• Test Execution
• Verification and Validation
• Reviews and Walkthroughs

The main difference in testing a ETL is that we basically involve the
SQL queries in our test case documents. It is vital to test both the initial loads of the Data
Warehouse from the source i.e. when it gets extracted and then updating it on the target
table i.e. the loading step. In specific cases, where trouble shooting is required, we verify
intermediate steps as well.

A defect or bug detection can be appreciated if and only if it is detected early and is fixed
at the right time without leading to a high cost. So to achieve it, it is very important to set
some basic testing rules. They are:
• No Data losses
• Correct transformation rules
• Data validation
• Regression Testing
• Oneshot/ retrospective testing
• Prospective testing
• View testing
• Sampling
• Post implementation

Mobile: 8790002007

Wednesday 24 December 2014

How to generate HTML results using QTP

'To practice, copy below code in qtp and run to generate HTML results.

'You can customize this code as per your need and implement same in your automation frameworks.

start=Timer
'Variables
Dim fso, ts
dim intCnt
Const ForWriting = 2
dim intPass,intFail
dim StartTime
dim stTime
dim enTime
dim objIE
dim strFileURL
'Implementation
OpenFile "H:\Test.html"
AddNewCase 1,"X","X","X","Pass"
AddNewCase 2,"X","X","X","Fail"
AddNewCase 3,"X","X","X","Pass"
CloseFile
' Function To Open the HTML file
Function OpenFile(strFileName)
StartTime = Timer
stTime = Time
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(strFileName, ForWriting, True)
strFileURL = strFileName
CreateHeader
End Function
' Function To Create Header
Function CreateHeader()
ts.writeline("<html>")
ts.writeline("<title>Test Results</title>")
ts.WriteLine("<head></head>")
ts.WriteLine("<body>")
ts.WriteLine("<font face='Tahoma'size='2'>")
ts.WriteLine("<h1>Test Results</h1>")
ts.writeline("<table border='0' width='100%' height='47'>")
ts.writeline("<tr>")
ts.writeline("<td width='13%' bgcolor='#CCCCFF' align='center'><b><font color='#000000' face='Tahoma' size='2'>TestCaseID</font></b></td>")
ts.writeline("<td width='24%' bgcolor='#CCCCFF'><b><font color='#000000' face='Tahoma' size='2'>Objective</font></b></td>")
ts.writeline("<td width='23%' bgcolor='#CCCCFF'><b><font color='#000000' face='Tahoma' size='2'>Expected Result</font></b></td>")
ts.writeline("<td width='22%' bgcolor='#CCCCFF'><b><font color='#000000' face='Tahoma' size='2'>Actual Result</font></b></td>")
ts.writeline("<td width='18%' bgcolor='#CCCCFF' align='center'><b><font color='#000000' face='Tahoma' size='2'>Pass/Fail</font></b></td>")
ts.writeline("</tr>")
End Function
' Function To Add New Case
Function AddNewCase(strTCID,strObjective,strExpectedResult,strActualResult,strPassFail)
ts.writeline("<tr>")
ts.writeline("<td width='13%' bgcolor='#FFFFDC' valign='middle' align='center'>" & strTCID & "</td>")
ts.writeline("<td width='24%' bgcolor='#FFFFDC' valign='top' align='justify'>" & strObjective & "</td>")
ts.writeline("<td width='23%' bgcolor='#FFFFDC' valign='top' align='justify'>" & strExpectedResult & "</td>")
ts.writeline("<td width='22%' bgcolor='#FFFFDC' valign='top' align='justify'>" & strActualResult & "</td>")
if strPassFail = "Pass" then
ts.writeline("<td width='18%' bgcolor='#FFFFDC' valign='middle' align='center'><b><font color='Green' face='Tahoma' size='2'>" & strPassFail & "</font></b></td>")
intPass = intPass + 1
else
ts.writeline("<td width='18%' bgcolor='#FFFFDC' valign='middle' align='center'><b><font color='yellow 'face='Tahoma' 'size='2'  >" & strPassFail & "</font></b></td>")
intFail = intFail + 1
end if
ts.writeline("</tr>")
End Function
' Function To Footer Info
Function Footer()
Dim EndTime
EndTime = Timer
enTime = Time
ts.writeline("</table>")
ts.writeline("<hr>")
ts.writeline("<table border='0' width='50%'>")
ts.writeline("<tr><td width='100%' colspan='2' bgcolor='#000000'><b><font face='Tahoma' size='2' color='#FFFFFF'>Summary</font></b></td></tr>")
ts.writeline("<tr><td width='45%' bgcolor='#E8FFE8'><b><font face='Tahoma' size='2'>Total Tests Passed</font></b></td><td width='55%' bgcolor='#E8FFE8'>" & intPass & "</td></tr>")
ts.writeline("<tr><td width='45%' bgcolor='#FFE6FF'><b><font face='Tahoma' size='2'>Total Tests Failed</font></b></td><td width='55%' bgcolor='#FFE6FF'>" & intFail & "</td></tr>")
ts.writeline("<tr><td width='45%' bgcolor='#FFFFDC'><b><font face='Tahoma' size='2'>Executed On</font></b></td><td width='55%' bgcolor= '#FFFFDC'>" & Date & "</td></tr>")
ts.writeline("<tr><td width='45%' bgcolor='#FFFFDC'><b><font face='Tahoma' size='2'>Start Time</font></b></td><td width='55%' bgcolor= '#FFFFDC'>" & stTime & "</td></tr>")
ts.writeline("<tr><td width='45%' bgcolor='#FFFFDC'><b><font face='Tahoma' size='2'>End Time</font></b></td><td width='55%' bgcolor= '#FFFFDC'>" & enTime & "</td></tr>")
ts.writeline("<tr><td width='45%' bgcolor='#FFFFDC'><b><font face='Tahoma' size='2'>Execution Time</font></b></td><td width='55%' bgcolor= '#FFFFDC'>" & CDbl(EndTime - StartTime) & "</td></tr>")
ts.writeline("</table>")
ts.writeline("</font>")
ts.WriteLine("</body>")
ts.WriteLine("</html>")
End Function
' Function To Close File
Function CloseFile()
Footer
ts.close()
Set objIE = CreateObject("InternetExplorer.Application")
objIE.visible = True
objIE.Navigate strFileURL
End Function

VBScript Advanced Questions


1 Write a program to read data from a text file
2 Write a program to write data into a text file
3 Write a program to print all lines that contains a word either “testing” or “qtp”
4 Write a program to print the current foldername
5 Write a program to print files in a given folder
6 Write a program to print subfolders in a given folder
7 Write a program to print all drives in the file system
8 Write a program to print current drive name
9 Print the last modified and creation date of a given file
10 Print the size of the file and size on the disk.
11 Write a program to display files of a specific type
12 Write a program to print the free space in a given drive
13 Write a program to display all subfolders in a given folder
14 Write a program to find whether a given folder is a special folder
15 Write a program to remove all empty files in the folder
16 Write a program to Copy contents of one folder to other folder
17 Write a program to check whether a given path represents a file or a folder
18 Write a program to compress a folder
19 Write a program to rename a folder
20 Write program to display all folders created on a specific date
21 Write a Program to enable disk quotas
22 Write a program to create, modify and delete disk quota
23 Write a program to display all files containing “demo” in their name
24 Write a program to print all lines in a file that ends with “world”
25 Write a program to check whether string starts with “Error”
26 Write a program to Replace all words that contains “demo” in a file with the word “QTP”
27 Write a program to check whether a string contains only alpha numerics
28 Write a program to check whether a string is in email format
29 Write a program to check whether given string is in date format
30 Write a program to print all the lines ending with '$'
31 Check whether middle three characters in a word contains alphanumeric
32 Check whether a given line is an empty
33 Write a program to Add elements to a dictionary
34 Write a program to display items in a dictionary
35 Write a program to check whether specified Key exists in a Dictionary
36 Write a program to Store dictionary items in an array
37 Write a program to delete Key Value pair in the dictionary
38 Write a program to monitor operating system performance
39 Write a program to monitor operating system objects
40 Write a program to monitor web server performance
41 Write a program to monitor browser service performance
42 Write a program to list the PID and PPID of a process
43 Write a program to create a registry key
44 Write a program to list registry files
45 Write a program to list registry value and types
46 Write a program to delete registry key
47 Write a program to Stop and Start alerter service
48 Write a program to list services running and their statuses.
49 Write a program to list services that can be stopped
50 Write a program to start auto start services that have stopped
51 Write a program to Invoke command prompt and execute dir command from the shell
52 Write a program to schedule a task
53 Write a program to list and delete scheduled tasks
54 Write a program to add a local user account
55 Write a program to disable and delete a local user account
56 Write a program to list all user accounts in the local computer
57 Write a program to display logged in user name
58 Write a program to list cache memory information
59 Write a program to list physical memory properties
60 Write a program to list memory devices
61 Write a program to find Hard Disk size
62 Write a program to find RAM size
63 Write a program to restart a computer
64 Write a program to shutdown a computer
65 Write a program to Execute Perl script from VB Script
66 Find the systems present in the LAN
67 Write a program to Print using remote printer
68 Verify whether IE enhanced security is enabled for logged on user
69 Write a program to add a website to a favourite menu
70 Write a program to list IE LAN settings
71 Write a program to list cache, connection and security zone settings
72 Find the arguments passed to a Windows Script Host
73 Write a program to Map a network drive
74 Write a program to Print to the local printer
75 Write a program to Print to remote printer
76 Write a program to Print Computer name
77 Write a program to Print free memory in the drive
78 Write a program to Print memory and CPU utilized by a process
79 Write a program to Find the ipaddress of a local system
80 Write a program to find Network Drives
81 Write a program to find the Full path name of a shortcut
82 Write a program to Retrieve all the rows in a table
83 Write a program to find the name of columns in a table
84 Write a program to find number of rows in each column
85 Write a program to connect and print data from oracle database
86 Write a program to connect and print data from SQL Server database
87 Write a program to retrieve specific field from the database table
88 Write a program to check whether a column in the database is in ascending order
89 Write a program to insert a new row into the database table
90 Write a program to open the two record sets
91 Write a program to Update the specific field in the database table
92 Write a program to delete all records whose username starts with demo
93 Write a program to sort the record set
94 Write a program to find number of rows in a table
95 Write a program to Write simple text to windows word
96 Write a program to Write table to windows word
97 Write a program to apply style to a table in word document
98 Write a program to open and print a word document
99 Write a program to send an email using outlook
100 Write a program to print data present in all sheets of an excel files

Automation Activities

Automation Activities
Activity Description
KT(Knowledge Transfer) / Requirement Analysis
To understand the application and to analyze the manual test cases  that have to be converted for automation
Test Automation Plan
To identify/create manual test cases that has to be converted for automation
Test case preparation
To identify/create manual test cases that has to be converted for automation
Data Flow
Prepare flow of test cases specific to automation
Framework Implementation
Define a framework for a module
GUI/Object learning
Learn all the GUI objects of application and store them in a dictionary.
Business Functions
Develop the business functions that can be reused across the application
Test data
Test data are stored in an excel sheet for multiple round of execution
Test Scripting
Development of module specific scripts
Script review/updating
Review effort from onsite and offshore
Error/Exception handling
Develop exception and error handling
Script Testing by Execution
Execute the script with sample sets of data for multiple times
Rework
Rework on the script creation based on the review comments/new modifications
Documents
Preparation of release and readme documents

Automation Checklist

Checklist for Automation Approach       

SNo
Items
Y/N
Comments
1.
Have the test cases been identified for automation?


2.
Is the dataflow prepared for effective reusability of test scripts? (The main objective of this approach is to increase reusability of codes, reduce redundancy in codes, and easy for maintenance)


3.
Is Requirements Traceability Matrix prepared for mapping a test case to a script?


4.
Are the necessary test data for automation available?


5.
Are all the common functions identified?


6.
Is the design document available for scripting?


7.
Are the folder names defined for the automation scripts?




Checklist for Automation Methodology 

SNo
Items
Y/N
Comments
1.
Is the identical start and end state defined for the test script?


    2.
Is the precondition documented for the test script?


    3.
Tables are defined with proper naming conventions in the database


    4.
Is the Global GUI File defined?


    5.
Are all the checkpoints results captured and validated?


    6.
All scripts should have appropriate verification points.


    7.
Verification points for key intermediary functional results or states in the flow will be inserted in-between steps and at the end of a script to verify the expected results.


    8.
The verification points should also check for every error condition possible from the UI.


    9.
On test execution of each test script, the test log will be used to verify the results for verification point passes and for the items that have not passed.


   10.
Document the steps that are not automated with reasons.


   11.
Check if the exception handling and recovery scenarios are done for all the expected and unexpected failures during the execution of scripts.





Checklist for Scripting Standards  

SNo
Items
Y/N
Comments
1.
GUI object names used in the GUI map and the object names used in business  functions follow the exact naming conventions


2.
Reference documents such as conventions and standards are available for review?


3.
Is the functionality of the script covered?


4.
Does it contain appropriate headers


5.
Is adequate Inline documentation available?


6.
Are meaningful naming conventions followed?


7.
Has code been adequately indented?


8.
Are common set of routines written instead of replicating code for these routines in various modules?


9.
Are adequate procedures written for the test script to proceed to next step/iteration during failure without the test script execution stopping?


10.
Are the error messages adequate?


11.
Is a meaningful message written to the test report if a step fails?


12.
Will the requirement of execution time be met?


13.
Verify if the name of the script is as per the “Naming Convention” given in the Scripting Standard document?


14.
Verify if the header of the script is as per the Scripting Standard document?


15.
Check for the proper version for the test script. Before initial review the test script version should be ‘Draft’ and should be incremented subsequently.


16.
Are local variables used within the functions wherever applicable?


17.
Is the Naming of variables/constants/functions according to the Naming convention document for script?


18.
Check if proper comments are added at the beginning and end of loops where multiple loops are present.


19.
Check if unused variables are not present in the script.


20.
Check if the script contains any unnecessary ‘pause’,’printf’ statement.


21.
Check if the script doesn’t contain any syntax errors.


22.
Check if the modification history is maintained properly.


23.
Check if the functions called inside the main script for entering data covers the entire screen flow for the corresponding product


24.
Check if tl_step event function is used only to report a problem/bug/pass case into the test result report.


25.
Check if script readability, maintainability and consistency are there.


26.
Is the Database connection session closed in the script?


27.
Are the previous GUI Files unloaded?