I've built a module to hold all of the common selenium expected_conditions which are then referenced throughout various tests. (The selenium portion of this example is not important, just the fact that I have a 'catalog' of a few thousand items.)
# ec module
class EcHR(object):
class sidemenu(object):
hrfile: Clickable = Clickable((By.ID, "sidemenu_HRFile"), f"HR File")
hrvistainfo: Clickable = Clickable((By.ID, "sidemenu_HRVistA Info"), f"HR VistA Info")
class hrfile(__hr_search__):
class actionmenu(__hr_search__.actionmenu):
add: Clickable = Clickable((By.ID, "NewHireLink"), f"Add {BUTTON}")
personnel: Clickable = Clickable((By.ID, 'setEmpType'), f"Personnel Filter {DROPDOWN}")
status: Clickable = Clickable((By.ID, 'setStatus'), f"Status {DROPDOWN}")
configure: Clickable = Clickable((By.ID, "configureLinkGen"), f"Configure {BUTTON}")
reports: Clickable = Clickable((By.ID, 'Reports'), f"Reports {BUTTON}")
class addmenu(object):
employee: Clickable = Clickable((By.ID, f'Employee'), f"Add->Employee {BUTTON}")
Sample reference to a given item in the ec module.
import ec
# navigation helper method for a given page
def do_hrfile_nav(self):
self.clickbutton(ec.EcHR.sidemenu.hrfile)
This works great; I can trace the usage of each object while still providing readability context for what the object is.
self.clickbutton(ec.EcHR.sidemenu.hrfile)
tells the reader we are clicking on the sidemenu item hrfile
on the HR
page. This is important to distinguish from the ec.EcHR.hrfile
which is a different set of objects.
My question: Is there a better/cleaner way to organize these objects? I'm using classes that never get instantiated. (which somehow feels awkward for reasons I can't articulate) These classes act solely as a means to reference them in an organized way. Perhaps some sort of lightweight data object that has class-like structure? (am I over thinking things?)