def test_method_waitvisible(self): """Testcase: test_method_waitvisible""" self.setup_login_to_inputs() ControlBase(self.bot, **self.btn_click_invisible).click() # end setup ctl = ControlBase(self.bot, **self.btn_click_visible) ctl_visible = ctl.wait_visible(timeout=7) ASSERT.is_instance(ctl_visible, ControlBase) ASSERT.is_instance(ctl_visible.element, WebElement)
def test_method_waittext(self, ctl_cfg): """Testcase: test_method_waittext""" self.setup_login_to_inputs() ctl_setup = ControlBase(self.bot, **self.btn_click_invisible) ctl_setup.click() ctl_setup.wait_visible(timeout=7) # end setup ctl = ControlBase(self.bot, **getattr(self, ctl_cfg[0])) ctl.reload() ASSERT.true(ctl.wait_text(ctl_cfg[1], timeout=7)) ASSERT.equals(ctl.text, ctl_cfg[1])
def test_003_instance_bydriverload(self): """Testcase: test_003_instance_bydriverload""" control = ControlBase(self.bot, selector=self.ele_menu, wait_for_load=True) self.assertIsInstance(control.element, WebElement) self.assertIsInstance(control, ControlBase)
def __load_table__(self, element=None): """Allow to load all TR > TD items from a TABLE element Before structure some checks are necessary for some children elements: tbody {ControlBase}-- required 1 or more <tbody> elements caption {ControlBase}-- optional <caption> element if tbody found thead {ControlBase}-- optional <thead> element if tbody found tfoot {ControlBase}-- optional <tfoot> element if tbody found Examples: Use case 1. TABLE > (TR > TH)+(TR > TD) Use case 2. TABLE > (THEAD > (TR > TH))+(TBODY > (TR > TH)) """ if element is None: element = self._element self._table = ControlBase( self.bot, **{ "selector": self.selector, "element": element }) # Preload self._tbodies = self.__try__("find_children", "tbody") if bool(self._tbodies): self._rows = self.__load_table_html5__() else: self._rows = self.__load_table_html4__()
def test_controlbase_instance(self, on_instance_search, auto_reload): """Testcase: test_instance_base""" tag_name = "input" cfg = { "name": "txt_username_base", "locator": "css selector", "selector": "#txtUsername-field", "instance": "ControlBase", "on_instance_search": on_instance_search, "auto_reload": auto_reload, } # functional testcases ctl = ControlBase(self.bot, **cfg) ASSERT.is_instance(ctl, ControlBase) # main config ASSERT.equals(ctl.selector, cfg.get('selector')) ASSERT.equals(ctl.name, cfg.get('name')) ASSERT.equals(ctl.locator, cfg.get('locator')) ASSERT.equals(ctl.on_instance_search, cfg.get('on_instance_search')) ASSERT.equals(ctl.auto_reload, cfg.get('auto_reload')) if on_instance_search: ASSERT.is_instance(ctl.element, WebElement) ASSERT.equals(ctl.tag, tag_name) else: ASSERT.none(ctl.element)
def test_method_setcssrule(self): """Testcase: test_method_setcssrule""" cfg_input = self.txt_username.copy() cfg_input.update({"on_instance_search": True}) control = ControlBase(self.bot, **cfg_input) control.type_text('test') control.set_css_value('color', 'red') ASSERT.equals(control.get_css_value('color'), 'rgba(255, 0, 0, 1)')
def test_method_findchild(self): """Testcase: test_method_findchild""" self.setup_login_to_data() control = ControlBase(self.bot, **self.lst_ordered) selector_child = self.lst_ordered_child.get("selector") ctl_child = control.find_child(selector_child) ASSERT.is_instance(ctl_child, ControlBase) ASSERT.is_instance(ctl_child.element, WebElement)
def test_013_method_get_attrs(self): """Testcase: test_013_method_get_attrs""" control = ControlBase(self.bot, selector=self.ele_searcher) attrs = control.get_attrs(['id', 'class']) self.assertEqual(attrs[0]['name'], 'id') self.assertEqual(attrs[0]['value'], 'docsQuery') self.assertEqual(attrs[1]['name'], 'class') self.assertIn('form-control', attrs[1]['value'])
def test_method_typetext(self, control_config, clear): """Testcase: test_method_typetext_cleartrue""" text_to_type = 'test' ctl_config = self.txt_username.copy() ctl_config.update(control_config) control = ControlBase(self.bot, **ctl_config) control.type_text(text_to_type, clear=clear) ASSERT.equals(control.text, text_to_type) ASSERT.equals(control.get_attr_value('value'), text_to_type)
def test_020_method_gettext_onscreenfalse(self): """Testcase: test_020_method_gettext_onscreenfalse""" control = ControlBase(self.bot, selector=self.ele_menu_common_errors) control control.set_css_value('display', 'none') text = control.get_text(on_screen=False) self.assert_greater(len(text), 0, msg='Failed at obtain text, open issue on Github')
def test_method_gettext_onscreenfalse(self): """Testcase: test_method_gettext_onscreenfalse""" msg_err = 'Failed at obtain text, open issue on Github' cfg_btn = self.btn_submit.copy() cfg_btn.update({"on_instance_search": True}) control = ControlBase(self.bot, **cfg_btn) control.set_css_value('display', 'none') text = control.get_text(on_screen=False) ASSERT.greater(len(text), 0, msg=msg_err)
def test_method_get_attrs(self): """Testcase: test_method_get_attrs""" cfg_form = self.form_login.copy() cfg_form.update({"on_instance_search": True}) control = ControlBase(self.bot, **cfg_form) attrs = control.get_attrs(['id', 'class']) ASSERT.equals(attrs[0]['name'], 'id') ASSERT.equals(attrs[0]['value'], 'frmLogin') ASSERT.equals(attrs[1]['name'], 'class') ASSERT.in_list('ember-view', attrs[1]['value'])
def test_controlbase_instance_raises(self): """Testcase: test_instance_raises_base""" cfg = { "name": "controlbase_raises", "selector": None, "instance": None, "on_instance_search": None, "auto_reload": None, } with pytest.raises(CoreException): ControlBase(self.bot, **cfg)
def test_method_reload_base(self, selector, instance): """Testcase: test_method_setcssrule""" # must be supported cfg_base = { "name": "txt_username_base", "locator": "css selector", "selector": selector, "instance": instance, "on_instance_search": False, } control = ControlBase(self.bot, **cfg_base) ASSERT.equals(control.on_instance_search, False) ASSERT.none(control.element) # Real test behaviour cfg_base.update({"on_instance_search": True}) control.reload(**cfg_base) ASSERT.equals(control.on_instance_search, True) ASSERT.is_instance(control.element, WebElement)
def get_elements(self, selectors, as_controls=False): """ Search elements on Bot instance, choose selectors from instance or locator param :Args: :optionals: :selectors: if not selectors passed, then use instance property :as_controls: if True, return list of ControlBase elements loaded from selectors """ msg_page_element_notfound = "Page element not found: " "url={}, selector={}" elements = [] if selectors is None: raise PageException( message='Can\'t use None selectors to get elements') for selector in list(selectors): self.bot.log.debug( "Searching element: with selector={} locator={}".format( selector, self.locator)) if as_controls: element = ControlBase(self.bot, selector, self.locator) else: try: element = self.bot.navigation.find_element( selector, self.locator) except CoreException: raise PageException( message=msg_page_element_notfound.format( self.bot.navigation.get_current_url(), selector)) self.bot.log.debug("Element Found, adding to return method") elements.append(element) return elements
def _load(self, settings=None): """Loads page elements and maximize browser window""" # TODO: tests passed ? self.log = self.bot.log if not settings: settings = self.settings if settings.get('url'): self.url = settings.get('url') if settings.get('go_url'): self.go_url() if settings.get('maximize'): self.log.debug('page action: maximizing browser window') self.bot.navigation.get_maximize_window() if not settings.get('controls'): self.log.debug('page action: empty list of controls for this page') return for cfg_control in settings.get('controls'): self.log.debug( ("page action: Loading element " "as property name='{}'").format(cfg_control.get('name'))) # load default value control = ControlBase(self.bot, **cfg_control) cfg_control.update({'instance': control}) self._set_control(cfg_control)
def test_014_property_tag(self): """Testcase: test_014_property_tag""" control = ControlBase(self.bot, selector=self.ele_menu) self.assertEqual(control.tag, 'div')
def test_016_method_typetext_withmethod(self): """Testcase: test_016_method_typetext_withmethod""" control = ControlBase(self.bot, selector=self.ele_searcher) control.type_text('test') self.assertEqual(control.get_attr_value('value'), 'test')
def test_015_method_typetext_withproperty(self): """Testcase: test_015_method_typetext_withproperty""" control = ControlBase(self.bot, selector=self.ele_searcher) control.type_text('test') self.assertEqual(control.text, 'test')
def test_018_method_getcssvalue(self): """Testcase: test_018_method_getcssvalue""" control = ControlBase(self.bot, selector=self.ele_searcher) self.assertEqual(control.get_css_value('color'), 'rgba(136, 136, 136, 1)')
def test_017_method_typetext_cleartrue(self): """Testcase: test_017_method_typetext_cleartrue""" control = ControlBase(self.bot, selector=self.ele_searcher) control.type_text('test', clear=True) self.assertEqual(control.get_attr_value('value'), 'test')
def test_method_getcssvalue(self): """Testcase: test_method_getcssvalue""" cfg_input = self.txt_username.copy() cfg_input.update({"on_instance_search": True}) control = ControlBase(self.bot, **cfg_input) ASSERT.equals(control.get_css_value('color'), 'rgba(73, 80, 87, 1)')
def test_019_method_setcssrule(self): """Testcase: test_019_method_setcssrule""" control = ControlBase(self.bot, selector=self.ele_searcher) control.type_text('test') control.set_css_value('color', 'red') self.assertEqual(control.get_css_value('color'), 'rgba(255, 0, 0, 1)')
def test_method_click(self, retry): """Testcase: test_method_click""" ctl_config = self.txt_username.copy() control = ControlBase(self.bot, **ctl_config) control.click(retry=retry)
def test_021_method_gettext_raises_onscreenfalse_whenisdisplayed(self): """Testcase: test_021_method_gettext_raises_onscreenfalse_whenisdisplayed """ control = ControlBase(self.bot, selector=self.ele_menu_common_errors) self.assertRaises(ControlException, control.get_text, on_screen=False)
def test_property_tag(self): """Testcase: test_property_tag""" cfg_form = self.form_login.copy() cfg_form.update({"on_instance_search": True}) control = ControlBase(self.bot, **cfg_form) ASSERT.equals(control.tag, 'form')
def test_001_instance_byelement(self): """Testcase: test_001_instance_byelement""" element = self.bot.navigation.find_element(self.ele_menu) control = ControlBase(self.bot, element=element) self.assertIsInstance(control.element, WebElement) self.assertIsInstance(control, ControlBase)
def test_method_getattrvalue(self): """Testcase: test_method_getattrvalue""" cfg_form = self.form_login.copy() cfg_form.update({"on_instance_search": True}) control = ControlBase(self.bot, **cfg_form) ASSERT.not_none(control.get_attr_value('id'))
def test_method_gettext(self): """Testcase: test_method_gettext""" cfg_btn = self.btn_submit.copy() cfg_btn.update({"on_instance_search": True}) control = ControlBase(self.bot, **cfg_btn) ASSERT.equals(control.get_text(), 'Login')
def test_002_instance_byselector(self): """Testcase: test_002_instance_byselector""" control = ControlBase(self.bot, selector=self.ele_menu) self.assertIsInstance(control.element, WebElement) self.assertIsInstance(control, ControlBase)