# Path: page_objects/hamburger_menu_object.py
# class Hamburger_Menu_Object:
#     "Page Object for the hamburger menu"
# 
#     #locators
#     menu_icon = locators.menu_icon
#     menu_link = locators.menu_link
#     menu_item = locators.menu_item
# 
#     @Wrapit._exceptionHandler
#     def goto_menu_link(self,my_link,expected_url_string=None):
#         "Navigate to a link: Hover + Click or just Click"
#         #Format for link: string separated by '>'
#         #E.g.: 'Approach > Where we start'
#         split_link = my_link.split('>')
#         hover_list = split_link[:-1]
#         self.click_hamburger_menu()
#         for element in hover_list:
#             self.hover(self.menu_item%element.strip())
#         result_flag = self.click_element(self.menu_link%split_link[-1].strip())
# 
#         #Additional check to see if we went to the right page
#         if expected_url_string is not None:
#             result_flag &= True if expected_url_string in self.get_current_url() else False
# 
#         #If the action failed, close the Hamburger menu
#         if result_flag is False:
#             self.click_hamburger_menu()
# 
#         return result_flag
# 
# 
#     def click_hamburger_menu(self):
#         "Click on the hamburger menu icon"
#         return self.click_element(self.menu_icon)
# 
# Path: utils/Wrapit.py
# class Wrapit():
# 
#     "Wrapit class to hold decorator functions"
#     def _exceptionHandler(f):
#         "Decorator to handle exceptions"
#         def inner(*args,**kwargs):
#             try:
#                 return f(*args,**kwargs)
#             except Exception as e:
#                 args[0].write('You have this exception')
#                 args[0].write('Exception in method: %s'%str(f.__name__))
#                 args[0].write('PYTHON SAYS: %s'%str(e))
#                 #we denote None as failure case
#                 return None
# 
#         return inner
# 
# 
#     def _screenshot(func):
#         "Decorator for taking screenshots"
#         #Usage: Make this the first decorator to a method (right above the 'def function_name' line)
#         #Otherwise, we cannot name the screenshot with the name of the function that called it
#         def wrapper(*args,**kwargs):
#             result = func(*args,**kwargs)
#             screenshot_name = '%003d'%args[0].screenshot_counter + '_' + func.__name__
#             args[0].screenshot_counter += 1
#             args[0].save_screenshot(screenshot_name)
# 
#             return result
# 
#         return wrapper
# 
# 
#     def _check_browser_console_log(func):
#         "Decorator to check the browser's console log for errors"
#         def wrapper(*args,**kwargs):
#             #As IE driver does not support retrieval of any logs,
#             #we are bypassing the read_browser_console_log() method
#             result = func(*args, **kwargs)
#             if "ie" not in str(args[0].driver):
#                 result = func(*args, **kwargs)
#                 log_errors = []
#                 new_errors = []
#                 log = args[0].read_browser_console_log()
#                 if log != None:
#                     for entry in log:
#                         if entry['level']=='SEVERE':
#                             log_errors.append(entry['message'])
# 
#                     if args[0].current_console_log_errors != log_errors:
#                         #Find the difference
#                         new_errors = list(set(log_errors) - set(args[0].current_console_log_errors))
#                         #Set current_console_log_errors = log_errors
#                         args[0].current_console_log_errors = log_errors
# 
#                     if len(new_errors)>0:
#                         args[0].failure("\nBrowser console error on url: %s\nMethod: %s\nConsole error(s):%s"%(args[0].get_current_url(),func.__name__,'\n----'.join(new_errors)))
# 
#             return result
# 
#         return wrapper
# 
# 
#     _exceptionHandler = staticmethod(_exceptionHandler)
#     _screenshot = staticmethod(_screenshot)
#     _check_browser_console_log = staticmethod(_check_browser_console_log)


from .hamburger_menu_object import Hamburger_Menu_Object
from utils.Wrapit import Wrapit
import conf.locators_conf as locators
"""
This class models the Qxf2.com header as a Page Object.
The header consists of the Qxf2 logo, Qxf2 tag-line and the hamburger menu
Since the hanburger menu is complex, we will model it as a separate object
"""



class Header_Object(Hamburger_Menu_Object):
    "Page Object for the header class"

    #locators
    qxf2_logo = locators.qxf2_logo
    qxf2_tagline_part1 = locators.qxf2_tagline_part1
    qxf2_tagline_part2 = locators.qxf2_tagline_part2


