18 Nov 2013

Remove the Spaces in a String without using Trim Functions

Remove the Spaces in a String without using Trim Functions

Dim str, newstr, arr

str ="Welcome to QTP World"

arr=split(str," " )

For i=lbound(arr) to ubound(arr)

newstr=newstr & arr(i)

Next

Msgbox newstr

Count the number of specific characters in a string using Regular Expression

Count the number of specific characters in a string using Regular Expression

Dim reRegExp 
str="BARBARICB"
 Set reRegExp = New RegExp
 With reRegExp
     .Global = True
     .Pattern = "B"
 Set Regcount = .Execute(str)
 End With
msgbox Regcount.count

17 Nov 2013

Reverse a each word of a String with and without StrReverse function using Vb Scripting

Reverse a each word of a String without using StrReverse function Vb Scripting

str="character/share/bangalore/chennai/trap"

x=split(str,"/")

For i = 0 to UBound(x)

sRev = StrReverse(x(i))

expStr = expStr & sRev & "/" 

Next


MsgBox expStr

Reverse a each word of a String with using StrReverse function Vb Scripting

Dim oStr,i 
oStr="Quick Test Professional" 
StrArray=split(oStr," ") 

For i=0 to ubound(StrArray) 
        msgbox strreverse(StrArray(i)) 
Next



Find the Length of a string without using InBuilt Functions using Vb Script

Length of a string without using InBuilt Functions using Vb Script

Dim arr()
On error resume next
str="My name is venkat kandula"
Set regex=new RegExp
regex.IgnoreCase=true
regex.Global=true
regex.pattern ="."
Set obj=regex.execute(str)
ReDim arr(obj.count-1)
i=0
For each temp in obj
    arr(i)=temp.value
    i=i+1
Next
msgbox i
Set obj=nothing
Set regex=nothing

3 Jul 2013

Run the Automation Script from machine 2, data present in machine 1 (Libraries, OR and Script)

Run the Automation Script from machine 2, data present in machine 1 (Libraries, OR and Script)

Use the following approach:

Set qtApp = CreateObject(“QuickTest.Application”, “Remote Machine Name”)

  Before using this statement ensure that the Distributed COM (DCOM) Configuration 

Properties of the remote computer are set to allow you to run QuickTest Professional 

Automation from your computer.

Steps to Set the DCOM Configuration Properties on Remote Machine

On the computer where you want to run the automation script, choose

Start–> Run. The Run dialog box opens.

1.Enter DCOMCNFG and click OK. The Distributed COM Configuration Properties 

dialog box or the Component Services window opens (depending on your operating 

system) and displays the list of COM applications available on the computer.

2.Select QuickTest Professional Automation from the list and open the Properties 

dialog box for the application. (Click the Properties button or right-click and choose 

Properties, depending on your operating system.)

3.In the QuickTest Professional Automation Properties dialog box, click the Security tab.

4.In the launch permissions section, choose the custom option and click Edit.

5.Use the Add and Remove options to select the network users or groups for which 

you want to allow or deny permission to launch QuickTest Professional via an automation 

script. When you are finished, click OK to save your settings.

6.Repeat steps 4and 5 for the configuration permissions section to select the users or 

groups who can modify QuickTest Professional configuration options via an 

automation script.

7.In the QuickTest Professional Automation Properties dialog box, click the Identity tab 

and select the interactive user option.

8.Click OK to save the QuickTest Professional Automation Properties settings.

9.Click OK to close the Distributed COM Configuration Properties dialog box or the 

Component Services window.

28 Jun 2013

Automation Object Model Scripts

Open QTP and Connect to Quality Center

' Declare the Application object variable 

Dim qtApp 

' Create the Application object 

Set qtApp = CreateObject("QuickTest.Application")  

' Start QuickTest 

qtApp.Launch  

' Make the QuickTest application visible 

qtApp.Visible = True  

' Make changes in a test on Quality Center with version control

' Connect to Quality Center 

qtApp.TDConnection.Connect "QC URL", "DOMAIN Name", "Project Name", "User Name", 

"Password", False  

' If connection is successful 

If qtApp.TDConnection.IsConnected Then  

   MsgBox "Succesfully connected to Quality Center" 

