Thursday, August 29, 2013

VB Script - Close All Browser

Function Details:
This Vb Script Function is for "Close browsers except QC window" using VB Script.This function will close all the Internet Explorer window and tabs except HP Quality Center. To use this function simply copy paste it in to text file and save the file with .vbs Extension. When you double click on the .vbs file, the script will be executed and you can found the result.

Function CloseIE
    On Error Resume Next

    'Variable Declaration
    dim objShell, objWindow, strTitle

    'Set Variables and Object Values
    set objShell = CreateObject("Shell.Application") 'Create Shell Application Object
    strTitle = "HP Quality Center" 'Set Window Title Search Name
   
    for each objWindow in objShell.Windows 'Get Window Objects
        if InStr(objWindow.FullName,"iexplore")<>0 then 'Check Object Window Full Name with iexplore   
            if(objWindow.document.title<>"") then 'Check Object Window Title not Blank   
                if InStr(objWindow.document.title,strTitle)=0 then 'Check Object Window is not Quality  Center
                    objWindow.Quit 'Close IE
                end if   
            end if   
        end if
    next

    if objShell.Windows.Count>0 then 'Check Object Window Count
        For i=0 to objShell.Windows.Count
            Call CloseIE 'Recursively call Function
        next
    end if

End Function

Note :- To Use this Function write the below statement in top of the .vbs file.
Call CloseIE statement

Add Remove Object Repository Dynamically in QTP

HP QTP provides a great functionality for adding or removing Object Repository at run time or dynamically. For that ObjectRepositories Utility object of QTP is used. 

Find the below code for Add/Remove Object Repository dynamically in QTP during run time.

'*********************************************************
'Function Name: AddRemoveOR
'Purpose: Use for Add Or Remove Object Repository with Action Name
'Inputs:
    'repositoryPath=Repository Path for Add or Remove with Action
    'actionName=Action Name for Add for Add Or Remove Repository
    ' operationName=Operation Name to be Perform either "Add" or "Remove" Object  Repository
'Return Values: -
'Created By: Krutin Gandhi
'*********************************************************

Function AddRemoveOR(repositoryPath,actionName,operationName)  

    Dim qtApp,qtRepositories, actName, RepPath,  rPosition'Variable Declaration

    RepPath=repositoryPath 'TRS File Path
    actName=actionName   'Get Action Name
    Set qtApp = CreateObject("QuickTest.Application")    ' Create Application Object
    Set qtRepositories = qtApp.Test.Actions(actName).ObjectRepositories    ' Get Associated repositories list

        'Adding Repository to an action
        If operationName="Add" Then       
            If qtRepositories.Find(RepPath) = -1 Then
                qtRepositories.Add RepPath, 1    ' Add the Object Repository to the current action 
            End If

        'Remove Repository to an action
        Else if operationName="Remove" Then
            rPosition=qtRepositories.Find(RepPath) 'Find the Position of the Repository
            If  rPosition<>-1 then
                qtRepositories.Remove rPosition  ' Remove Repository From the Action
            End if           
        End If
    End If

    'Assign nothing
    Set qtApp= Nothing
    Set qtRepositories= Nothing
End Function