Forum Discussion

harmatii's avatar
harmatii
Occasional Contributor
4 years ago
Solved

Having issues with implementing Page Object Model in TestComplete using Python language

Using TestComplete with Python to automate Desktop project and trying to implement Page Object Model. Have 2 files:

 

#first file which contains test

Test001:

 

import ExcelObjects

 

def Test001():

  #create object of Excel page class
  eo = ExcelObjects()
  #Runs the "EXCEL" tested application.
  TestedApps.EXCEL.Run(1, True)
  #Maximize window
  Sys.Process("EXCEL").Form("Excel").Maximize()
  #Selects the 'Blank workbook' item of the 'list' select control.
  eo.blank_workbook.Click()

 

 

#second file with Page Object which will contain all the locators, methods etc. related to Excel page

ExcelObjects

 

class ExcelObjects:
  blank_workbook = Aliases.EXCEL.wndXLMAIN.FullpageUIHost.ListItem("Blank workbook")

 

And when I run my test it gives me an error: "the object "list" does not exist"

so basically it tries to find this object "blank_workbook = Aliases.EXCEL.wndXLMAIN.FullpageUIHost.ListItem("Blank workbook")" even before it runs TestedApp. any thoughts why it calls that object on the beginning but not at the time where it placed (last step of the test)?

 

  • You CAN do a POM, but the code is going to probably be more complicated than you want.  NameMapping is what is basically the replacement for POM in Silenium.  All your main actions (click, keys, etc) are on the Alias objects themselves so you don't need, really, to create classes for each of the different objects.  You just need to use NameMapping or one of those other methods that I suggested for building your objects.

6 Replies

  • Wamboo's avatar
    Wamboo
    Community Hero

    Yo,

    It comes because you're trying to use an object that's probably not available to you.

     

    Run it on the debugger and see if these items do not load at the very beginning of the test. If so, change the call to a function and then refer to it in the file.

     

    Change this into function.

    blank_workbook = Aliases.EXCEL.wndXLMAIN.FullpageUIHost.ListItem("Blank workbook")

     

    If You are sure that this obj exist while running test. Use WaitChild function of Your's specific object.

    • harmatii's avatar
      harmatii
      Occasional Contributor

      Yo,

      It comes because you're trying to use an object that's probably not available to you.

       

      Yes, because it tries to find that object before it opens the app.

       

      It worked after I changed that to a function. But is that possible to have as class attribute not a function?

      Because I'd like to have all locators as an attributes in separate class and then use them in my tests and perform some actions on them (ex: Click(), SetText ..)?

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        You can't set UI objects in classes ahead of time.  NameMapping/TestComplete uses a model that you can assign the Alias.blahblahblah to a variable before the object exists... and that variable will contain the object AT THE TIME THAT IT WAS ASSIGNED... so, if the object doesn't exist in the initialization/instantiation of the object, it won't be seen as "existing" when you try and use the property.  UI components need to be assigned or refreshed during execution so that they are found in real-time.  

        You can do some of this if you use WaitChild or WaitAliasChild or FindChild or similar methods to assign the UI object to your class.