Else 

   MsgBox "Cannot connect to Quality Center" 

End If 

' Exit QuickTest 

qtApp.Quit  

' Release the Application object 

Set qtApp = Nothing  

Start QTP and open New test  

' Declare the application object variable 

Dim qtApp  

' Create the application object 

Set qtApp = CreateObject("QuickTest.Application")  

' Start QuickTest 

qtApp.Launch  

' Make the QuickTest application visible 

qtApp.Visible = True  

' Open a new test 

qtApp.New  

' Release the Application object 


Set qtApp = Nothing  

 Start QTP, open an existing test and Run the Test 

' Declare the application object variable 

Dim qtApp 

Dim qtTest 

' Create the Application object 

Set qtApp = CreateObject("QuickTest.Application")  

' Start QuickTest 

qtApp.Launch  

' Make the QuickTest application visible 

qtApp.Visible = True  

' Set QuickTest run options 

qtApp.Options.Run.ImageCaptureForTestResults = "OnError" 

qtApp.Options.Run.RunMode = "Fast"  

qtApp.Options.Run.ViewResults = False 

' Open the test in read-only mode 

qtApp.Open "C:\Tests\Test1", True  

' Set run settings for the test 

Set qtTest = qtApp.Test 

' Instruct QuickTest to perform next step when error occurs 

qtTest.Settings.Run.OnError = "NextStep"  

' Run the test 

qtTest.Run  

' Check the results of the test run 

MsgBox qtTest.LastRunResults.Status  

' Close the test 

qtTest.Close  

' Release the Test object 

Set qtTest = Nothing  

' Release the Application object 


Set qtApp = Nothing  

Start QTP, open an existing test, Run the Test with configured Run and Result options 

' Declare the application object variable 

Dim qtApp 

Dim qtTest 

Dim qtResultsOpt 

' Create the Application object 

Set qtApp = CreateObject("QuickTest.Application")  
  
' Start QuickTest 

qtApp.Launch  

' Make the QuickTest application visible 

qtApp.Visible = True  

' Set QuickTest run options 

qtApp.Options.Run.ImageCaptureForTestResults = "OnError" 

qtApp.Options.Run.RunMode = "Fast" 

qtApp.Options.Run.ViewResults = False 

' (True) Open the test in read-only mode 

qtApp.Open "C:\Tests\Test1", True  

' Set run settings for the test 

Set qtTest = qtApp.Test 

' Run only iterations 2 to 4 

qtTest.Settings.Run.IterationMode = "rngIterations"  

qtTest.Settings.Run.StartIteration = 2 

qtTest.Settings.Run.EndIteration = 4 

' Instruct QuickTest to perform next step when error occurs 

qtTest.Settings.Run.OnError = "NextStep"  

' Create the Run Results Options object 

Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")  

' Set the results location 

qtResultsOpt.ResultsLocation = "C:\Tests\Test1\Res1"  

' Run the test 

qtTest.Run qtResultsOpt  

' Check the results of the test run 

MsgBox qtTest.LastRunResults.Status  

' Close the test 

qtTest.Close  

' Release the Run Results Options object 

Set qtResultsOpt = Nothing  

' Release the Test object 

Set qtTest = Nothing  

' Release the Application object  


Set qtApp = Nothing

 Start QTP, open an existing test, associate libraries and save the test 

' Declare the application object variable 

Dim qtApp 

Dim qtLibraries 

Dim lngPosition 

' Create the Application object 

Set qtApp = CreateObject("QuickTest.Application")  

' Launch QuickTest 

qtApp.Launch  

' Set QuickTest to be visible 

qtApp.Visible = True  

' Open a test 

qtApp.Open "C:\Tests\Test1", False, False  

' Get the libraries collection object 

Set qtLibraries = qtApp.Test.Settings.Resources.Libraries  

' Add Utilities.vbs if it's not in the collection 

' If the library cannot be found in the collection 
  
If qtLibraries.Find("C:\Utilities.vbs") = -1 Then  

   ' Add the library to the collection 

    qtLibraries.Add "C:\Utilities.vbs", 1  

End If 

' Save the test 

qtApp.Test.Save  

' Quit QuickTest 

qtApp.Quit  

' Release the test's library’s collection 

Set qtLibraries = Nothing  

