Wednesday, December 28, 2011

Open QTP Scripts from quality Centre using .VBS


Problem:
I have 50 test scripts stored in Quality Center (in different sub folder’s), It’s a time consuming process to open individual scripts from different folder and executing them back. Is there any way to open QTP script from different location?
OR
How to open QTP script from QC using .vbs file?
OR
How to execute scripts from QC?

Solution: VBS file can be used to open QTP scripts from quality center and executing them back. Refer the below code to open QTP, connect to QC and execute the selected scripts.

--------------------------------------------------------------------------------------------------------
   
        Dim QTP_App                 ' Declare the Application object variable
        Dim QTP_Test                 ' Declare a Test object variable
        Dim QTP_Results             ' Declare a Run Results Options object variable
        Dim QC_Path                   ' Declare QC Path and assigned actual path
       
        ' Create the Application object

        Set QTP_App = CreateObject("QuickTest.Application")           
       ' Start QuickTest
        QTP_App.Launch                                                                                        
       ' Make the QuickTest application visible
        QTP_App.Visible = True                                                                            
       
        'Connect to Quality Center
        QTP_App.TDConnection.Connect QC_Path, False
       
        'Run a test
         Call OpenScriptRunTest (ScriptName,TestSetName)

   
        'Function to open QTPScript and run that script
        Function OpenScriptRunTest (ScriptName,TestSetName)
        QTP_App.Open QC_Path&ScriptName,True
        QTP_App.Options.Run.ImageCaptureForTestResults = "OnError"
        QTP_App.Options.Run.RunMode = "Fast"
        QTP_App.Options.Run.ViewResults =True
         Set QTP_Test = QTP_App.Test
        QTP_Test.Settings.Run.IterationMode = "allIterations"
        QTP_Test.Run.StartIteration = 1
        QTP_Test.Run.EndIteration = 1
        QTP_Test.Run.OnError = "NextStep"
        Set QTP_Results = CreateObject("QuickTest.RunResultsOptions")
        QTP_Results.TDRunName="Run_Sample"
        QTP_Results.TDTestInstance=1
        QTP_Results.TDTestSet=QC_Path&TestSetName
        QTP_App.Test.Run qtRunResultsOptions
        QTP_App.Close    
        End Function
       
       

Friday, November 25, 2011

Functions in QTP........

 'FAQ, Functions


 'Functions (strcomp, mid, split, instr, replace,filter etc)
 temp="Welcome BAck"
 temp1="Welcome Back"
 temp2="Welcome, Mr. James, Way, JamBach"
 temp3="come"

 'SPLIT()
 text=split(temp2,",")
 limit=ubound(text)
 For i=0 to limit
 msgbox text(i)
 Next

 'FILTER
 text1=filter(text,"Jam")
 limit=ubound(text1)
 For i=0 to limit
 msgbox text1(i)
 Next

 'REPLACE()
 text=replace(temp,"JP","a")
 msgbox text

 'INSTR()
 text=Instr(1,temp1,temp3)
 msgbox text

 'MID()
 text=mid(temp1,4,3)
 msgbox text


 'STRCOMP()  Binary & Text Comprison
 If strcomp(temp,temp1,0)=0 Then
  msgbox "Pass"
  else
  msgbox "Failed"
 End If

Sunday, May 22, 2011

QTP 10 Menu Item Missing

Try the below steps, You will get your menu item's back.


Step1: Launch QTP.
Step2: Right click on the top of toolbar
Step3: Select Customize ---> Select Toolsbar Tab ---> Click on Restore All

Monday, May 16, 2011

How to use key strokes in QTP?


'Problem: Sometimes it happened that QTP is not recognizing the objects. Can i use keyboard strokes to click any of the link and Navigate the different parts of open application.

'Solution: 
'Use of KeyStroke on Active Browser/Window
Set Obj=CreateObject("WScript.Shell")
wait 2
Obj.Run "http://www.google.com"
wait 2
     Obj.SendKeys "{Enter}"
  wait 2
  Obj.SendKeys "{Tab}"
  wait 2
     Obj.SendKeys "{Enter}"
  wait 2
  Obj.SendKeys "{Tab}"
  wait 2
  Obj.SendKeys "{Tab}"
  wait 2
  Obj.SendKeys "{Tab}"
  wait 2
  Obj.SendKeys "{Tab}"
  wait 2
  Obj.SendKeys "{Tab}"
  wait 2
  Obj.SendKeys "{Tab}"
  wait 2
  Obj.SendKeys "{Tab}"
  wait 2
  Obj.SendKeys "{Enter}"
         
'The above code will
1.  Launch "Google.com"
2.  Click on link "Advanced Search"
3.  Click on link "Google Instant" within Advanced Search Page

How to Close Multiple Browser? QTP

Problem: I have 10 open Browsers, How can i close them 1 by 1.

Solution:

'Close All the Open Browser
While Browser("title:=.*","index:=0").Exist
Browser("title:=.*","index:=0").close
Wend

Friday, February 25, 2011

Perform search in Excel file

'Excel1 : D:\temp.xls            Sheet1 with two columns "Mobile" &"result"
'Excel2 : D:\temp1.xls           Sheet1 with column "Mobile"
'Search "Mobile #" present in Excel1 into Excel2
'if information is available in Excel 2 , Put the text "P" in result column of Excel1
'if information is not available in Excel 2 , Put the text "NP" in result column of Excel1
'Save temp.xls as temp2.xls
---------------------------------------------------------------------------------------

DataTable.Import "D:\temp.xls"
globalrow=DataTable.GetRowCount

Set obj=Createobject("Excel.Application")
Set objwb=obj.WorkBooks.Open("D:\temp1.xls")
Set objsheet=objwb.Sheets("Sheet1")
obj.visible="True"
flag=0

For i=1 to globalrow
   Datatable.SetCurrentRow(i)
   dev=int(DataTable("East",global))
   set foundrow=objsheet.Cells.Find(dev)
   On Error resume next
   flag=foundrow.Row

   If flag<>0Then
    DataTable.Value("result",global)="P"
    else
    DataTable.Value("result",global)="NP"
  End If
flag=0
Next

DataTable.Export "c:\temp2.xls"


Revert me back in case of query @ http://twitter.com/jaijeetpandey