SPONSORS:






User Tag List

Results 1 to 8 of 8
  1. #1
    Junior Member
    Join Date
    Aug 2002
    Location
    Roseville, CA, USA
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamically instantiate objects

    Can I dynamically instantiate objects?

    What I want to do is be able to read from a data file the name of the window I want to declare, and the class I want to set it to.

    For example:

    data file reads:
    "activity1, GetFileClass
    activity2, PrintMyFileClass
    activity3, PrintMyFileClass"

    I want to declare in SilkTest the following code:
    WINDOW activity1 = GetFileClass();
    WINDOW activity2 = PrintMyFileClass();
    WINDOW activity3 = PrintMyFileClass();

    But I'm not sure I can do this dynamically. I would like to have different data files for different scenarious. So, the first test, I call GetFileClass 3 times, but the second test, I call GetFileClass 10 times.

    I used the "@" reference, but every time I try, SilkTest says there is a syntax error.

    The classes I am using are not actual windows, but user-defined classes.

    Any suggestions??

    Thanks!

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

  2. #2
    Member
    Join Date
    Jun 2001
    Location
    Bedford, MA, USA
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Dynamically instantiate objects

    You can do this. Here's how:

    The script and the datafile are attached.
    Hope this helps!
    - Jim




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

  3. #3
    Member
    Join Date
    Jun 2001
    Location
    Bedford, MA, USA
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Dynamically instantiate objects

    On second thought, here's a much simpler version.
    I don't know how you plan to use the objects that you will instanciate dynamically.
    I presume that the classes in the input file could vary in type and number. Therefore your scripts/testcases should not contain hardcoded references to these objects. By using a list, you can reference any number of objects. It will work fine as long as the methods are polymorphic.
    - Jim

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

  4. #4
    Member
    Join Date
    Jun 2001
    Location
    Bedford, MA, USA
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Dynamically instantiate objects

    oops...
    The text file (MyInputFile.txt) that I attached above contains an entry that will cause the script to fail. To fix it, either remove the item "SomeOtherClass" from the text file or define a window class named SomeOtherClass in the script. Sorry for the confusion.
    - Jim

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

  5. #5
    Member
    Join Date
    Jun 2001
    Location
    Bedford, MA, USA
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Dynamically instantiate objects

    Glad to help!

    Originally posted by stauffer1963: <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>I actually have the name of the class and any parameters that it may need in the text file...<HR></BLOCKQUOTE>

    Are these parameters for method calls, or for the initialization of the object? If it's the latter, I have a SilkTest function called New() that instanciates an object of any given class and calls the object's constructor (if one exists) passing-in the parameter values.
    Also, you may want to use the technique in the 1st example which reads records from the input file instead of just the class name.

    Let me know if you're interested in the New() function. I use it for dynamic instanciation of non-Window objects, but it would work fine for window objects also.

    - Jim


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

  6. #6
    Junior Member
    Join Date
    Aug 2002
    Location
    Roseville, CA, USA
    Posts
    2
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Dynamically instantiate objects

    Thank you VERY much, Jim!!

    I actually have the name of the class and any parameters that it may need in the text file, so I just read the class names in a seperate list of string.

    But you're code worked wonderfully!! Thanks again! You saved me a LOT of work!!

    Lynnette

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

  7. #7
    Junior Member
    Join Date
    Nov 1999
    Location
    la,ca,us
    Posts
    8
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Dynamically instantiate objects

    Out of curiosity I would like to see your new () function and how you call the contructor. I try to treat most of my code as OO as I can and I am interested in seeing how you are handling this with the new () function.

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

  8. #8
    Member
    Join Date
    Jun 2001
    Location
    Bedford, MA, USA
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Dynamically instantiate objects

    catman,

    I've attached a zip file that contains the New() function and related include files. Also included is a sample script (DynamicObject.t) that demonstrates how to use New().

    I use it to create non-GUI automation objects that represent the things the application deals with (customer, vendor, etc) or things we want to interact with via automation, such as databases, server machines, and AppServers.

    I hope you find these include files useful.
    - Jim


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

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin 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 03:49 PM.

Copyright BetaSoft Inc.