' Release the Application object 


Set qtApp = Nothing  

Start QTP, open an existing test, associate Object Repositories and save the test
  
' Declare the application object variable 

Dim qtApp 

Dim qtRepositories 

Dim lngPosition 

' Create the Application object 

Set qtApp = CreateObject("QuickTest.Application")  

' Launch QuickTest 

qtApp.Launch  

' Set QuickTest to be visible 

qtApp.Visible = True  

' Open a test and get the "Login" action's object repositories collection 

qtApp.Open "C:\Tests\Test1", False, False   

' Get the object repositories collection object of the "Login" action 

Set qtRepositories = qtApp.Test.Actions("Login").ObjectRepositories  

' Add MainApp.tsr if it's not already in the collection 

' If the repository cannot be found in the collection 

If qtRepositories.Find("C:\MainApp.tsr") = -1 Then  

   ' Add the repository to the collection 

   qtRepositories.Add "C:\MainApp.tsr", 1  

End If 

'Save the test and close QuickTest 

qtApp.Test.Save 

qtApp.Quit 

' Release the action's shared repositories collection 

Set qtRepositories = Nothing  

' Release the Application object 


Set qtApp = Nothing  

Open and minimize QTP Window  

' Declare the application object variable 

Dim qtApp 

' Create the Application object 

Set qtApp = CreateObject("QuickTest.Application")  

' Start QuickTest 

qtApp.Launch  

' Make the QuickTest window visible 

qtApp.Visible = True  

' Maximize the QuickTest window 

qtApp.WindowState = "Minimized"   

' Release the Application object 


Set qtApp = Nothing  

Start QTP, Open an Existing Test and Get All Available Action Names From the Test
  
' Declare the application object variable 

Dim qtApp 

' Create the Application object 

Set qtApp = CreateObject("QuickTest.Application")  

' Launch QuickTest   

qtApp.Launch  

' Set QuickTest to be visible 

qtApp.Visible = True  

' Open a test 

qtApp.Open "C:\Tests\Test1", False, False 

oActCount=qtApp.Test.Actions.Count 

For iCounter=1 to oActCount 

     ' Get the first action in the test by index (start from 1) 

     MsgBox qtApp.Test.Actions(iCounter).Name 

Next 

'Close QuickTest 

qtApp.Quit  

' Release the Application object 


Set qtApp = Nothing

Start QTP with specified views 

' Declare the application object variable 

Dim qtApp 

' Create the Application object 

Set qtApp = CreateObject("QuickTest.Application") 

' Start QuickTest 

qtApp.Launch  

' Display the Expert View 

qtApp.ActivateView "ExpertView"  

' Display the Active Screen pane 

qtApp.ShowPaneScreen "ActiveScreen", True  

' Hide the Data Table pane 

qtApp.ShowPaneScreen "DataTable", False  

' Display the Debug Viewer pane 

qtApp.ShowPaneScreen "DebugViewer", True  

' Maximize the QuickTest window 

qtApp.WindowState = "Maximized"  

' Make the QuickTest window visible 

qtApp.Visible = True  

' Release the Application object 


Set qtApp = Nothing  

4 Jun 2013

Capture the screen shot withou word object

How to the Capture the screen shot withou word object

'Create a function as showed below.

'Taking Screenshot using word object

Set oWordBasic = CreateObject("Word.Basic")

oWordBasic.SendKeys "{prtsc}"
oWordBasic.AppClose "Microsoft Word"

Set oWordBasic = Nothing
'WScript.Sleep 2000

wait 10

'Opening Paint Application
set WshShell = CreateObject("WScript.Shell")

WshShell.Run "mspaint"
'WScript.Sleep 2000

wait 10
'Activating Paint Application
WshShell.AppActivate "untitled - Paint"

'WScript.Sleep 1000
 wait 10
'Paste the captured Screenshot

WshShell.SendKeys "^v"
'WScript.Sleep 500
wait 10

'Save Screenshot
WshShell.SendKeys "^s"
wait 10
'WScript.Sleep 500
WshShell.SendKeys "c:\test.bmp"
wait 10
'WScript.Sleep 500
WshShell.SendKeys "{ENTER}"

wait 10

'Release Objects
Set WshShell=Nothing

wait 10