def f(_): toplevel_elem = sel.element(toplevel_loc % toplevel) if secondlevel is None: sel.click(toplevel_elem) else: sel.move_to_element(toplevel_elem) sel.click(sel.element(secondlevel_loc % (toplevel, secondlevel)))
def _get_box(self): """Caching of the opened box""" if getattr(self, "_box_id", None) is None: self._open_box() for box in sel.elements(self._box): try: sel.move_to_element(box) if sel.is_displayed(box): self._box_id = box.id return box except sel.NoSuchElementException: pass else: raise Exception("Could not open the box!") else: el = WebElement(sel.browser(), self._box_id) try: el.tag_name if not sel.is_displayed(el): raise NotDisplayedException() return el except (StaleElementReferenceException, NoSuchElementException, NotDisplayedException): del self._box_id return self._get_box()
def can_be_clicked(self): """Whether the button is displayed, therefore clickable.""" try: sel.move_to_element(self) return sel.is_displayed(self) except NoSuchElementException: return False
def _get_tooltip(cls, lines, circle_index): for line in lines: cir = line.find_elements_by_tag_name("circle")[circle_index] if 'opacity: 1' in cir.get_attribute('style'): sel.move_to_element(cir) return sel.element('//*[contains(@class, "c3-tooltip-container")]') return None
def proc_node(loc, c=0, prev_node=None): if not prev_node: prev_node = [] for el in sel.elements(loc + self.ANY_LEV): sel.move_to_element(el) new_loc = loc + self.NAMED_LEV.format(el.text) nn = prev_node[:] nn.append(el.text) proc_node(new_loc, c + 1, nn) else: nodes.append(prev_node)
def form(self): """Returns Form filled with fields. Scraps the webpage to determine the fields. Requires to be on the page """ names = [] for cell in sel.elements(self.fields): # The received text is something like u' (blabla)' so we extract 'blabla' sel.move_to_element(cell) # This is required in order to correctly read the content names.append(re.sub(r"^[^(]*\(([^)]+)\)[^)]*$", "\\1", sel.text(cell).encode("utf-8"))) return Form(fields=[(name, InstanceFieldsRow(i)) for i, name in enumerate(names)])
def _old_visible_pages(self): """Method returning the visible pages in 5.4""" menu_names = self._old_visible_toplevel_tabs() # Now go from tab to tab and pull the secondlevel names from the visible links displayed_menus = [] for menu_name in menu_names: menu_elem = sel.element(self.toplevel_loc.format(menu_name)) sel.move_to_element(menu_elem) for submenu_elem in sel.elements('../ul/li/a', root=menu_elem): displayed_menus.append((menu_name, sel.text(submenu_elem))) return displayed_menus
def select_n_move(el): """ Clicks an element and then moves the mouse away This is required because if the button is active and we clicked it, the CSS class doesn't change until the mouse is moved away. Args: el: The element to click on. Returns: None """ # .. if we don't move the "mouse" the button stays active sel.click(el) sel.move_to_element(".navbar-brand")
def f(_): if callable(toplevel): top_level = toplevel() else: top_level = toplevel if not is_page_active(top_level): try: # Try to circumvent the issue on fir get_rid_of_the_menu_box() open_top_level(top_level) get_rid_of_the_menu_box() if get_current_toplevel_name() != top_level: # Infrastructure / Requests workaround sel.move_to_element(get_top_level_element(top_level)) # Using pure move_to_element to not move the mouse anywhere else # So in this case, we move the mouse to the first item of the second level ActionChains(sel.browser())\ .move_to_element(sel.element(Loc.secondlevel_first_item_loc.format( top_level)))\ .click()\ .perform() get_rid_of_the_menu_box() # Now when we went directly to the first item, everything should just work tl = get_current_toplevel_name() if tl != top_level: raise Exception("Navigation screwed! (wanted {}, got {}".format(top_level, tl)) except NoSuchElementException: if visible_toplevel_tabs(): # Target menu is missing raise else: return # no menu at all, assume single permission # Can't do this currently because silly menu traps us # if is_page_active(toplevel, secondlevel): # return if secondlevel is not None: get_rid_of_the_menu_box() if callable(secondlevel): second_level = secondlevel() else: second_level = secondlevel open_second_level(get_top_level_element(top_level), second_level) get_rid_of_the_menu_box() if reset_action is not None: if callable(reset_action): reset_action() else: sel.click(reset_action)
def form(self): """Returns Form filled with fields. Scraps the webpage to determine the fields. Requires to be on the page """ names = [] for cell in sel.elements(self.fields): # The received text is something like u' (blabla)' so we extract 'blabla' sel.move_to_element( cell ) # This is required in order to correctly read the content names.append( re.sub(r"^[^(]*\(([^)]+)\)[^)]*$", "\\1", sel.text(cell).encode("utf-8"))) return Form(fields=[(name, InstanceFieldsRow(i)) for i, name in enumerate(names)])
def _assign_unassign_policy_profiles(self, assign, *policy_profile_names): """ Assign or unassign Policy Profiles to this Provider. DRY method Args: assign: Whether this method assigns or unassigns policy profiles. policy_profile_names: :py:class:`str` with Policy Profile's name. After Control/Explorer coverage goes in, PolicyProfile object will be also passable. """ sel.force_navigate('clouds_provider_policy_assignment', context={'provider': self}) for policy_profile in policy_profile_names: if assign: manage_policies_tree.check_node(policy_profile) else: manage_policies_tree.uncheck_node(policy_profile) sel.move_to_element('#tP') form_buttons.save()
def _assign_unassign_policy_profiles(self, assign, *policy_profile_names): """DRY function for managing policy profiles. See :py:func:`assign_policy_profiles` and :py:func:`assign_policy_profiles` Args: assign: Wheter to assign or unassign. policy_profile_names: :py:class:`str` with Policy Profile names. """ sel.force_navigate('infrastructure_provider_policy_assignment', context={'provider': self}) for policy_profile in policy_profile_names: if assign: manage_policies_tree.check_node(policy_profile) else: manage_policies_tree.uncheck_node(policy_profile) sel.move_to_element('#tP') form_buttons.save()
def _assign_unassign_policy_profiles(self, assign, *policy_profile_names): """DRY function for managing policy profiles. See :py:func:`assign_policy_profiles` and :py:func:`assign_policy_profiles` Args: assign: Wheter to assign or unassign. policy_profile_names: :py:class:`str` with Policy Profile names. """ self.load_details(refresh=True) pol_btn("Manage Policies") for policy_profile in policy_profile_names: if assign: manage_policies_tree.check_node(policy_profile) else: manage_policies_tree.uncheck_node(policy_profile) sel.move_to_element('#tP') form_buttons.save()
def visible_pages(): """Return a list of all the menu pages currently visible top- and second-level pages Mainly useful for RBAC testing """ # Gather up all the visible toplevel tabs menu_names = visible_toplevel_tabs() # Now go from tab to tab and pull the secondlevel names from the visible links displayed_menus = [] for menu_name in menu_names: menu_elem = sel.element(toplevel_loc.format(menu_name)) sel.move_to_element(menu_elem) for submenu_elem in sel.elements('../ul/li/a', root=menu_elem): displayed_menus.append((menu_name, sel.text(submenu_elem))) # Do reverse lookups so we can compare to the list of nav destinations for this group return sorted([reverse_lookup(*displayed) for displayed in displayed_menus])
def visible_pages(): """Return a list of all the menu pages currently visible top- and second-level pages Mainly useful for RBAC testing """ # Gather up all the visible toplevel tabs menu_names = visible_toplevel_tabs() # Now go from tab to tab and pull the secondlevel names from the visible links displayed_menus = [] for menu_name in menu_names: menu_elem = sel.element(Loc.toplevel_loc.format(menu_name)) sel.move_to_element(menu_elem) for submenu_elem in sel.elements('../ul/li/a', root=menu_elem): displayed_menus.append((menu_name, sel.text(submenu_elem))) # Do reverse lookups so we can compare to the list of nav destinations for this group return sorted([reverse_lookup(*displayed) for displayed in displayed_menus])
def _assign_unassign_policy_profiles(self, assign, *policy_profile_names): """DRY function for managing policy profiles. See :py:func:`assign_policy_profiles` and :py:func:`assign_policy_profiles` Args: assign: Wheter to assign or unassign. policy_profile_names: :py:class:`str` with Policy Profile names. """ self.load_details(refresh=True) pol_btn("Manage Policies") for policy_profile in policy_profile_names: if assign: self.manage_policies_tree.check_node(policy_profile) else: self.manage_policies_tree.uncheck_node(policy_profile) sel.move_to_element({version.LOWEST: '#tP', "5.5": "//h3[1]"}) form_buttons.save() flash.assert_no_errors()
def _assign_unassign_policy_profiles(vm_name, assign, *policy_profile_names, **kwargs): """DRY function for managing policy profiles. See :py:func:`assign_policy_profiles` and :py:func:`assign_policy_profiles` Args: vm_name: Name of the instance. assign: Wheter to assign or unassign. policy_profile_names: :py:class:`str` with Policy Profile names. """ _method_setup(vm_name, **kwargs) toolbar.select("Policy", "Manage Policies") for policy_profile in policy_profile_names: if assign: manage_policies_tree.check_node(policy_profile) else: manage_policies_tree.uncheck_node(policy_profile) sel.move_to_element('#tP') sel.click(form_buttons.save)
def _assign_unassign_policy_profiles(self, assign, *policy_profile_names): """ Assign or unassign Policy Profiles to this Provider. DRY method See :py:func:`assign_policy_profiles` and :py:func:`assign_policy_profiles` Args: assign: Whether this method assigns or unassigns policy profiles. policy_profile_names: :py:class:`str` with Policy Profile's name. After Control/Explorer coverage goes in, PolicyProfile object will be also passable. """ sel.force_navigate('{}_provider_policy_assignment'.format( self.page_name), context={'provider': self}) for policy_profile in policy_profile_names: if assign: manage_policies_tree.check_node(policy_profile) else: manage_policies_tree.uncheck_node(policy_profile) sel.move_to_element('#tP') form_buttons.save()
def test_hostname_max_character_validation(): """Test to validate max character for hostname field""" prov = OpenStackProvider(name=fauxfactory.gen_alphanumeric(5), hostname=fauxfactory.gen_alphanumeric(256), ip_address='10.10.10.13') try: prov.create() except FlashMessageException: element = sel.move_to_element( prov.properties_form.locators["hostname_text"]) text = element.get_attribute('value') assert text == prov.hostname[0:255]
def validate_menus(group_name, group_data): displayed_menus = {} navbar = menu_by_name('main') # Save menus that are available to the user and sort them for menu_name, menu_loc in navbar.locators.iteritems(): if sel.is_displayed(menu_loc): displayed_menus[menu_name] = [] sel.move_to_element(menu_loc) menu = menu_by_name(menu_name) for submenu_name, submenu_loc in menu.locators.iteritems(): if sel.is_displayed(submenu_loc): displayed_menus[menu_name].append(submenu_name) displayed_menus[menu_name].sort() # Sort the yaml menus for menu_name in group_data["menus"]: group_data["menus"][menu_name].sort() # Compare them assert displayed_menus == group_data["menus"]
def test_hostname_max_character_validation(request): """Test to validate max character for hostname field""" prov = OpenStackProvider( name=fauxfactory.gen_alphanumeric(5), hostname=fauxfactory.gen_alphanumeric(256), ip_address='10.10.10.13') try: prov.create() except FlashMessageException: element = sel.move_to_element(prov.properties_form.locators["hostname_text"]) text = element.get_attribute('value') assert text == prov.hostname[0:255]
def test_api_port_max_character_validation(): """Test to validate max character for api port field""" prov = OpenStackProvider(name=fauxfactory.gen_alphanumeric(5), hostname=fauxfactory.gen_alphanumeric(5), ip_address='10.10.10.15', api_port=fauxfactory.gen_alphanumeric(16)) try: prov.create() except FlashMessageException: element = sel.move_to_element( prov.properties_form.locators["api_port"]) text = element.get_attribute('value') assert text == prov.api_port[0:15]
def test_api_port_max_character_validation(): """Test to validate max character for api port field""" prov = RHEVMProvider( name=fauxfactory.gen_alphanumeric(5), hostname=fauxfactory.gen_alphanumeric(5), ip_address='10.10.10.15', api_port=fauxfactory.gen_alphanumeric(16)) try: prov.create() except FlashMessageException: element = sel.move_to_element(prov.properties_form.locators["api_port"]) text = element.get_attribute('value') assert text == prov.api_port[0:15]
def f(_): try: toplevel_elem = sel.element(toplevel_loc % toplevel) except NoSuchElementException: if visible_toplevel_tabs(): # Target menu is missing raise else: return # no menu at all, assume single permission if secondlevel is None: sel.click(toplevel_elem) else: sel.move_to_element(toplevel_elem) for (toplevel_dest, toplv), secondlevels in sections.items(): if toplv == toplevel: try: sel.move_to_element(sel.element(secondlevel_first_item_loc % toplevel)) except NoSuchElementException: # Target menu is missing sel.click(toplevel_elem) return # no 2nd lvl menu, assume single permission break sel.click(sel.element(secondlevel_loc % (toplevel, secondlevel)))
def f(_): try: toplevel_elem = sel.element(toplevel_loc % toplevel) except NoSuchElementException: if visible_toplevel_tabs(): # Target menu is missing raise else: return # no menu at all, assume single permission if secondlevel is None: sel.click(toplevel_elem) else: sel.move_to_element(toplevel_elem) for (toplevel_dest, toplv), secondlevels in sections.items(): if toplv == toplevel: try: sel.move_to_element( sel.element(secondlevel_first_item_loc % toplevel)) except NoSuchElementException: # Target menu is missing sel.click(toplevel_elem) return # no 2nd lvl menu, assume single permission break sel.click(sel.element(secondlevel_loc % (toplevel, secondlevel)))