def __init__(self, select_locator=None, options_names_locator_template=None, value_locator=None): super(ComboBox, self).__init__(select_locator, options_names_locator_template) self.text_field = GetElementType( value_locator, self) if value_locator is not None else GetElementType( select_locator, self)
def __init__(self, by_select_locator=None, by_option_locator_template=None, by_option_locator_all=None, root=None): if by_select_locator is not None and by_option_locator_template is None and by_option_locator_all is None: super(Dropdown, self).__init__(by_option_locator_all=by_select_locator) elif by_select_locator is not None and by_option_locator_template is not None and by_option_locator_all is None: super(Dropdown, self).__init__(by_option_locator_template, by_option_locator_all) self.element = GetElementType(by_select_locator, self) self.expander = GetElementType(by_select_locator, self) elif by_select_locator is not None and by_option_locator_all is not None and by_option_locator_template is None: super(Dropdown, self).__init__(by_option_locator_all=by_option_locator_all) if root is not None: el = Element(by_locator=root) el.set_parent(self.get_parent()) self.set_parent(el) self.set_avatar(el.avatar)
def next_action(self): short_name = "next" if self.next_locator is not None: GetElementType(self.next_locator, self).get(Clickable).click() return new_link = self.get_clickable(short_name) if new_link is not None: new_link.click() return raise Exception( self.cant_choose_element_msg("Next", short_name, "nextAction"))
def last_action(self): short_name = "last" if self.last_locator is not None: GetElementType(self.last_locator, self).get(Clickable).click() return last_link = self.get_clickable(short_name) if last_link is not None: last_link.click() return raise Exception( self.cant_choose_element_msg("Last", short_name, "lastAction"))
class ComboBox(Dropdown): text_field = None def __init__(self, select_locator=None, options_names_locator_template=None, value_locator=None): super(ComboBox, self).__init__(select_locator, options_names_locator_template) self.text_field = GetElementType( value_locator, self) if value_locator is not None else GetElementType( select_locator, self) @scenario(action_name="Clear drop-down text field") def clear(self): self.clear_action() def clear_action(self): self.text_field.get(TextField).clear() def focus_action(self): self.text_field.get(TextField).focus() def get_options(self): is_expanded = self.is_displayed_action(1) if not is_expanded: self._element().click() res = super(ComboBox, self).get_options_actions() if not is_expanded: self._element().click() return res def get_text_action(self): return self.text_field.get(TextField).get_text() @scenario(action_name="Input text %s in text field", values_list={"value_from_function"}) def input(self, text): self.input_action(text) def input_action(self, value): self.text_field.get(TextField).input(value) def new_input(self, text): self.clear() self.input(text) def send_keys(self, text): self.input(text) def set_value_action(self, value): self.clear_action() self.input_action(value)
def select_page_action(self, index): short_name = "page" if self.get_locator() is not None and "%s" in self.get_locator(): GetElementType(self.get_locator() % index, self).get(Clickable).click() return last_link = self.get_clickable(short_name) if last_link is not None: last_link.click() return raise Exception( self.cant_choose_element_msg(index, short_name, "lastAction"))
def previous_action(self): short_name = "previous" if self.next_locator is not None: GetElementType(self.previous_locator, self).get(Clickable).click() return prev_link = self.get_clickable(short_name) if prev_link is not None: prev_link.click() return raise Exception( self.cant_choose_element_msg("Previous", short_name, "previousAction"))
def get_element(self, name): if not self.has_locator() and self.all_labels is None: raise Exception( "Can't find option '%s'. No optionsNamesLocator and allLabelsLocator found" % name) if self.has_locator() and "%s" in self.get_locator()[1]: return GetElementType(self.get_locator() % "%s").get(Clickable) if self.all_labels is not None: return self.get_from_list( self.get_all_labels().avatar.get_elements(), name) elements = self.get_web_elements() if isinstance(name, str): return self.get_from_list(elements, name) elif isinstance(name, Enum): return self.get_from_list(elements, name.value) else: return elements[name - 1]
class ComboBox(Dropdown): text_field = None def __init__(self, select_locator=None, options_names_locator_template=None, value_locator=None): super(ComboBox, self).__init__(select_locator, options_names_locator_template) self.text_field = GetElementType(value_locator, self) if value_locator is not None else GetElementType(select_locator, self) @scenario(action_name="Clear drop-down text field") def clear(self): self.clear_action() def clear_action(self): self.text_field.get(TextField).clear() def focus_action(self): self.text_field.get(TextField).focus() def get_options(self): is_expanded = self.is_displayed_action(1) if not is_expanded: self._element().click() res = super(ComboBox, self).get_options_actions() if not is_expanded: self._element().click() return res def get_text_action(self): return self.text_field.get(TextField).get_text() @scenario(action_name="Input text %s in text field", values_list={"value_from_function"}) def input(self, text): self.input_action(text) def input_action(self, value): self.text_field.get(TextField).input(value) def new_input(self, text): self.clear() self.input(text) def send_keys(self, text): self.input(text) def set_value_action(self, value): self.clear_action() self.input_action(value)
def __init__(self, by_option_locator_template=None, by_option_locator_all=None): super(BaseSelector, self).__init__(by_option_locator_template) if by_option_locator_all is not None: self.all_labels = GetElementType(by_option_locator_all, self)
class Dropdown(Selector, Clickable, Text): element = None expander = None root = None def __init__(self, by_select_locator=None, by_option_locator_template=None, by_option_locator_all=None, root=None): if by_select_locator is not None and by_option_locator_template is None and by_option_locator_all is None: super(Dropdown, self).__init__(by_option_locator_all=by_select_locator) elif by_select_locator is not None and by_option_locator_template is not None and by_option_locator_all is None: super(Dropdown, self).__init__(by_option_locator_template, by_option_locator_all) self.element = GetElementType(by_select_locator, self) self.expander = GetElementType(by_select_locator, self) elif by_select_locator is not None and by_option_locator_all is not None and by_option_locator_template is None: super(Dropdown, self).__init__(by_option_locator_all=by_option_locator_all) if root is not None: el = Element(by_locator=root) el.set_parent(self.get_parent()) self.set_parent(el) self.set_avatar(el.avatar) def click_action(self): self._element().click() @scenario(action_name="Close drop-down") def close(self): if self.is_displayed_action(1): self._element().click() @scenario(action_name="Expand Element") def expand(self): self.expand_action(1) def expand_action(self, value): if isinstance(value, Number): # if not self.is_displayed_in_list(1): self._get_expander().avatar.get_element().click() def is_displayed_action(self, name): el = None try: el = self.all_labels.get(TextList).get_element(name) except: return False return el is not None and el.is_displayed() def get_text_action(self): res = "" if str(self._element().get_locator()[1]).find("select") != -1: res = Select( self._element().get_web_element()).first_selected_option().text return res if res != "" and res is not None else self._element( ).get_text() def get_selected_action(self): return self.get_text() def get_value_action(self): return self.get_text() def get_options(self): is_expanded = self.is_displayed_in_list(1) if not is_expanded: self._element().click() res = super(Dropdown, self).get_options_actions() if not is_expanded: self._element().click() return res def select_action(self, name): if isinstance(name, str): if str(self._element().get_locator()[1]).find(" select") != -1: try: Select(self._element().get_web_element() ).select_by_visible_text(name) except: return self.expand() super(Dropdown, self).select_action(name) elif isinstance(name, Enum): if str(self._element().get_locator()[1]).find(" select") != -1: try: Select(self._element().get_web_element() ).select_by_visible_text(name.value) except: return self.expand() super(Dropdown, self).select_action(name.value) else: if self._element() is not None: self.expand() super(Dropdown, self).select_action(name) else: Select(self.get_web_element().select_by_index(name)) def _element(self): if self.element is None: return GetElementType( self.get_locator(), self).get(Label) if self.get_locator( ) is not None and not self.get_locator() == "" else None return self.element.get(Label) def _get_expander(self): if self.expander is None: if self.get_locator() is not None and not self.get_locator() == "": return GetElementType(self.get_locator(), self).get(Label) raise Exception("'expander' element for dropdown not defined") return self.expander.get(Label)
def _get_expander(self): if self.expander is None: if self.get_locator() is not None and not self.get_locator() == "": return GetElementType(self.get_locator(), self).get(Label) raise Exception("'expander' element for dropdown not defined") return self.expander.get(Label)
def _element(self): if self.element is None: return GetElementType( self.get_locator(), self).get(Label) if self.get_locator( ) is not None and not self.get_locator() == "" else None return self.element.get(Label)
class Dropdown(Selector, Clickable, Text): element = None expander = None root = None def __init__(self, by_select_locator=None, by_option_locator_template=None, by_option_locator_all=None, root=None): if by_select_locator is not None and by_option_locator_template is None and by_option_locator_all is None: super(Dropdown, self).__init__(by_option_locator_all=by_select_locator) elif by_select_locator is not None and by_option_locator_template is not None and by_option_locator_all is None: super(Dropdown, self).__init__(by_option_locator_template, by_option_locator_all) self.element = GetElementType(by_select_locator, self) self.expander = GetElementType(by_select_locator, self) elif by_select_locator is not None and by_option_locator_all is not None and by_option_locator_template is None: super(Dropdown, self).__init__(by_option_locator_all=by_option_locator_all) if root is not None: el = Element(by_locator=root) el.set_parent(self.get_parent()) self.set_parent(el) self.set_avatar(el.avatar) def click_action(self): self._element().click() @scenario(action_name="Close drop-down") def close(self): if self.is_displayed_action(1): self._element().click() @scenario(action_name="Expand Element") def expand(self): self.expand_action(1) def expand_action(self, value): if isinstance(value, Number): # if not self.is_displayed_in_list(1): self._get_expander().avatar.get_element().click() def is_displayed_action(self, name): el = None try: el = self.all_labels.get(TextList).get_element(name) except: return False return el is not None and el.is_displayed() def get_text_action(self): res = "" if str(self._element().get_locator()[1]).find("select") != -1: res = Select(self._element().get_web_element()).first_selected_option().text return res if res != "" and res is not None else self._element().get_text() def get_selected_action(self): return self.get_text() def get_value_action(self): return self.get_text() def get_options(self): is_expanded = self.is_displayed_in_list(1) if not is_expanded: self._element().click() res = super(Dropdown, self).get_options_actions() if not is_expanded: self._element().click() return res def select_action(self, name): if isinstance(name, str): if str(self._element().get_locator()[1]).find(" select") != -1: try: Select(self._element().get_web_element()).select_by_visible_text(name) except: return self.expand() super(Dropdown, self).select_action(name) elif isinstance(name, Enum): if str(self._element().get_locator()[1]).find(" select") != -1: try: Select(self._element().get_web_element()).select_by_visible_text(name.value) except: return self.expand() super(Dropdown, self).select_action(name.value) else: if self._element() is not None: self.expand() super(Dropdown, self).select_action(name) else: Select(self.get_web_element().select_by_index(name)) def _element(self): if self.element is None: return GetElementType(self.get_locator(), self).get(Label) if self.get_locator() is not None and not self.get_locator() == "" else None return self.element.get(Label) def _get_expander(self): if self.expander is None: if self.get_locator() is not None and not self.get_locator() == "": return GetElementType(self.get_locator(), self).get(Label) raise Exception("'expander' element for dropdown not defined") return self.expander.get(Label)
def __init__(self, select_locator=None, options_names_locator_template=None, value_locator=None): super(ComboBox, self).__init__(select_locator, options_names_locator_template) self.text_field = GetElementType(value_locator, self) if value_locator is not None else GetElementType(select_locator, self)
class BaseSelector(Element): is_selector = None all_labels = None def __init__(self, by_option_locator_template=None, by_option_locator_all=None): super(BaseSelector, self).__init__(by_option_locator_template) if by_option_locator_all is not None: self.all_labels = GetElementType(by_option_locator_all, self) def is_displayed_in_list(self, num): els = self.get_web_elements() if num <= 0: raise Exception( "Can't get option with num '{0}'. Number should be 1 or more". format(num)) if els is None: raise Exception( "Can't find option with num '{0}'. Please fix allLabelsLocator" .format(num)) if len(els) < num: raise Exception( "Can't find option with num '{0}'. Find '{1}' options".format( num, els.size())) return els[num].is_displayed() def is_selected(self, el): return self.is_selected_action(el) def is_selected_action(self, el): if self.is_selector: return el.is_selected() attr = el.get_attribute("checked") return attr is not None and attr == "true" def get_all_labels(self): return self.all_labels.get(TextList) def get_element(self, name): if not self.has_locator() and self.all_labels is None: raise Exception( "Can't find option '%s'. No optionsNamesLocator and allLabelsLocator found" % name) if self.has_locator() and "%s" in self.get_locator()[1]: return GetElementType(self.get_locator() % "%s").get(Clickable) if self.all_labels is not None: return self.get_from_list( self.get_all_labels().avatar.get_elements(), name) elements = self.get_web_elements() if isinstance(name, str): return self.get_from_list(elements, name) elif isinstance(name, Enum): return self.get_from_list(elements, name.value) else: return elements[name - 1] def get_from_list(self, elements, name): return next(x for x in elements if x.text == name) def get_options(self): return self.get_options_actions() @scenario(action_name="Get options(text) of element") def get_options_actions(self): return list(map(lambda el: el.text, self.get_web_elements())) @scenario(action_name="Get value") def get_value(self): return self.get_value_action() def get_value_action(self): raise NotImplemented("Need to be implemented in subclasses") def select_action(self, name): el = self.get_element(name) if el is not None: el.click() @scenario(action_name="Set value") def set_value(self, value): self.set_value_action(value) def set_value_action(self, value): self.select_action(value)
class BaseSelector(Element): is_selector = None all_labels = None def __init__(self, by_option_locator_template=None, by_option_locator_all=None): super(BaseSelector, self).__init__(by_option_locator_template) if by_option_locator_all is not None: self.all_labels = GetElementType(by_option_locator_all, self) def is_displayed_in_list(self, num): els = self.get_web_elements() if num <= 0: raise Exception("Can't get option with num '{0}'. Number should be 1 or more".format(num)) if els is None: raise Exception("Can't find option with num '{0}'. Please fix allLabelsLocator".format(num)) if len(els) < num: raise Exception("Can't find option with num '{0}'. Find '{1}' options".format(num, els.size())) return els[num].is_displayed() def is_selected(self, el): return self.is_selected_action(el) def is_selected_action(self, el): if self.is_selector: return el.is_selected() attr = el.get_attribute("checked") return attr is not None and attr == "true" def get_all_labels(self): return self.all_labels.get(TextList) def get_element(self, name): if not self.has_locator() and self.all_labels is None: raise Exception("Can't find option '%s'. No optionsNamesLocator and allLabelsLocator found" % name) if self.has_locator() and "%s" in self.get_locator()[1]: return GetElementType(self.get_locator() % "%s").get(Clickable) if self.all_labels is not None: return self.get_from_list(self.get_all_labels().avatar.get_elements(), name) elements = self.get_web_elements() if isinstance(name, str): return self.get_from_list(elements, name) elif isinstance(name, Enum): return self.get_from_list(elements, name.value) else: return elements[name - 1] def get_from_list(self, elements, name): return next(x for x in elements if x.text == name) def get_options(self): return self.get_options_actions() @scenario(action_name="Get options(text) of element") def get_options_actions(self): return list(map(lambda el: el.text, self.get_web_elements())) @scenario(action_name="Get value") def get_value(self): return self.get_value_action() def get_value_action(self): raise NotImplemented("Need to be implemented in subclasses") def select_action(self, name): el = self.get_element(name) if el is not None: el.click() @scenario(action_name="Set value") def set_value(self, value): self.set_value_action(value) def set_value_action(self, value): self.select_action(value)
def __init__(self, by_options_name_locator=None, by_all_labels_locator=None): super(BaseSelector, self).__init__(by_options_name_locator) if by_all_labels_locator is not None: self.all_labels = GetElementType(by_all_labels_locator, self)