Forum Discussion

Divya-tfw's avatar
Divya-tfw
New Contributor
8 years ago

Need support regarding scripting and running tests using python in TestComplete

Hi Team,

 

We have got a new project on testcomplete scripting using python language.But we dint find much blogs for our queries.

We are having following queries .Any help on the same would be grate:

1.How to identify dynamically changing object and how we can script for such scenarios.

2.Running script from cmd

3.How to run a specific list of test scripts based on runmode or tag names

4.How to send reports of execution via email

5.How to compare 2 excel sheets using python xlrd

6.We are facing lot of issues when working with desktop app any guidance on same

 

 

 

6 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Questions 1, 2, and 4 are not python script specific.  

     

    For 1, you're going to want to investigate using FindChild and FindAllChildren methods.  What you'll end up doing is starting with a static parent object (like a table or panel or form or some other container) and call one of those two methods to return the objects that you need for the next step of your scripts.

     

    For 2, check out the documentaiton on TestComplete Command Line as that will tell you how to run tests from any command prompt.

     

    For 4, check out the documentaiton on Sending Results via E-Mail

     

    For 3, I'm not sure what you mean by "runmode" or "tag names".  Perhaps these are Python terms I'm unfamiliar with.  Could you clarify?

     

    For 5, as I understand it, you should be able to import any third party package into TestComplete's scripts (so long as it's compatible with Python 3.4).  Check out the topic on Python - Specifics of Usage.

     

    For 6... well, can't help you with this one because it's WAAAAY to vague.  Please create an individual topic for each item that you're running into problems with.  Be sure to include as much information as possible concerning the application under test, the code and/or tests you've attempted, what errors or behavior you're experiencing, etc.  

  • For cases 2 and 4 (eh sorry I thought you meant python script from command line via TC):

     

    def TestBlah():
      #call python from command line
      execResult = WshShell.Exec("python \"C:\Python27\Scripts\calledfromtc.py\"")
      sout = execResult.StdOut.ReadAll()
      #log it
      Log.Message(sout)
      #send python output to myself as an e-mail
      emailWorked = SendMail("blah@yahoo.com", "mail.yahoo.com", "TC Python Result", "blah@yahoo.com", "Automated Test Result", sout)
      if emailWorked:
        Log.Message("email with results was sent")
      else:
        Log.Warning("unable to send email with results")

    Where calledfromtc.py has:

    print 'tc called this'

    ^Only 'gotcha' is that I think TC uses pre-compiled Python (pyd only the stuff they needed) so you may have to install Python from scratch to get to it from outside TC. Also check environmental variables.

     

    6. I have had two issues with Python in TC. In TC11 the performance was horrible, TC12 appears to have fixed this. The second issue is that when I hit a breakpoint in TC I cannot browse through Python list objects in the debug window. I remember seeing this elsewhere so I think it is a known issue.

  • Well, Thank you for the quick response tristaanogre, but we tried the same but it is failing for Desktop application. 

     

    For 1, As you said we need to investigate using FindChild and FindAllChildren methods. How do we navigate from child to parent in a desktop application? Could you please give some examples?

     

    For 3,  I'm not sure what you mean by "runmode" or "tag names".  Perhaps these are Python terms I'm unfamiliar with.  Could you clarify?:

                "runmode" or "tag names" is nothing but from excel. Crerate a column with name as "runmode" with data as 'Y' or 'N' below that, if you have 100 testcases and you need to run only 60 testcases and ignore 40, then you can use runmode, wherein you give 'Y' to run the testcase and 'N' to ignore the execution for the same.

     

    For 5, We weren't able to import the packages. Script fails and we get Python Runtime error and the line failing is for importing packages.

     

    For 6, We are facing lot of difficulties for automating a desktop application. Like:

     

     Identifying the objects, Comparing the excel files, running the script or suite from command prompt..

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      Well, let's break this down then:

       


      Rajesh2 wrote:

      Well, Thank you for the quick response tristaanogre, but we tried the same but it is failing for Desktop application. 

       

      For 1, As you said we need to investigate using FindChild and FindAllChildren methods. How do we navigate from child to parent in a desktop application? Could you please give some examples?

       

       


      The two topics I linked you to in the online help documentation gives examples of how to use those two methods to find child objects.  Have you tried using those examples as a starting point?  As to your question of "how do we navigate from child to parent in a desktop application"... I'm not sure I understand the question to begin with.  Any application, Web or Desktop, has a hierarchy of objects.  Sys is the parent object of everything.  Process is a method of Sys, that when passed a test string, will return the process object corresponding to the application. e.g., Sys.Process('iexplore') will give you the Windows Internet Explorer process.  If your application runs as 'myapp', than Sys.Process('myapp') is your application once it's running.  Forms, buttons, controls, etc., are all in a hierarchical tree of objects off your application.  A form is a child of the application, which itself has child objects of buttons, text fields, and labels.  And they, also, may have child objects depending upon how they are constructed.  FindChild and FindAllChildren give you the ability that, given any object, you can search the tree of child objects under that object to find a particular object or set of objects for you to work with.  I'm not sure if that counts as "navigating" but that's what this means.

       


      Rajesh2 wrote:

       

       

                  "runmode" or "tag names" is nothing but from excel. Crerate a column with name as "runmode" with data as 'Y' or 'N' below that, if you have 100 testcases and you need to run only 60 testcases and ignore 40, then you can use runmode, wherein you give 'Y' to run the testcase and 'N' to ignore the execution for the same.

       

       


      My confusion was in your assumption that "runmode" and "tag names" are universal concepts in TestComplete.  They are not.  Your description clarifies: they are columns in an excel spreadsheet that you wish to use to control test execution and flow.  To do so, the easiest way is using a DDT.ExcelDriver to read the data and process it, row by row.  Please read Using DDT Drivers.  It gives examples of how to do so.  What you are asking has to do with what you do with the data once you've obtained the driver and started running the loop.  Basically, in the loop, you'll employ if/then logic to check the "runmode" column.  If it contains a Y, do something and then go to the next row..  If it contains an N, skip everything and go to the next row.  Based upon something else you've posted, it seems you may already have a DDT driver running but it is not working well.  Could you copy and paste your code that you are executing? That may help us help you better.

       


      Rajesh2 wrote:

       

      For 5, We weren't able to import the packages. Script fails and we get Python Runtime error and the line failing is for importing packages.


      What error message are you getting? What does your code look like? What package are you trying to import?  Please post example code so that we can help you.  Suggestion: create different topics here on the forums for each question so we can track better the conversations.

       


      Rajesh2 wrote:

       

       

       Identifying the objects, Comparing the excel files, running the script or suite from command prompt..


      Concerning identifying objects, we need specifics.  What type of application are you testing? What language is it written in? What type of component are you working on? What have you tried already? What errors are you getting with what you tried? Different applications and implementations require different approaches.  There are some standard ways of doing things but, without knowing what you're working with, we are only guessing as to how to help you.

      As for comparing excel files, there's a great article and script extension for doing so.  See https://support.smartbear.com/viewarticle/42199/.

       

      As for running from the command prompt... I've already posted for you a link on the command line options for TestComplete/TestExecute.  Have you tried to implement them? If so, what happened? What errors? What worked/didn't work?  

       

      We're happy to help, obviously... but we need more information to be able to give you effective help.

      And, again, it would be better to create different topics here on the forums for each specific situation.  It will help you track the answer and will make things easier for us to help you AND will benefit others by making the specific topics categorized and searchable.

  •  

    John_Laird i tried executing the script which you had mentioned above. But once the execution is started its not stopping, not even forcefully. I was forced to stop TC from Task Manager.

     

    • John_Laird's avatar
      John_Laird
      Contributor

      Rajesh2

       

      Did TC log anything when you ran the script?

       

      That code sample also makes some assumptions:

      1. You have Python 2.7 installed. Be aware: TC uses a subset of Python 3. I just have Python 2 installed on my system because I want to access scripts written against Python 2.

      2. You have a windows PATH entry in your environmental variables pointed at the Python 2.7 folder.

      3. You have the sample python script being called in the 'Scripts' directory.

      4. Your network (consult IT) will not block the e-mail from being sent.

       

      ^If all of those conditions are met and it still does not work, let me know.

       

      To be clear, the code sample I posted was intended as a starting point, not something you just plug-in with no regard to how your system and network are set up and it works via magic.