-->Steps to Associate an Object Repository file to an Action of the Script

1. Ensure that the shared object repository file is available
2. Select Resources -> object repository -> Tools -> Associate Repository
3. Select the required object repository file using the + button
4. Select the required action from the list
5. Click on associate button (>)
6. Click on OK
Note: By default the objects in the associated object repository file are non-editable. To make it editable, right click on the required object and select “Copy to Local”
Script to associate an object repository file to an action of the script:
Dim App
Set App=CreateObject(“QuickTest.Application”)
Set Repositories=App.Test.Actions(“Action1”).ObjectRepositories
If Repositories.Find(“D:\QTPTesting\stureg.tsr”)=-1
Then Repositories.Add “D:\QTPTesting\stureg.tsr”,1
End if
Note:If we want to assign for multiple actions, we need to write the code set multiple times

Alternative code (Available from QTP_9.2)
If RepositoriesCollection.Find(“D:\QTPTesting\stureg.tsr”)=-1
RepositriesCollection.Add(“D:\QTPTesting\stureg.tsr”),1
End If
Note: RepositoriesCollection.Count (Method to count object repositories)
RepositoriesCollection.Remove (Method to remove object repositories)

Sample Script:
VBWindow(“Login”).VBEdit(“User id”).Set “Pass”
VBWindow(“Login”).VBEdit(“Password”).SetSecure “sunil”
VBWindow(“Login”).ACXCalender(“DTPicker”).Setdate “20-july-2009”
VBWindow(“Login”).VBButton(“OK”).Click

We can use “With” statement to reduce the repeating of the parent windows code every time:

With VbWindow(“Login”)
.VBEdit(“User id”).Set “Pass”
.VBEdit(“Password”).SetSecure “sunil”
.ACXCalender(“DTPicker”).Setdate “3-feb-2009”
.VBButton(“OK”).Click
End With

To apply “With” Statement:
Edit -> Advanced -> Apply “with” to Script (Remove “With” from Script)

If the AUT is Java & Java Add-in is selected, the script would be like below:
With JavaWindow(“Login”)
.JavaEdit(“User id”).Set “Pass”s
.JavaEdit(“Password”).SetSecure “sunil”
.JavaCalender(“DTPicker”).Setdate “3-feb-2009”
.JavaButton(“OK”).Click
End With

If the AUT is .Net & .Net Add-in is selected, the script would be like below:
(Swf means Shake Wave Form)
With SwfWindow(“Login”)
.SwfEdit(“User id”).Set “Pass”
.SwfEdit(“Password”).SetSecure “sunil”
.SwfCalender(“DTPicker”).Setdate “3-feb-2009”
.SwfButton(“OK”).Click
End With

If the AUT is Web application & Web technology Add-in is selected, the script would be like below:
With Browser(“name”).Page(“Login”).Frame(“login”)
.WebEdit(“User id”).Set “Pass”
.WebEdit(“Password”).SetSecure “sunil”
.WebCalender(“DTPicker”).Setdate “3-feb-2009”
.webButton(“OK”).Click
End With
Note: The path where we can see the controls of all the languages is “Tools --> Object Repository”
“Nested with” also works in QTP

If no language is selected, then QTP identifies the objects as standard windows controls, like below:
With Dialog(“Login”)
.WinEdit(“User id”).Set “Pass”
.WinEdit(“Password”).SetSecure “sunil”
.WinCalender(“DTPicker”).Setdate “3-feb-2009”
.WinButton(“OK”).Click
End With