# Path: page_objects/hamburger_menu_object.py
# class Hamburger_Menu_Object:
#     "Page Object for the hamburger menu"
# 
#     #locators
#     menu_icon = locators.menu_icon
#     menu_link = locators.menu_link
#     menu_item = locators.menu_item
# 
#     @Wrapit._exceptionHandler
#     def goto_menu_link(self,my_link,expected_url_string=None):
#         "Navigate to a link: Hover + Click or just Click"
#         #Format for link: string separated by '>'
#         #E.g.: 'Approach > Where we start'
#         split_link = my_link.split('>')
#         hover_list = split_link[:-1]
#         self.click_hamburger_menu()
#         for element in hover_list:
#             self.hover(self.menu_item%element.strip())
#         result_flag = self.click_element(self.menu_link%split_link[-1].strip())
# 
#         #Additional check to see if we went to the right page
#         if expected_url_string is not None:
#             result_flag &= True if expected_url_string in self.get_current_url() else False
# 
#         #If the action failed, close the Hamburger menu
#         if result_flag is False:
#             self.click_hamburger_menu()
# 
#         return result_flag
# 
# 
#     def click_hamburger_menu(self):
#         "Click on the hamburger menu icon"
#         return self.click_element(self.menu_icon)
# 
# Path: utils/Wrapit.py
# class Wrapit():
# 
#     "Wrapit class to hold decorator functions"
#     def _exceptionHandler(f):
#         "Decorator to handle exceptions"
#         def inner(*args,**kwargs):
#             try:
#                 return f(*args,**kwargs)
#             except Exception as e:
#                 args[0].write('You have this exception')
#                 args[0].write('Exception in method: %s'%str(f.__name__))
#                 args[0].write('PYTHON SAYS: %s'%str(e))
#                 #we denote None as failure case
#                 return None
# 
#         return inner
# 
# 
#     def _screenshot(func):
#         "Decorator for taking screenshots"
#         #Usage: Make this the first decorator to a method (right above the 'def function_name' line)
#         #Otherwise, we cannot name the screenshot with the name of the function that called it
#         def wrapper(*args,**kwargs):
#             result = func(*args,**kwargs)
#             screenshot_name = '%003d'%args[0].screenshot_counter + '_' + func.__name__
#             args[0].screenshot_counter += 1
#             args[0].save_screenshot(screenshot_name)
# 
#             return result
# 
#         return wrapper
# 
# 
#     def _check_browser_console_log(func):
#         "Decorator to check the browser's console log for errors"
#         def wrapper(*args,**kwargs):
#             #As IE driver does not support retrieval of any logs,
#             #we are bypassing the read_browser_console_log() method
#             result = func(*args, **kwargs)
#             if "ie" not in str(args[0].driver):
#                 result = func(*args, **kwargs)
#                 log_errors = []
#                 new_errors = []
#                 log = args[0].read_browser_console_log()
#                 if log != None:
#                     for entry in log:
#                         if entry['level']=='SEVERE':
#                             log_errors.append(entry['message'])
# 
#                     if args[0].current_console_log_errors != log_errors:
#                         #Find the difference
#                         new_errors = list(set(log_errors) - set(args[0].current_console_log_errors))
#                         #Set current_console_log_errors = log_errors
#                         args[0].current_console_log_errors = log_errors
# 
#                     if len(new_errors)>0:
#                         args[0].failure("\nBrowser console error on url: %s\nMethod: %s\nConsole error(s):%s"%(args[0].get_current_url(),func.__name__,'\n----'.join(new_errors)))
# 
#             return result
# 
#         return wrapper
# 
# 
#     _exceptionHandler = staticmethod(_exceptionHandler)
#     _screenshot = staticmethod(_screenshot)
#     _check_browser_console_log = staticmethod(_check_browser_console_log)


# Path: page_objects/header_object.py
from .hamburger_menu_object import Hamburger_Menu_Object
from utils.Wrapit import Wrapit
import conf.locators_conf as locators

"""
This class models the Qxf2.com header as a Page Object.
The header consists of the Qxf2 logo, Qxf2 tag-line and the hamburger menu
Since the hanburger menu is complex, we will model it as a separate object
"""



class Header_Object(Hamburger_Menu_Object):
    "Page Object for the header class"

    #locators
    qxf2_logo = locators.qxf2_logo
    qxf2_tagline_part1 = locators.qxf2_tagline_part1
    qxf2_tagline_part2 = locators.qxf2_tagline_part2


    @Wrapit._exceptionHandler