SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 16
  1. #1
    Member
    Join Date
    Mar 2012
    Posts
    285
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Class Based framework Approach

    Hi,
    I have seen many users using a class based framework approach for their qtp tests.
    Can people throw some light on the advantages of a class based framework in comparison to a Keyword approach / BPT etc.
    Advantages in terms of encapsulation / abstraction / polymorphism? Is it a serious game changer?

  2. #2
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: Class Based framework Approach

    Well from QTP 12/UFT 12 it will be. I love to use classes because of the way it allows you to structure code. But with QTP 11 having no intellisense for classes life becomes quite tough. But that will come in next version and I guess I will move to a pure class based framework

  3. #3
    Member
    Join Date
    Feb 2012
    Posts
    74
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Class Based framework Approach

    Can anyone shed more light on the class based framework. I am hearing it for the first time here & also not much of info available out here . How exactly does this differentiate from the current available frameworks ? Any pointers for any docs .. ?
    If you do find solution to a problem - have a bud & re-visit !

  4. #4
    Member
    Join Date
    Mar 2012
    Posts
    285
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Class Based framework Approach

    @Kartik - You can check out Relevant codes. Anshoo has a Class based framework approach demo uploaded there which you can refer to.

    @Tarun - Thanks a lot. Could you share on how one goes about creating one?
    1.What does one class represent (is it like one module for one class eg. Login)
    2.How does the test flow take place (one class instantiating the object of another class and so on)
    3.How would different test scripts be created:
    eg Script A: ClassA -> ClassB -> ClassC
    Script B: ClassA -> ClassC-> ClassD
    This is kinda confusing. Hope to get some more light on the topic

    There are many topics available for creating a class (variables,properties,methods,instantition,destruc tion) etc but how is the whole thing organized to create an entire end to end class based framework.
    Thanks

  5. #5
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: Class Based framework Approach

    Well one is your core functionality goes into classes. Like below
    <font class="small">Code:</font><hr /><pre>
    Class Logger
    Sub LogText()
    End Sub
    End Class

    Set Log = New Logger


    Class HomePage
    Sub Login(username, password)
    Browser().Page().WebEdit("username").Set username
    Browser().Page().WebEdit("password").Set password

    End Sub
    End Class
    Set oHomePage = New HomePage

    Log.LogText "Start login"
    HomePage.Login "tarun", "tarun"
    </pre><hr />

  6. #6
    Super Member QAGanesh's Avatar
    Join Date
    Sep 2010
    Posts
    1,898
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Class Based framework Approach

    Tarun,

    True but then to create a new instance of a Class defined in library file, can this be done in QTP script file or does it need to be in the functional library itself.

    Are we also going to have something like importing class definition and use them in test script(using import statements as in programming)
    Thanks,
    Ganesh Iyer
    Winds of Change

  7. #7
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: Class Based framework Approach

    Well you can add a generic method in the library file to get any class object

    <font class="small">Code:</font><hr /><pre>
    Function GetNewClass(ByVal Name)
    Set GetNewClass = Eval("New " &amp; Name)
    End Function
    </pre><hr />

  8. #8
    Super Member QAGanesh's Avatar
    Join Date
    Sep 2010
    Posts
    1,898
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Class Based framework Approach

    Thanks Tarun
    Thanks,
    Ganesh Iyer
    Winds of Change

  9. #9
    Advanced Member Anshoo Arora's Avatar
    Join Date
    Oct 2007
    Location
    New Delhi, India
    Posts
    635
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Class Based framework Approach

    Some of my classes require a single instantiation, which is where I avoid using repeat Function calls to load them. The reason is, each time I use a function call to load my class, the Class_Initialize and Class_Terminate routines load as well. Example (each time the function call is made, Class_Initialize and Class_Terminate will execute):

    <font class="small">Code:</font><hr /><pre>
    Class TestClass
    Public Sub Method()
    Print "In Method()"
    End Sub

    Private Sub Class_Initialize()
    Print "In Class_Initialize()"
    End Sub

    Private Sub Class_Terminate()
    Print "In Class_Terminate()"
    End Sub
    End Class

    Public Function GetTestClassInstance()
    Set GetTestClassInstance = New TestClass
    End Function

    Set NewTestClass = GetTestClassInstance
    Set NewTestClass = GetTestClassInstance
    Set NewTestClass = GetTestClassInstance
    Set NewTestClass = GetTestClassInstance
    </pre><hr />

    Output:

    <font class="small">Code:</font><hr /><pre>
    In Class_Initialize()
    In Class_Initialize()
    In Class_Terminate()
    In Class_Initialize()
    In Class_Terminate()
    In Class_Initialize()
    In Class_Terminate()
    In Class_Terminate()
    </pre><hr />

    Instead, I bind to the existing instance created from the function (Use NewTestClass instead of GetTestClassInstance) or simply instantiate like this:

    <font class="small">Code:</font><hr /><pre>
    Class TestClass
    Public Sub Method()
    Print "In Method()"
    End Sub

    Private Sub Class_Initialize()
    Print "In Class_Initialize()"
    End Sub

    Private Sub Class_Terminate()
    Print "In Class_Terminate()"
    End Sub
    End Class

    Public NewTestClass: Set NewTestClass = New TestClass
    </pre><hr />

    *Edit: Now, in cases where I do not want to instantiate my classes when libraries load, I just declare the variables as Public but instantiate the class when some "behavior" occurs. Example:

    <font class="small">Code:</font><hr /><pre>
    'Some where in my library
    Public NewTestClass

    'Some where else in my library
    Class PageObject
    Public Sub PageObjectMethod()
    If PageObjectLoadSuccessful Then
    Set NewTestClass = New TestClass
    End If
    End Sub
    End Class
    </pre><hr />

    Added a more detailed explanation here: http://relevantcodes.com/qtp-oops-class-instantiation/
    Regards,

    Anshoo Arora
    Relevant Codes

  10. #10
    Super Member QAGanesh's Avatar
    Join Date
    Sep 2010
    Posts
    1,898
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: Class Based framework Approach

    Anshoo,

    Thanks for the sample code.

    This ideally means you have a single functional library file, Let us take an instance where I have two functional libraries

    'f1.vbs

    Class TestClass1
    Public Sub Method()
    Print "In Method()"
    End Sub

    Private Sub Class_Initialize()
    Print "In Class_Initialize()"
    End Sub

    Private Sub Class_Terminate()
    Print "In Class_Terminate()"
    End Sub
    End Class

    'f2.vbs
    Public NewTestClass

    'Some where else in my library
    Class PageObject
    Public Sub PageObjectMethod()
    If PageObjectLoadSuccessful Then
    Set NewTestClass = New TestClass1
    End If
    End Sub
    End Class

    then If i wish to create an instance of TestClass1 as above, how can i provide a reference of the other functional library since my TestClass1 is in f1.vbs.

    So should we use Eval/Execute statement after reading the contents of f1.vbs so these are available for f2.vbs


    -------------------------------------------

    Not sure, if I sound correct with my question. It might be vague but I had taken this approach some time back, so wanted to know if this is the right way or is there a simpler way of doing the same.
    Thanks,
    Ganesh Iyer
    Winds of Change

 

 
Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 10.00%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 04:10 PM.

Copyright BetaSoft Inc.