Forum Discussion

dkasirajan's avatar
dkasirajan
Contributor
7 years ago

Using findchild method in global variable file - test fails. please give me examples using classes

We are using Python script  and I have used Findchild method in function- to find objects. 

So I have duplicate code in each function for every test case.

But i would like to do with using python class.

Can you please give me example how to use Python classes and calling them in test complete.

I am learning python separately. but i am not able to use it in testcomplete environment.

We are using desktop application.

 - please help me how to organize  find child method .

-I would like to create object file for each page - where all the objects of that page is identified  and will be used in projects.

while running my test - it tries to find objects which will be created when loading that page and test fails.

 

Thanks,

Devaki

2 Replies

  • karkadil's avatar
    karkadil
    Valued Contributor

    The simple answer to you question looks like this (it works in TestComplete 11):

    class MyClass():
      def __init__(self):
        Log.Message('An object of the class is created')
      def print(self, message):
        Log.Message(message)
        
    def test_my_class():
      my_obj = MyClass()
      my_obj.print('my message')
      

    As for your second question, there is no simple answer, you have to learn Python good enough to build your own class-based framework

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    Try to get started with these answers and then tell us where you get stuck.  You have a lot of different questions here so, giving us details about where you have a problem will help us help you.

     

     

    Can you please give me example how to use Python classes and calling them in test complete.

    There are lots of good Python references here:

    https://support.smartbear.com/testcomplete/docs/reference/language/python/index.html

     

     

    I would like to create object file for each page - where all the objects of that page is identified  and will be used in projects.

    That would be NameMapping

    https://support.smartbear.com/testcomplete/docs/testing-with/object-identification/name-mapping/overview.html

     

     please help me how to organize  find child method 

    With FindChild, you don't usually have to have a full list of every object like you've asked for above.  You can have a high level mapping and then use FindChild for lower level objects.