def __init__(self, by, value, parent=None, page_element_class=None, order=None): """Initialize the PageElements object with the given locator components. If parent is not None, find_elements will be performed over it, instead of using the driver's method, so it can find nested elements. :param by: locator type :param value: locator value :param parent: parent element (WebElement, PageElement or locator tuple) :param order: index value if the locator returns more than one element :param page_element_class: class of page elements (PageElement, Button...) :param shadowroot: CSS SELECTOR of JS element where shadowroot tag appears """ super(PageElements, self).__init__() self.locator = (by, value ) #: tuple with locator type and locator value self.parent = parent #: element from which to find actual elements self.order = order #: index value if the locator returns more than one element self.shadowroot = None #: Not implemented for PageElements yet self.driver_wrapper = DriverWrappersPool.get_default_wrapper( ) #: driver wrapper instance # update instance element class or use PageElement class if page_element_class: self.page_element_class = page_element_class self._page_elements = [] self.reset_object(self.driver_wrapper)
def __new__(cls, driver_wrapper=None): """Instantiate android or ios page object from base page object depending on driver configuration Base, Android and iOS page objects must be defined with following structure: FOLDER/base/MODULE_NAME.py class BasePAGE_OBJECT_NAME(MobilePageObject) FOLDER/android/MODULE_NAME.py class AndroidPAGE_OBJECT_NAME(BasePAGE_OBJECT_NAME) FOLDER/ios/MODULE_NAME.py class IosPAGE_OBJECT_NAME(BasePAGE_OBJECT_NAME) :param driver_wrapper: driver wrapper instance :returns: android or ios page object instance """ if cls.__name__.startswith('Base'): __driver_wrapper = driver_wrapper if driver_wrapper else DriverWrappersPool.get_default_wrapper( ) __os_name = 'ios' if __driver_wrapper.is_ios_test() else 'android' __class_name = cls.__name__.replace('Base', __os_name.capitalize()) try: return getattr(importlib.import_module(cls.__module__), __class_name)(__driver_wrapper) except AttributeError: __module_name = cls.__module__.replace( '.base.', '.{}.'.format(__os_name)) return getattr(importlib.import_module(__module_name), __class_name)(__driver_wrapper) else: return super(MobilePageObject, cls).__new__(cls)
def __init__(self, by, value, parent=None, driver_wrapper=None, order=None): """Initialize the Group object with the given locator components. If parent is not None, find_elements will be performed over it, instead of using the driver's method, so it can find nested elements. :param by: locator type :param value: locator value :param parent: parent element (WebElement, PageElement or locator tuple) :param order: index value if the locator returns more than one element :param driver_wrapper: driver wrapper instance """ self.logger = logging.getLogger(__name__) #: logger instance self.locator = (by, value ) #: tuple with locator type and locator value self.parent = parent #: element from which to find actual elements self.order = order #: index value if the locator returns more than one element self.driver_wrapper = driver_wrapper if driver_wrapper else \ DriverWrappersPool.get_default_wrapper() #: driver wrapper instance self.init_page_elements() self.reset_object(self.driver_wrapper)
def setUp(self): # Remove previous visual path visual_path = os.path.join(self.root_path, 'output', 'visualtests') if os.path.exists(visual_path): shutil.rmtree(visual_path) # Reset wrappers pool values DriverWrappersPool._empty_pool() DriverWrapper.config_properties_filenames = None # Create a new wrapper self.driver_wrapper = DriverWrappersPool.get_default_wrapper() self.driver_wrapper.driver = mock.MagicMock() # Configure properties config_files = ConfigFiles() config_files.set_config_directory(os.path.join(self.root_path, 'conf')) config_files.set_config_properties_filenames('properties.cfg') config_files.set_output_directory( os.path.join(self.root_path, 'output')) self.driver_wrapper.configure(tc_config_files=config_files) self.driver_wrapper.config.set('VisualTests', 'enabled', 'true') # Create a new VisualTest instance self.visual = VisualTest(self.driver_wrapper)
def bdd_common_before_scenario(context_or_world, scenario): """Common scenario initialization in behave or lettuce :param context_or_world: behave context or lettuce world :param scenario: running scenario """ # Initialize and connect driver wrapper if not DriverWrappersPool.get_default_wrapper().driver: create_and_configure_wrapper(context_or_world) connect_wrapper(context_or_world) # Add assert screenshot methods with scenario configuration add_assert_screenshot_methods(context_or_world, scenario) # Configure Jira properties save_jira_conf() # Add implicitly wait implicitly_wait = context_or_world.toolium_config.get_optional( 'Driver', 'implicitly_wait') if context_or_world.driver and implicitly_wait: context_or_world.driver.implicitly_wait(implicitly_wait) context_or_world.logger.info("Running new scenario: {0}".format( scenario.name))
def __init__(self, by, value, parent=None, driver_wrapper=None, order=None, wait=False, webview=False, webview_context_selection_callback=None, webview_csc_args=None): """Initialize the Group object with the given locator components. If parent is not None, find_elements will be performed over it, instead of using the driver's method, so it can find nested elements. :param by: locator type :param value: locator value :param parent: parent element (WebElement, PageElement or locator tuple) :param driver_wrapper: driver wrapper instance :param order: index value if the locator returns more than one element :param wait: True if the page element must be loaded in wait_until_loaded method of the container page object :param shadowroot: CSS SELECTOR of JS element where shadowroot tag appears :param webview: True if the element is in a mobile webiew :param webview_context_selection_callback: method provided to select the desired webview context if automatic_context_selection is enabled. Must return a tuple (context, window_handle) for android, and a context for ios :param webview_csc_args: arguments list for webview_context_selection_callback """ self.logger = logging.getLogger(__name__) #: logger instance self.locator = (by, value) #: tuple with locator type and locator value self.parent = parent #: element from which to find actual elements self.order = order #: index value if the locator returns more than one element self.wait = wait #: True if it must be loaded in wait_until_loaded method of the container page object self.webview = webview #: True if element is in a mobile webview self.webview_context_selection_callback = webview_context_selection_callback #: callback for selection of the # webview context with automatic_context_selection self.webview_csc_args = webview_csc_args #: arguments list for the context selection callback method self.shadowroot = None #: Not implemented for Group yet self.driver_wrapper = driver_wrapper if driver_wrapper else \ DriverWrappersPool.get_default_wrapper() #: driver wrapper instance self.init_page_elements() self.reset_object(self.driver_wrapper)
def __new__(cls, driver_wrapper=None): """Instantiate android or ios page object from base page object depending on driver configuration Base, Android and iOS page objects must be defined with following structure: FOLDER/base/MODULE_NAME.py class BasePAGE_OBJECT_NAME(MobilePageObject) FOLDER/android/MODULE_NAME.py class AndroidPAGE_OBJECT_NAME(BasePAGE_OBJECT_NAME) FOLDER/ios/MODULE_NAME.py class IosPAGE_OBJECT_NAME(BasePAGE_OBJECT_NAME) :param driver_wrapper: driver wrapper instance :returns: android or ios page object instance """ if cls.__name__.startswith('Base'): __driver_wrapper = driver_wrapper if driver_wrapper else DriverWrappersPool.get_default_wrapper() __os_name = 'ios' if __driver_wrapper.is_ios_test() else 'android' __class_name = cls.__name__.replace('Base', __os_name.capitalize()) try: return getattr(importlib.import_module(cls.__module__), __class_name)(__driver_wrapper) except AttributeError: __module_name = cls.__module__.replace('.base.', '.{}.'.format(__os_name)) return getattr(importlib.import_module(__module_name), __class_name)(__driver_wrapper) else: return super(MobilePageObject, cls).__new__(cls)
def create_and_configure_wrapper(context_or_world): """Create and configure driver wrapper in behave or lettuce tests :param context_or_world: behave context or lettuce world """ # Create default driver wrapper context_or_world.driver_wrapper = DriverWrappersPool.get_default_wrapper() context_or_world.utils = context_or_world.driver_wrapper.utils # Get behave userdata properties to override config properties try: behave_properties = context_or_world.config.userdata except AttributeError: behave_properties = None # Configure wrapper context_or_world.driver_wrapper.configure(True, context_or_world.config_files, behave_properties) # Copy config object context_or_world.toolium_config = context_or_world.driver_wrapper.config # Configure logger context_or_world.logger = logging.getLogger(__name__)
def __init__(self, by, value, parent=None, order=None, wait=False, shadowroot=None, webview=False): """Initialize the PageElement object with the given locator components. If parent is not None, find_element will be performed over it, instead of using the driver's method, so it can find nested elements. :param by: locator type :param value: locator value :param parent: parent element (WebElement, PageElement or locator tuple) :param order: index value if the locator returns more than one element :param wait: True if the page element must be loaded in wait_until_loaded method of the container page object :param shadowroot: CSS SELECTOR of JS element where shadowroot tag appears :param webview: True if the element is in a mobile webiew """ super(PageElement, self).__init__() self.locator = (by, value ) #: tuple with locator type and locator value self.parent = parent #: element from which to find actual elements self.order = order #: index value if the locator returns more than one element self.wait = wait #: True if it must be loaded in wait_until_loaded method of the container page object self.shadowroot = shadowroot #: CSS SELECTOR of the shadowroot for encapsulated element self.webview = webview #: True if element is in a mobile webview self.driver_wrapper = DriverWrappersPool.get_default_wrapper( ) #: driver wrapper instance self.reset_object(self.driver_wrapper)
def driver_wrapper(): # Remove previous visual path root_path = os.path.dirname(os.path.realpath(__file__)) visual_path = os.path.join(root_path, 'output', 'visualtests') if os.path.exists(visual_path): shutil.rmtree(visual_path) # Reset wrappers pool values DriverWrappersPool._empty_pool() DriverWrapper.config_properties_filenames = None # Create a new wrapper driver_wrapper = DriverWrappersPool.get_default_wrapper() driver_wrapper.driver = mock.MagicMock() # Configure properties root_path = os.path.dirname(os.path.realpath(__file__)) config_files = ConfigFiles() config_files.set_config_directory(os.path.join(root_path, 'conf')) config_files.set_config_properties_filenames('properties.cfg') config_files.set_output_directory(os.path.join(root_path, 'output')) driver_wrapper.configure(config_files) driver_wrapper.config.set('VisualTests', 'enabled', 'true') yield driver_wrapper # Remove visual path visual_path = os.path.join(root_path, 'output', 'visualtests') if os.path.exists(visual_path): shutil.rmtree(visual_path) # Reset wrappers pool values DriverWrappersPool._empty_pool() DriverWrapper.config_properties_filenames = None
def __init__(self, driver_wrapper=None): """Initialize page object properties and update their page elements :param driver_wrapper: driver wrapper instance """ super(PageObject, self).__init__() self.driver_wrapper = driver_wrapper if driver_wrapper else \ DriverWrappersPool.get_default_wrapper() #: driver wrapper instance self.init_page_elements() self.reset_object(self.driver_wrapper)
def __init__(self, driver_wrapper=None): """Initialize page object properties and update their page elements :param driver_wrapper: driver wrapper instance """ super(PageObject, self).__init__() self.driver_wrapper = driver_wrapper if driver_wrapper else \ DriverWrappersPool.get_default_wrapper() #: driver wrapper instance self.app_strings = self.driver_wrapper.app_strings #: mobile application strings self.init_page_elements() self._update_page_elements()
def __init__(self, driver_wrapper=None, wait=False): """Initialize page object properties and update their page elements :param driver_wrapper: driver wrapper instance :param wait: True if the page object must be loaded in wait_until_loaded method of the container page object """ super(PageObject, self).__init__() self.wait = wait #: True if it must be loaded in wait_until_loaded method of the container page object self.driver_wrapper = driver_wrapper if driver_wrapper else \ DriverWrappersPool.get_default_wrapper() #: driver wrapper instance self.init_page_elements() self.reset_object(self.driver_wrapper)
def __init__(self, by, value, parent=None): """Initialize the PageElement object with the given locator components. If parent is not None, find_element will be performed over it, instead of using the driver's method, so it can find nested elements. :param by: locator type :param value: locator value :param parent: parent element (WebElement, PageElement or locator tuple) """ super(PageElement, self).__init__() self.locator = (by, value) #: tuple with locator type and locator value self.parent = parent #: element from which to find actual elements self.driver_wrapper = DriverWrappersPool.get_default_wrapper() #: driver wrapper instance self._web_element = None
def __init__(self, by, value, parent=None): """Initialize the PageElement object with the given locator components. If parent is not None, find_element will be performed over it, instead of using the driver's method, so it can find nested elements. :param by: locator type :param value: locator value :param parent: parent element (WebElement, PageElement or locator tuple) """ super(PageElement, self).__init__() self.locator = (by, value ) #: tuple with locator type and locator value self.parent = parent #: element from which to find actual elements self.driver_wrapper = DriverWrappersPool.get_default_wrapper( ) #: driver wrapper instance self._web_element = None
def __init__(self, by, value, parent=None, order=None, wait=False): """Initialize the PageElement object with the given locator components. If parent is not None, find_element will be performed over it, instead of using the driver's method, so it can find nested elements. :param by: locator type :param value: locator value :param parent: parent element (WebElement, PageElement or locator tuple) :param order: index value if the locator returns more than one element :param wait: True if the page element must be loaded in wait_until_loaded method of the container page object """ super(PageElement, self).__init__() self.locator = (by, value) #: tuple with locator type and locator value self.parent = parent #: element from which to find actual elements self.order = order #: index value if the locator returns more than one element self.wait = wait #: True if it must be loaded in wait_until_loaded method of the container page object self.driver_wrapper = DriverWrappersPool.get_default_wrapper() #: driver wrapper instance self.reset_object(self.driver_wrapper)
def __init__(self, by, value, parent=None, driver_wrapper=None, order=None): """Initialize the Group object with the given locator components. If parent is not None, find_elements will be performed over it, instead of using the driver's method, so it can find nested elements. :param by: locator type :param value: locator value :param parent: parent element (WebElement, PageElement or locator tuple) :param order: index value if the locator returns more than one element :param driver_wrapper: driver wrapper instance """ self.logger = logging.getLogger(__name__) #: logger instance self.locator = (by, value) #: tuple with locator type and locator value self.parent = parent #: element from which to find actual elements self.order = order #: index value if the locator returns more than one element self.driver_wrapper = driver_wrapper if driver_wrapper else \ DriverWrappersPool.get_default_wrapper() #: driver wrapper instance self.init_page_elements() self.reset_object(self.driver_wrapper)
def create_and_configure_wrapper(context_or_world): """Create and configure driver wrapper in behave or lettuce tests :param context_or_world: behave context or lettuce world """ # Create default driver wrapper context_or_world.driver_wrapper = DriverWrappersPool.get_default_wrapper() context_or_world.utils = context_or_world.driver_wrapper.utils # Configure wrapper context_or_world.driver_wrapper.configure(True, context_or_world.config_files) # Override properties with behave userdata properties context_or_world.driver_wrapper.config.update_from_behave_properties(context_or_world) # Copy config object context_or_world.toolium_config = context_or_world.driver_wrapper.config # Configure logger context_or_world.logger = logging.getLogger(__name__)
def __init__(self, by, value, parent=None, page_element_class=None, order=None): """Initialize the PageElements object with the given locator components. If parent is not None, find_elements will be performed over it, instead of using the driver's method, so it can find nested elements. :param by: locator type :param value: locator value :param parent: parent element (WebElement, PageElement or locator tuple) :param order: index value if the locator returns more than one element :param page_element_class: class of page elements (PageElement, Button...) """ super(PageElements, self).__init__() self.locator = (by, value) #: tuple with locator type and locator value self.parent = parent #: element from which to find actual elements self.order = order #: index value if the locator returns more than one element self.driver_wrapper = DriverWrappersPool.get_default_wrapper() #: driver wrapper instance # update instance element class or use PageElement class if page_element_class: self.page_element_class = page_element_class self._page_elements = [] self.reset_object(self.driver_wrapper)
def create_and_configure_wrapper(context_or_world): """Create and configure driver wrapper in behave or lettuce tests :param context_or_world: behave context or lettuce world """ # Create default driver wrapper context_or_world.driver_wrapper = DriverWrappersPool.get_default_wrapper() context_or_world.utils = context_or_world.driver_wrapper.utils # Configure wrapper context_or_world.driver_wrapper.configure(True, context_or_world.config_files) # Override properties with behave userdata properties context_or_world.driver_wrapper.config.update_from_behave_properties( context_or_world) # Copy config object context_or_world.toolium_config = context_or_world.driver_wrapper.config # Configure logger context_or_world.logger = logging.getLogger(__name__)
def bdd_common_before_scenario(context_or_world, scenario): """Common scenario initialization in behave or lettuce :param context_or_world: behave context or lettuce world :param scenario: running scenario """ # Initialize and connect driver wrapper if not DriverWrappersPool.get_default_wrapper().driver: create_and_configure_wrapper(context_or_world) connect_wrapper(context_or_world) # Add assert screenshot methods with scenario configuration add_assert_screenshot_methods(context_or_world, scenario) # Configure Jira properties save_jira_conf() # Add implicitly wait implicitly_wait = context_or_world.toolium_config.get_optional('Driver', 'implicitly_wait') if context_or_world.driver and implicitly_wait: context_or_world.driver.implicitly_wait(implicitly_wait) context_or_world.logger.info("Running new scenario: {0}".format(scenario.name))
def __init__(self, by, value, parent=None, driver_wrapper=None, order=None, wait=False): """Initialize the Group object with the given locator components. If parent is not None, find_elements will be performed over it, instead of using the driver's method, so it can find nested elements. :param by: locator type :param value: locator value :param parent: parent element (WebElement, PageElement or locator tuple) :param driver_wrapper: driver wrapper instance :param order: index value if the locator returns more than one element :param wait: True if the page element must be loaded in wait_until_loaded method of the container page object :param shadowroot: CSS SELECTOR of JS element where shadowroot tag appears """ self.logger = logging.getLogger(__name__) #: logger instance self.locator = (by, value) #: tuple with locator type and locator value self.parent = parent #: element from which to find actual elements self.order = order #: index value if the locator returns more than one element self.wait = wait #: True if it must be loaded in wait_until_loaded method of the container page object self.shadowroot = None #: Not implemented for Group yet self.driver_wrapper = driver_wrapper if driver_wrapper else \ DriverWrappersPool.get_default_wrapper() #: driver wrapper instance self.init_page_elements() self.reset_object(self.driver_wrapper)
def setUp(self): # Remove previous visual path visual_path = os.path.join(self.root_path, 'output', 'visualtests') if os.path.exists(visual_path): shutil.rmtree(visual_path) # Reset wrappers pool values DriverWrappersPool._empty_pool() DriverWrapper.config_properties_filenames = None # Create a new wrapper self.driver_wrapper = DriverWrappersPool.get_default_wrapper() self.driver_wrapper.driver = mock.MagicMock() # Configure properties config_files = ConfigFiles() config_files.set_config_directory(os.path.join(self.root_path, 'conf')) config_files.set_config_properties_filenames('properties.cfg') config_files.set_output_directory(os.path.join(self.root_path, 'output')) self.driver_wrapper.configure(tc_config_files=config_files) self.driver_wrapper.config.set('VisualTests', 'enabled', 'true') # Create a new VisualTest instance self.visual = VisualTest(self.driver_wrapper)