Reputation: 197
I'm getting an error "module object is not callable" when trying to create a class with a reference: import LoginPage as loginPage. However, when I try to import just the class itself import LoginPage.LoginPage as loginPage I get a different error saying the module does not contain that object.
Im not sure if its the way I am creating the object through the reference with parenthesis. Is there another way to do this? I also had tried pageClassRef.LoginPage(), same error 'module' is not callable
import ....
import inspect
import LoginPage as loginPage
#Singleton class type
class Singleton(type):
def __init__(cls, name, bases, dic):
super(Singleton, cls).__init__(name, bases, dic)
cls.instance = None
def __call__(cls, *args, **kwargs):
if cls.instance is None:
cls.instance = super(Singleton, cls).__call__(*args, **kwargs)
return cls.instance
class NavTestSession(object):
# Config properties
__metaclass__ = Singleton
def __init__(self, configManager):
self.cfgManager = configManager
self.navTestEngine = NavTestEngine.Navigator(navVersion, resolution, scoreList)
def getConfigManager(self):
return self.cfgManager
def startNavigating(self):
return self.createPageObject(loginPage)
def createPageObject(self, pageClassRef):
# Create page factory method and validation
newPageObj = pageClassRef()
#print(newPageObj)
newPageObj.validatePage()
return newPageObj
def startNewSession(self):
loginPage = self.navTestEngine.launchAppFromMenu()
return loginPage
LoginPage.py
import NavPageObject
class LoginPage(NavPageObject):
# Image to validate the current page
PAGE_VALIDATION_IMAGE = "Views_SIGNIN.png"
# Images of objects on the current page
USERNAME_INPUT_FIELD_1 = "Input_USERNAME_1.png"
USERNAME_INPUT_FIELD_2 = "Input_USERNAME_2.png"
PASSWORD_INPUT_FIELD = "Input_PASSWORD.png"
def __init__(self):
super(LoginPage, self).__init__()
def validatePage(self):
if not self.navTestEngine.imageExists(self.PAGE_VALIDATION_IMAGE,
super().getCurrentRegion()):
raise FindFailed("Page Validation fail at %s" % __file__)
def typeUsername(self, username):
self.navTestEngine.clickWithRetry(USERNAME_INPUT_FIELD_1)
type("blahblah")
return self
def typePassword(self, password):
return self
def clickLogin(self):
return self
Upvotes: 0
Views: 896
Reputation: 192
i think the problems is that you trying to import LoginPage as loginPage. why don't you just type "from LoginPage import LoginPage as logingpage"
Upvotes: 1