Header Ads

Load Object Repository Dynamically in QTP

When automation test engineers design a framework, always they target to run the script uninterruptedly .Even if entry level record and framework needs an uninterrupted run!!! So for uninterrupted flow execution, one important aspect is choose and execute a set of predefined scripts.Sounds good!!!
Automation test engineers tried a lot and succeed by using excel or data loading logic.Yes...the power of automation viz coding logic. Excel was having several columns along with an executable column . Where automation test engineers use to mentioned like yes or no. Based on that value the framework use to use to pick correct row to execute which intern calls correct subscripts to run.


One more sophisticated way to run through batch execution. More can be found here..
http://www.askqtp.com/2009/03/test-batch-runner.html


With this approach there ware  flaws.
1. It was not dynamic enough.
2. It was very slow as framework used to load all the object repositories at a time or used to load a shared object repository.
3. Execution was frequently stuck by the object identification errors.


In this article I want to venture how an automation engineer team has overcome these problems.
Well , after an analysis automation engineers saw that if we can control the Object repository and supply the same as and when required basis to the framework, we will be able to solve the huge shared object repository .
This is kind of divide and conquer rule!!!.


From this concept automation test engineers came up with incorporation of dynamic object repository loading concept.
Let us look into the code..Here is small function or a method that will load Object Repository Dynamically.




Function Load_OR(sPath)
'/This is the path where the OR is situated.
'msgbox sPath
Set objnew = CreateObject("QuickTest.Application")
objnew.Test.Settings.Resources.ObjectRepositoryPath =sPath
Set objnew= Nothing
End Function
This function is written in QTP 8.2.Dont Know if it can be used in QTP 9 and above.allmost the same but another technique is given below......The interesting point is tha here the path is also dynamic.


Public Sub proAddRepository(ByVal strRepName)
Dim App
Dim qtRepositories
Set App = CreateObject("QuickTest.Application") ' Create the Application object
App.Launch ' Launch QuickTest
App.Visible = True ' Set QuickTest to be visible
Set qtRepositories = App.Test.Actions(Environment("ActionName")).ObjectRepositories
'If the repository cannot be found in the collection
If qtRepositories.Find(strRepName) = -1 Then
Wait(1)
qtRepositories.Add strRepName, 1
End If
Set qtRepositories = Nothing
Set App = Nothing
End Sub

Lets see an example....


Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtRepositories 'As QuickTest.ObjectRepositories ' Declare an action's object repositories collection variable
Dim lngPosition
' Open QuickTest
Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object


Set qtRepositories = qtApp.Test.Actions("Login").ObjectRepositories ' Get the object repositories collection object of the "Login" action


' Add MainApp.tsr if it's not already in the collection
repositorypath=InputBox("Enter the abosolute path along with the Repository name to attache")
If qtRepositories.Find(repositorypath) = -1 Then ' If the repository cannot be found in the collection
qtRepositories.Add repositorypath, 1 ' Add the repository to the collection
End If
' Set the new object repository configuration as the default for all new actions
qtRepositories.SetAsDefault ' Set object repositories associated with the "Login" action as the default for all new actions
'Save the test and close QuickTest
qtApp.Test.Save ' Save the test
qtApp.Quit ' Quit QuickTest
Set qtRepositories = Nothing ' Release the action's shared repositories collection
Set qtApp = Nothing ' Release the Application object

The code has placed the automation one step further. Framework has been improved.
Shared object repository concept has been removed for ever!!!!!





Powered by Blogger.