Forum Discussion

dkasirajan's avatar
dkasirajan
Contributor
8 years ago

We are moving to Python Scripting from keyword script.

I have couple of question: -Which one is good going complete Python Scripting or Keyword Script and python script mixed. -I do want to follow object oriented concept  in scripting. How to organize ...
  • tristaanogre's avatar
    8 years ago

    WEll, more than a couple of questions

     

    -Which one is good going complete Python Scripting or Keyword Script and python script mixed.

     

     

    The answer I'm going to give may seem unhelpful... but it depends.  What works best for you? I know some folks who go full on script... and some folks who use Keyword tests driven by script... or some folks who just use all keyword tests.  cunderw demonstrated a project at the recent user conference where he has a bunch of JavaScript units that act as "building blocks" for folks to build Keyword Tests.  So... whatever works for you, if it works, then that's the "good" one to use.

     

    -I do want to follow object oriented concept  in scripting. How to organize global variables?

     

    I use ScriptExtensions to store my global variables for my framework.  That way, no matter what project I'm running, I always have the same variables available without having to edit my project file.  However, I'd go with Project Variables as probably a good way for storing global variables.  Another option is to create a code unit whose only purpose is to declare global variables and then reference that in all your other code units.

     

    -Alias names are big would like to store in variable and use that variables to refer objects. Is there way to put all alias mapped to variable in one single and refer it. 

     

    To quote someone else, if your Alias names are unwieldy and too long... you're doing it wrong.  Aliases are intended as a way to take the lengthy detailed namemapping tree and "compress" it into more usable constructions.  For example, an application may have an object like

     

    Sys.Process('myApp').form1.panel1.panel2.container2.textfield2

     

    Now, if you map that raw, it will show up as 

     

    NameMapping.Sys.myapp.form1.panel1.panel2.container2.textfield2

     

    With an Alias of

     

    Aliases.myapp.form1.panel1.panel2.container2.textfield2

     

    What I would do in this case is, in the Aliases panel, drag textfield2 to be a child of form1.  So, your alias looks like

     

    Aliases.myapp.form1.textfield2

     

    The hierarchy is preserved in the actual NameMapping but, for usability sake, the Alias is what you would reference in your code.

     

    -Is there any tutorial / training/ video to setup framework?

     

    What kind of framework? What model are you looking at? How are you going to drive your data? etc. etc. etc.  All sorts of ways to build a framework... again, what will work best for you?  There's a video that I helped produce back in October of last year that walks through how I built a framework that I was using... that framework may work for you... or it may not.   But I'd suggest watching that video as it may give you a good idea.

     

    -Mapping all objects Vs Find/FindChild method to identify objects. Which one is quickstart. 

     

    If you already are using Keyword tests, then you should already have mapping done.  Don't re-invent the wheel.  Quick start is to just edit your existing project and use the name mapping you already have in place.  Or, if you're going from scratch, I'd still suggest using NameMapping as your fastest start.  Writing the Find/FindChild code is going to take some work to build out all the code to do all the searching and finding... and you'll have to make sure that this code is called and accessible from all your code units where as NameMapping is ALWAYS available (no need to "export" or "import" or anything like that).  I personally use a hybrid... I map a good chunk of the "basic" application... and then I use various "find" methods to get to the objects that are dynamically built or are a bit trickier to map.

     

    As for your last question...

     

    https://support.smartbear.com/testcomplete/docs/index.html

     

    That's ALL the TestComplete documentation available, including a Language Reference section on Python.  I'd say start there.  There are built in tutorials on using TestComplete and doing other tasks (not one specifically for frameworks) but it's the best place I know to start.