Wednesday, January 14, 2009

Search for a word and replace the word with a new word then save as a different file name

'Before this script executes, you need to have a "Greetings.doc" in C drive and it contains some information. In that information each line is contains a word "Good". Now my objective is to Replace the word "Good" with "Bad". And save file with new name.
################################################################

Set Word = CreateObject("Word.Application")
Word.Visible = TRUE
Set WordDoc=Word.Documents.Open ("C:\Greetings.doc")
Do
With Word.Selection.Find
.Text = "Good"
.Replacement.Text = "Bad"
.Forward = True
.wrap=1
.Format = False
.MatchWholeWord = True
End With
Word.Documents.Application.Selection.Find.Execute
If Word.Selection.Find.Found Then
Word.Selection.Range="bad"
else
Exit Do
End If
Loop
WordDoc.SaveAS "C:\BadGreetings.doc"

QTP VB Script Trainings

Check out this SlideShare Presentation:
QTP VB Script Trainings
View SlideShare presentation or Upload your own.

QTP Shortcut Keys

Check out this SlideShare Presentation:
QTP Shortcut Keys
View SlideShare presentation or Upload your own.

Polish Your Skills For QTP Interview In MNC's

Check out this SlideShare Presentation:

How to Implement Keyword Driven Methodology in QTP

Check out this SlideShare Presentation:

QTP Descriptive Programming

Check out this SlideShare Presentation:

Sunday, January 11, 2009

QTP 9.2

Check out this Presentation:
QTP 9.2
View SlideShare presentation or Upload your own. (tags: solutions testing)

Script for adding and ramoving Object repository to an action

Here i have written two functions for adding and removing Object Repositories for an action call these function with object repository path.
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Adding Repository to an action
Function AddRepositorytoCurrentAction(RepPath)

Dim qtApp,qtRepositories, actName

actName=Environment.Value("ActionName")

Set qtApp = CreateObject("QuickTest.Application")
Set qtRepositories = qtApp.Test.Actions(actName).ObjectRepositories

If qtRepositories.Find(RepPath) = -1 Then
qtRepositories.Add RepPath, 1
End If

If rmvPosition<> -1 Then
Reporter.ReportEvent micPass,"Adding Object Repository","Object Repository is Succesfully Added to the Action "&actName
else
Reporter.ReportEvent micFail,"Adding Object Repository","Object Repository is not Added to the Action "&actName
End If

qtApp= Nothing
qtRepositories= Nothing
End Function

'Remove repository from an action
Function RemoveRepositoryfromCurrentAction(RepPath)
Dim qtApp,qtRepositories, actName

actName=Environment.Value("ActionName")

Set qtApp = CreateObject("QuickTest.Application")
Set qtRepositories = qtApp.Test.Actions(actName).ObjectRepositories

rPosition=qtRepositories.Find(RepPath)

qtRepositories.Remove rPosition

rmvPosition=qtRepositories.Find(RepPath)

If rmvPosition= -1 Then
Reporter.ReportEvent micPass,"Removing Object Repository","Object Repository is Succesfully Removed From the Action "&actName
else
Reporter.ReportEvent micFail,"Removing Object Repository","Object Repository is not Removed From the Action "&actName
End If

qtApp= Nothing
qtRepositories= Nothing

End Function

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

To get the tool tip of the Link

l_ToolTip=Browser( bName).Page( pName).Link( lName).object. title
msgbox
l_ToolTip
This statement will bring the tooltip of a link.

How to click on Dynamic Links

Here is the script to click on the dynamic Links in table. Even though if any link are dynamic we can get control on the links by using index.

'########### ######### ######### ######### ######### ######### #########
Set TblObj=Browser( BrowserProp) .Page(PageProp) .WebTable( TableProp)

r_Count=TblObj. RowCount

For r=1 to r_Count
c_Count=TblObj. ColumnCount( r)

For c=1 to c_Count

chItems_Count= TblObj.ChildItem Count(r,c, "Link")

For ItemIndex=0 to chItems_Count- 1

Set ch_Item=TblObj. ChildItem( r,c,"Link" ,ItemIndex)
Print ch_Item.object. title
ch_Item.click
' Specify the required operations after clicking on link
' Make sure that again you should navigate to the same page to get other links tooltip
'Or to click on other Links
Next

Next
Next
'########### ######### ######### ######### #########

How to use Classes in QTP

Here i am giving an useful information about how to use classes in QTP.

Before going to that we will discuss about using functions in QTP.

If there is a function in our script like this

'*********** ********* ********* ********* ********* ********* **
Function Demo(a,b)
demo=a+b
End Function
'*********** ********* ********* ********* ********* ********* **

This is a function to add two numbers.
To call this function we write
'*********** ********* *****
val=demo(2,3)
msgbox val
'*********** ********* *****
We can store the functions in library files (.vbs) and to use this function, Library should be associated to the QTP Test or library file should be executed by QTP Test using ExecuteFile statement.
This means we can use the functions which are written in QTP Script or in Library files by associating it or by executing it.

But this is not possible when using classes in our QTP Test. If we want to use a class which is there in the libraryfile its mandotory that the library should be executed using Executefile statement.
Classes will not work which are there in associated libraries. Here is an example...

'*********** ********* ********* ********* ********* **
Class Maths
Function Add1(a,b)
add1=a+b
End Function

Function sub1(a,b)
sub1=a-b
End Function

End Class
'*********** ********* ********* ********* ********* **
If the above code is there with in the test script then the usage of this class will be like this
'*********** ********* ********* ********* ********* **
Set mat=New Maths
val=mat.add1( 2,3)
msgbox val
'*********** ********* ********* ********* ********* **
If the class code is there with in the library file then the usage of this class will be like this
'*********** ********* ********* ********* ********* **
ExecuteFile (Library Path)
Set mat=New Maths
val=mat.add1( 2,3)
msgbox val
'*********** ********* ********* ********* ********* **
This class will not work If you just associate the library with in the
File--> Settings --> Resources
But there is a way of using the classes even though if it is in associated library.

First Method:
Where ever the class is declared in the library it self create the class instance and use it in your qtp script.
'*********** ********* ********* ********* ********* **
Set mat=New Maths

Class Maths
Function Add1(a,b)
add1=a+b
End Function

Function sub1(a,b)
sub1=a-b
End Function

End Class
'*********** ********* ********* ********* ********* **
To Use this class
'*********** ********* *
val=mat.add1( 2,3)
msgbox val
'*********** ********* *

Second Method:
Create a function which is returning class object by creating instance of the class.
'*********** ********* ********* ********* ********* **
Function mat()
Set mat=New Maths
End Function

Class Maths
Function Add1(a,b)
add1=a+b
End Function

Function sub1(a,b)
sub1=a-b
End Function

End Class
'*********** ********* ********* ********* ********* **
To Use this class
'*********** ********* *
Set mth=mat ' mat is a function which will return the class instance
val=mth.add1( 2,3)
msgbox val
'*********** ********* *

About Me

My photo
Hi all,I am Arun Singh Rajaputra. I am working as a Project Lead in a reputed organization in Hyderabad, AP, India. I have little bit knowledge on Quick Test Professional and like to share my knowledge to all through this blog.

Subscribe to get updates on this blog

Enter your email address:

NOTE

Some of the posts posted in this blog are collected and most of them have been prepared by me. If any one have objections regarding any copied posts. Please mail me so that I can take a necessary action on that post.