# Path: wtframework/wtf/web/page.py
# class PageObject(object):
# 
#     """Base class for PageObjects.  The goal of PageObjects is to allow a logical 
#     encapsulation of page recognition, mapping of page elements, and exposing logical 
#     services provided by the page on a higher level for high level tests to consume.
# 
#     Basic Usage:
# 
#     #. define '_validate_page(webdriver)' method.  This method will check to make sure 
#        we are on the correct page.
#     #. define '__cmp__' method to allow page ranking when there are multiple matches 
#        to the same page to disambiguate which page should take precedence.
# 
#     """
#     __metaclass__ = abc.ABCMeta  # needed to make this an abstract class in Python 2.7
# 
#     # Webdriver associated with this instance of the PageObject
# 
#     __names_of_classes_we_already_took_screen_caps_of__ = {}
# 
#     def __init__(self, webdriver, *args, **kwargs):
#         """Constructor.  It's better to not call this directly, instead use PageFactory 
#         to instantiate PageObjects.
# 
#         Args: 
#             webdriver (Webdriver): Selenium Webdriver instance.
# 
#         """
#         try:
#             config_reader = kwargs['config_reader']
#         except KeyError:
#             config_reader = WTF_CONFIG_READER
# 
#         try:
#             self._validate_page(webdriver)
#         except TypeError as e:
#             _wtflog.error("PageObjects need to implement '_validate_page(self, webdriver)' method: %s", e)
#             raise e
#         except Exception as e:
#             _wtflog.debug("Unable to instantiate page: %s", e)
#             raise e
# 
#         # Assign webdriver to PageObject.
#         # Each page object has an instance of "webdriver" referencing the webdriver
#         # driving this page.
#         self.webdriver = webdriver
# 
#         # Take reference screenshots if this option is enabled.
#         if config_reader.get("selenium.take_reference_screenshot", False) == True:
#             class_name = type(self).__name__
#             if class_name in PageObject.__names_of_classes_we_already_took_screen_caps_of__:
#                 pass
#             else:
#                 try:
#                     WebScreenShotUtil.take_reference_screenshot(
#                         webdriver, class_name)
#                     PageObject.__names_of_classes_we_already_took_screen_caps_of__[
#                         class_name] = True
#                 except Exception as e:
#                     # Some WebDrivers such as head-less drivers does not take
#                     # screenshots.
#                     _wtflog.error(e)
#         else:
#             pass
# 
#     @abc.abstractmethod
#     def _validate_page(self, webdriver):
#         """Perform checks to validate this page is the correct target page.
# 
#         All PageObjects must implement this method.
# 
#         Args:
#             webdriver (Webdriver) : instance of Selenium Webdriver
#         Raises:
#             InvalidPageError: Raised when we try to assign the wrong page 
#             to this page object.  This exception should be raised when a page match 
#             fails.  Any other exception type would be consider a code failure.
# 
#         """
#         return
# 
#     @classmethod
#     def create_page(cls, webdriver=None, **kwargs):
#         """Class method short cut to call PageFactory on itself.  Use it to instantiate 
#         this PageObject using a webdriver.
# 
#         Args:
#             webdriver (Webdriver): Instance of Selenium Webdriver.
# 
#         Returns:
#             PageObject
# 
#         Raises:
#             InvalidPageError
# 
#         """
#         if not webdriver:
#             webdriver = WTF_WEBDRIVER_MANAGER.get_driver()
#         return PageFactory.create_page(cls, webdriver=webdriver, **kwargs)
# 
#     # Magic methods for enabling comparisons.
#     def __cmp__(self, other):
#         """Override this to implement PageObject ranking.  This is used by PageObjectFactory
#         when it finds multiple pages that qualify to map to the current page.  The 
#         PageObjectFactory will check which page object is preferable.
# 
#         Args:
#             other (PageObject) : Other page object to compare it against.
# 
#         Returns:
#             int ::
#                 postive number - this page is prioritized over the other page.
#                 negative number - this page is lower in priority than the other page.
# 
#         """
#         if not isinstance(other, PageObject):
#             # By default page object will rank itself over non page objects.
#             return 1
#         else:
#             return 0
# 
# class InvalidPageError(Exception):
#     '''Thrown when we have tried to instantiate the incorrect page to a PageObject.'''
#     pass
# 
# Path: tests/pages/search_page.py
# class ISearchPage(object):
# 
#     """
#     Example of how you can use a an interface to create a higher level 
#     abstraction that can be used by PageFactory.
#     """
#     __metaclass__ = abc.ABCMeta
# 
#     @abc.abstractmethod
#     def search(self, search_string):
#         "Submit a search"
#         pass
# 
#     @abc.abstractmethod
#     def result_contains(self):
#         "Submit a search"
#         pass


from wtframework.wtf.web.page import PageObject, InvalidPageError
from tests.pages.search_page import ISearchPage




class YahooSearchPage(PageObject, ISearchPage):

    "Simple PageObject class"

    # Object Mappings for fields on this page. #
    # Note the 'self.webdriver', this is because PageObjects keep track
    # of their own webdriver that's driving the page.
    search_field = lambda self: self.webdriver.find_element_by_name('p')
    submit_button = lambda self: self.webdriver.find_eleent_by_id(
        'search-submit')

    # Page objects all override the _validate_page() method so pages
    # can self validate upon creation.
    def _validate_page(self, webdriver):

