Forum Discussion

shenyusun's avatar
shenyusun
Contributor
9 years ago
Solved

Any examples of using python to build your own class and add into test case?

Hello beautiful people,

 

Hope my question make sense here...

 

I've been using python to build a lot of test cases.

I separated all my scripts into different categories, and import them when I need them.

This is sort of like import 'class', but instead of 'class', I import script that contains a lot of test cases.

 

Have any of you guys build your own python class and add the class into your testcomplete script?

 

 

  • Not python, but I use classes in a framework that I built.  Basically, for any given test scenario, there are a sequence of steps. Each step has an action and a set of parameters that inform that action.  I translate that into that I have a class for each test step. The class has properties that are the parameters needed to execute the step and validate the result. The class also has an "Execute" method which uses those properties to execute a bit of script code to perform the action.  Effectively, I have as many classes as I have distinct test step configurations.

     

    I then build an array of objects based upon these classes for the test scenario and then iterate through that array, calling the "Execute" method on each class.  

    Just one example... YMMV but I've seen a number of framework models that use something similar.  The tutorials for Selenium kind of walk through something similar.

  • baxatob's avatar
    baxatob
    Community Hero

    Yes, you can build your own class and then import it like you do it in other IDEs:

     

    unit1
    
    class YourClass:
        pass
    
    
    unit2
    
    from unit1 import YourClass
  • NisHera's avatar
    NisHera
    Valued Contributor

    Your question make sense ...

    But examples you would like depends on what you are going to do with it.

     

    Currently I'm developing test suite to test some Rest API's using python

    There in my base common classes, written skeleton to authorize and calling

    API methods…

     

    So if you specific on your requirement would be easy to reply

    • shenyusun's avatar
      shenyusun
      Contributor

      Thank you for the response NisHera.

       

      My requirements would be something like:

       

      1. Make sure the button can be clicked, and has correct response.

      2. Verify the edit box has the correct behavior with valid input and invalid input.

       

      I guess those doesn't require a class, it's just a simple test cases.

       

      I am trying to get familiar with how class works, and if I can find a way to use that while using Test Complete, I think it'll help me.

      I read tutorials, and articles of how to build a class, but I just don't know how to use it in my project.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Not python, but I use classes in a framework that I built.  Basically, for any given test scenario, there are a sequence of steps. Each step has an action and a set of parameters that inform that action.  I translate that into that I have a class for each test step. The class has properties that are the parameters needed to execute the step and validate the result. The class also has an "Execute" method which uses those properties to execute a bit of script code to perform the action.  Effectively, I have as many classes as I have distinct test step configurations.

         

        I then build an array of objects based upon these classes for the test scenario and then iterate through that array, calling the "Execute" method on each class.  

        Just one example... YMMV but I've seen a number of framework models that use something similar.  The tutorials for Selenium kind of walk through something similar.

  • Thank you guys! I think that I got a basic idea how to use class in test complete automation. Thank you guys for sharing the knowledage!!