Custom Search

Friday, March 30, 2012

How to reverse the string with out using strreverse function and not rotate the loop up to string length? ex: if you have a string length 10 characters, string should be reversed in off of the loop rotation.

 str=inputbox ("Enter String:")
 intlen=round(len(str)/2)
 leftstr=mid(str,1,intlen)
 rgtstr=mid(str,intlen+1,len(str))
 res=mid(str,intlen,1)
 For i=1 to len(leftstr) -1

  leftres=mid(rgtstr,i,1)
  rgtres=mid(leftstr,intlen-i,1)
  res=leftres&res&rgtres

 Next

 If Len(str)<>len(res) Then
  res=mid(str,len(str),1)&res
 End If
 msgbox res

Wednesday, March 7, 2012

Can we set value in Edit /Text field without using .set method.

Using below code you can enter values in edit field with out using set method
Browser("Gmail: Email from Google").Page("Gmail: Email from Google").WebEdit("Email").Object.value="gmail"

Monday, March 5, 2012

How do we add object repository dynamically in QTP

Rem declaring Variables
Dim qtApp 'QuickTest.Application object variable
Dim qtRepositories 'QuickTest.Repositories object variable
' Create the QTP Application object
Set qtApp = CreateObject("QuickTest.Application")
' Create the Repositories object
Set qtRepositories = qtApp.Test.Actions("DriverScript").ObjectRepositories
' If there are any Repository , remove them
qtRepositories.RemoveAll()
' Add Repository
qtRepositories.Add(strRepositoryFilePath)
' Release the Application object
Set qtApp = Nothing
' Release the Repositories object
Set qtRepositories = Nothing
==========OR========
Use below code- below code is supported after QTP 9.5 versions.
RepositoriesCollection.Add "C:\Test.tsr"


Friday, March 2, 2012

Sorting an array with out using Sort method in vbscript/QTP

dim arrSortOut(8)
arrSortOut(0)="xCount"
arrSortOut(1)="zExec"
arrSortOut(2)="yFinance"
arrSortOut(3)="HR"
arrSortOut(4)="IT "
arrSortOut(5)="!aaaLegal"
arrSortOut(6)="Liberman"
arrSortOut(7)="Martha"
arrSortOut(8)="Regis"

for i = UBound(arrSortOut) - 1 To 0 Step -1
     for j= 0 to i
          if arrSortOut(j)>arrSortOut(j+1) then
             temp=arrSortOut(j+1)
             arrSortOut(j+1)=arrSortOut(j)
             arrSortOut(j)=temp
         end if
    next
next

for x=0 to 8
    print arrSortOut(x)
next

Sorting an array using Sort method in Vbscript/QTP

dim myArray(6)
myArray(0)= "New"
myArray(1)= "Old"
myArray(2)= "Add"
myArray(3)= "Create"
myArray(4)= "Insert"
myArray(5)= "Delete"

Set myArrayList= CreateObject( "System.Collections.ArrayList" )
For i=0 to Ubound(myArray)-1
myArrayList.Add myArray(i)
Next

Rem Sorting array list
myArrayList.sort

For i=0 to Ubound(myArray)-1
print myArrayList.item(i)
Next

Sunday, January 29, 2012

Open Internet Explorer through CreateObject


Function IEOpen( strApplicationURL,bBrowser)
   Set IE=CreateObject("InternetExplorer.application")
   IE.visible=True
   IE.Navigate2 strApplicationURL ''''''''' Application URL as parameter
   IE.WindowState=Maximized
   Browser(bBrowser).sync '''''''' Application Browser Object as parameter
End function

Monday, January 23, 2012

Dictionary Object


Dictionary Object 
Dictionary Object  stores data key, item pairs. A Dictionary object stores the items in the array. Each item is associated with a unique key. The key is used to retrieve an individual item and is usually an integer or a string, but can be anything except an array. 


 Advantages of using it in QTP:
1. can be used as Global variable declaration. so that any test can access the values from it in the run time.
2. You can store and retrieve any number of run time values in to dictionary.
3. It is one of the Parametrization technique we can use in QTP

we can use below methods in Dictionary Object.
1. Add Method
2. Exists Method
3. Items Method
4.Keys Method
5. Remove Method
6. Removeall Method

Add Method
=========
Dim d ' Create a variable. 
Set d = CreateObject("Scripting.Dictionary") 
d.Add "a", "Athens" ' Add some keys and items. 
d.Add "b", "Belgrade" 
d.Add "c", "Cairo"

Exists Method
=========
Dim d, msg ' Create some variables. 
Set d = CreateObject("Scripting.Dictionary") 
d.Add "a", "Athens" ' Add some keys and items. 
d.Add "b", "Belgrade"
d.Add "c", "Cairo" 
If d.Exists("c") Then 
msg = "Specified key exists." 
Else
msg = "Specified key doesn't exist."
End If

Items Method
=========
Use below code after add the values to dictionary

a = d.Items ' Get the items. 
For i = 0 To d.Count -1' Iterate the array. 
s = s & a(i) & "
" ' Create return string. 
Next