# Path: wtframework/wtf/web/page.py
# class PageObject(object):
# 
#     """Base class for PageObjects.  The goal of PageObjects is to allow a logical 
#     encapsulation of page recognition, mapping of page elements, and exposing logical 
#     services provided by the page on a higher level for high level tests to consume.
# 
#     Basic Usage:
# 
#     #. define '_validate_page(webdriver)' method.  This method will check to make sure 
#        we are on the correct page.
#     #. define '__cmp__' method to allow page ranking when there are multiple matches 
#        to the same page to disambiguate which page should take precedence.
# 
#     """
#     __metaclass__ = abc.ABCMeta  # needed to make this an abstract class in Python 2.7
# 
#     # Webdriver associated with this instance of the PageObject
# 
#     __names_of_classes_we_already_took_screen_caps_of__ = {}
# 
#     def __init__(self, webdriver, *args, **kwargs):
#         """Constructor.  It's better to not call this directly, instead use PageFactory 
#         to instantiate PageObjects.
# 
#         Args: 
#             webdriver (Webdriver): Selenium Webdriver instance.
# 
#         """
#         try:
#             config_reader = kwargs['config_reader']
#         except KeyError:
#             config_reader = WTF_CONFIG_READER
# 
#         try:
#             self._validate_page(webdriver)
#         except TypeError as e:
#             _wtflog.error("PageObjects need to implement '_validate_page(self, webdriver)' method: %s", e)
#             raise e
#         except Exception as e:
#             _wtflog.debug("Unable to instantiate page: %s", e)
#             raise e
# 
#         # Assign webdriver to PageObject.
#         # Each page object has an instance of "webdriver" referencing the webdriver
#         # driving this page.
#         self.webdriver = webdriver
# 
#         # Take reference screenshots if this option is enabled.
#         if config_reader.get("selenium.take_reference_screenshot", False) == True:
#             class_name = type(self).__name__
#             if class_name in PageObject.__names_of_classes_we_already_took_screen_caps_of__:
#                 pass
#             else:
#                 try:
#                     WebScreenShotUtil.take_reference_screenshot(
#                         webdriver, class_name)
#                     PageObject.__names_of_classes_we_already_took_screen_caps_of__[
#                         class_name] = True
#                 except Exception as e:
#                     # Some WebDrivers such as head-less drivers does not take
#                     # screenshots.
#                     _wtflog.error(e)
#         else:
#             pass
# 
#     @abc.abstractmethod
#     def _validate_page(self, webdriver):
#         """Perform checks to validate this page is the correct target page.
# 
#         All PageObjects must implement this method.
# 
#         Args:
#             webdriver (Webdriver) : instance of Selenium Webdriver
#         Raises:
#             InvalidPageError: Raised when we try to assign the wrong page 
#             to this page object.  This exception should be raised when a page match 
#             fails.  Any other exception type would be consider a code failure.
# 
#         """
#         return
# 
#     @classmethod
#     def create_page(cls, webdriver=None, **kwargs):
#         """Class method short cut to call PageFactory on itself.  Use it to instantiate 
#         this PageObject using a webdriver.
# 
#         Args:
#             webdriver (Webdriver): Instance of Selenium Webdriver.
# 
#         Returns:
#             PageObject
# 
#         Raises:
#             InvalidPageError
# 
#         """
#         if not webdriver:
#             webdriver = WTF_WEBDRIVER_MANAGER.get_driver()
#         return PageFactory.create_page(cls, webdriver=webdriver, **kwargs)
# 
#     # Magic methods for enabling comparisons.
#     def __cmp__(self, other):
#         """Override this to implement PageObject ranking.  This is used by PageObjectFactory
#         when it finds multiple pages that qualify to map to the current page.  The 
#         PageObjectFactory will check which page object is preferable.
# 
#         Args:
#             other (PageObject) : Other page object to compare it against.
# 
#         Returns:
#             int ::
#                 postive number - this page is prioritized over the other page.
#                 negative number - this page is lower in priority than the other page.
# 
#         """
#         if not isinstance(other, PageObject):
#             # By default page object will rank itself over non page objects.
#             return 1
#         else:
#             return 0
# 
# class InvalidPageError(Exception):
#     '''Thrown when we have tried to instantiate the incorrect page to a PageObject.'''
#     pass
# 
# Path: tests/pages/search_page.py
# class ISearchPage(object):
# 
#     """
#     Example of how you can use a an interface to create a higher level 
#     abstraction that can be used by PageFactory.
#     """
#     __metaclass__ = abc.ABCMeta
# 
#     @abc.abstractmethod
#     def search(self, search_string):
#         "Submit a search"
#         pass
# 
#     @abc.abstractmethod
#     def result_contains(self):
#         "Submit a search"
#         pass


# Path: tests/pages/www_yahoo_com.py
from wtframework.wtf.web.page import PageObject, InvalidPageError
from tests.pages.search_page import ISearchPage





class YahooSearchPage(PageObject, ISearchPage):

    "Simple PageObject class"

    # Object Mappings for fields on this page. #
    # Note the 'self.webdriver', this is because PageObjects keep track
    # of their own webdriver that's driving the page.
    search_field = lambda self: self.webdriver.find_element_by_name('p')
    submit_button = lambda self: self.webdriver.find_eleent_by_id(
        'search-submit')

    # Page objects all override the _validate_page() method so pages
    # can self validate upon creation.
    def _validate_page(self, webdriver):

        "Check to make sure we're on google.com"