Ask a Question

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

SOLVED
harmatii
Occasional Contributor

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)?

 

6 REPLIES 6
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
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
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.  


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
harmatii
Occasional Contributor

So basically there is no such a way to implement standard POM in here, and the best way to store objects is the Name Mapping?

tristaanogre
Esteemed Contributor

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.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

Hi,

 

the best way to store objects is the Name Mapping?

As Robert wrote.

But not NameMapping but Aliases. Aliases, actually, is a far more handy and functional analogue of POM in TestComplete.

One more note:

When you are using POM in Selenium, you are instantiating POM class on the given page/form test start and dispose it of when the page/form is closed/navigated away.

Aliased object in TestComplete is not disposed of after it is assigned to a variable but is cached and TestComplete tries to re-use it later. This will result in the 'Object not found error' (analogue of the Stalled Object Reference exception in Selenium) if some object has been recreated after the first use. .RefreshMappingInfo() method solves this problem, but it is expensive and must be used only when really unavoidable.

To sum up: pure classical POM is not a recommended way of test code development in TestComplete's world in favor of properly crafted Aliases tree. (And, quite probably, dynamic search via .FindXXX() methods that use some Aliased object as a search root. And such dynamic search well may be implemented as a set of POM-like functions.)

 

Regards,
  /Alex [Community Champion]
____
[Community Champions] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Champions]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Champion] signature is assigned on quarterly basis and is used with permission by SmartBear Software.
https://community.smartbear.com/t5/Community-Champions/About-the-Community-Champions-Program/gpm-p/252662
================================
cancel
Showing results for 
Search instead for 
Did you mean: