Example #1
0
def select_security_group(sg):
    '''Workaround for select box that is immediately replaced by the same
       select box no matter what selenium clicks on (but works fine
       manually).  For now only selects one item even though it's a
       multiselect.

    '''
    val = sel.get_attribute("//select[@id='environment__security_groups']/option[.='%s']" %
                            sg, 'value')
    sel.browser().execute_script(
        "$j('#environment__security_groups').val('%s');"
        "$j.ajax({type: 'POST', url: '/miq_request/prov_field_changed/new',"
        " data: {'environment__security_groups':'%s'}})" % (val, val))
    sel.wait_for_ajax()
    sel.sleep(1)
def select_security_group(sg):
    '''Workaround for select box that is immediately replaced by the same
       select box no matter what selenium clicks on (but works fine
       manually).  For now only selects one item even though it's a
       multiselect.

    '''
    val = sel.get_attribute(
        "//select[@id='environment__security_groups']/option[.='%s']" % sg,
        'value')
    sel.browser().execute_script(
        "$j('#environment__security_groups').val('%s');"
        "$j.ajax({type: 'POST', url: '/miq_request/prov_field_changed/new',"
        " data: {'environment__security_groups':'%s'}})" % (val, val))
    sel.wait_for_ajax()
    sel.sleep(1)
Example #3
0
 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 set_relationship(self, server_name, server_id, click_cancel=False):
            self.navigate()
            option = "{} ({})".format(server_name, server_id)

            if click_cancel:
                fill(self.relationship_form, {'server_select': option},
                     action=self.relationship_form.cancel_button)
            else:
                fill(self.relationship_form, {'server_select': option},
                     action=self.relationship_form.save_button)
                # something weird going on where changing the select doesn't POST to undim save
                sel.wait_for_ajax()
                if self.relationship_form.save_button.is_dimmed:
                    logger.warning("Worked around dimmed save button")
                    sel.browser().execute_script(
                        "$j.ajax({type: 'POST', url: '/vm_infra/evm_relationship_field_changed',"
                        " data: {'server_id':'%s'}})" % (server_id))
                    sel.click(form_buttons.FormButton(
                        "Save Changes", dimmed_alt="Save", force_click=True))
                flash.assert_success_message("Management Engine Relationship saved")
Example #5
0
    def update(self, updates, cancel=False, validate_credentials=False):
        """
        Updates a host in the UI.  Better to use utils.update.update context
        manager than call this directly.

        Args:
           updates (dict): fields that are changing.
           cancel (boolean): whether to cancel out of the update.
        """

        sel.force_navigate('infrastructure_host_edit', context={'host': self})
        change_stored_password()
        fill(credential_form, updates.get('credentials', None), validate=validate_credentials)

        # Workaround for issue with form_button staying dimmed.
        try:
            logger.debug("Trying to save update for host with id: " + str(self.get_db_id))
            self._submit(cancel, self.forced_saved)
            logger.debug("save worked, no exception")
        except Exception as e:
            logger.debug("exception detected: " + str(e))
            sel.browser().execute_script(
                "$j.ajax({type: 'POST', url: '/host/form_field_changed/%s',"
                " data: {'default_userid':'%s'}})" %
                (str(sel.current_url().split('/')[5]), updates.get('credentials', None).principal))
            sel.browser().execute_script(
                "$j.ajax({type: 'POST', url: '/host/form_field_changed/%s',"
                " data: {'default_password':'******'}})" %
                (str(sel.current_url().split('/')[5]), updates.get('credentials', None).secret))
            sel.browser().execute_script(
                "$j.ajax({type: 'POST', url: '/host/form_field_changed/%s',"
                " data: {'default_verify':'%s'}})" %
                (str(sel.current_url().split('/')[5]),
                    updates.get('credentials', None).verify_secret))
            self._submit(cancel, self.forced_saved)
Example #6
0
    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 set_relationship(self, server_name, server_id, click_cancel=False):
            self.navigate()
            option = "{} ({})".format(server_name, server_id)

            if click_cancel:
                fill(self.relationship_form, {'server_select': option},
                     action=self.relationship_form.cancel_button)
            else:
                fill(self.relationship_form, {'server_select': option},
                     action=self.relationship_form.save_button)
                # something weird going on where changing the select doesn't POST to undim save
                sel.wait_for_ajax()
                if self.relationship_form.save_button.is_dimmed:
                    logger.warning("Worked around dimmed save button")
                    sel.browser().execute_script(
                        "$j.ajax({type: 'POST', url: '/vm_infra/evm_relationship_field_changed',"
                        " data: {'server_id':'%s'}})" % (server_id))
                    sel.click(
                        form_buttons.FormButton("Save Changes",
                                                dimmed_alt="Save",
                                                force_click=True))
                flash.assert_success_message(
                    "Management Engine Relationship saved")
Example #8
0
    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)
Example #9
0
 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()
Example #10
0
 def close_all_boxes(cls):
     """No other solution as the boxes have no ID"""
     for box in sel.elements(cls._box):
         sel.browser().execute_script(
             "if(arguments[0].style.display != 'none') arguments[0].style.display = 'none';", box
         )
Example #11
0
 def close_all_boxes(cls):
     """No other solution as the boxes have no ID"""
     for box in sel.elements(cls._box):
         sel.browser().execute_script(
             "if(arguments[0].style.display != 'none') arguments[0].style.display = 'none';",
             box)
Example #12
0
def get_rid_of_the_menu_box():
    """Moves the mouse pointer away from the menu location and waits for the popups to hide."""
    # We received quite a lot of errors based on #tP not being visible. This tries to wait for it.
    wait_for(sel.is_displayed, ["#tP"], num_sec=5, delay=0.1, message="page ready")
    ActionChains(sel.browser()).move_to_element(sel.element("#tP")).perform()
    wait_for(lambda: not any_box_displayed(), num_sec=10, delay=0.1, message="menu box")
Example #13
0
def get_rid_of_the_menu_box():
    """Moves the mouse pointer away from the menu location and waits for the popups to hide."""
    ActionChains(sel.browser()).move_to_element(sel.element("#tP")).perform()
    wait_for(lambda: not any_box_displayed(), num_sec=10, delay=0.1, message="menu box")
Example #14
0
def get_rid_of_the_menu_box():
    """Moves the mouse pointer away from the menu location and waits for the popups to hide."""
    # We received quite a lot of errors based on #tP not being visible. This tries to wait for it.
    wait_for(sel.is_displayed, ["#tP"], num_sec=5, delay=0.1, message="page ready")
    ActionChains(sel.browser()).move_to_element(sel.element("#tP")).perform()
    wait_for(lambda: not any_box_displayed(), num_sec=10, delay=0.1, message="menu box")