コード例 #1
0
ファイル: menu.py プロジェクト: vprusa/cfme_tests
    def f(_):
        # Can't do this currently because silly menu traps us
        # if is_page_active(toplevel, secondlevel):
        #     return
        if callable(toplevel):
            top_level = toplevel()
        else:
            top_level = toplevel

        if secondlevel is not None:
            if callable(secondlevel):
                second_level = secondlevel()
            else:
                second_level = secondlevel

            if secondlevel.startswith('/'):
                active_loc = (TOP_LEV_ACTIVE + SECOND_LEV_ACTIVE_HREF).format(
                    top_level, second_level)
                inactive_loc = (TOP_LEV_INACTIVE +
                                SECOND_LEV_INACTIVE_HREF).format(
                                    top_level, second_level)
            else:
                active_loc = (TOP_LEV_ACTIVE + SECOND_LEV_ACTIVE).format(
                    top_level, second_level)
                inactive_loc = (TOP_LEV_INACTIVE + SECOND_LEV_INACTIVE).format(
                    top_level, second_level)
            el = "{} | {}".format(active_loc, inactive_loc)

            try:
                href = sel.get_attribute(el, 'href')
                sel.execute_script('document.location.href="{}"'.format(href))
            except NoSuchElementException:
                raise
        else:
            active_loc = TOP_LEV_ACTIVE.format(top_level)
            inactive_loc = TOP_LEV_INACTIVE.format(top_level)
            el = "{} | {}".format(active_loc, inactive_loc)

            try:
                href = sel.get_attribute(el, 'href')
                sel.execute_script('document.location.href="{}"'.format(href))
            except NoSuchElementException:
                raise
        sel.wait_for_ajax()
        if reset_action is not None:
            try:
                if callable(reset_action):
                    reset_action()
                else:
                    sel.click(reset_action)
            except NoSuchElementException:
                if _final:
                    # We have tried to renavigate but still some problem. Never mind and explode.
                    raise
                else:
                    # Work around the problem when the display selector disappears after returning
                    # from VM summary view. Can be fixed by renavigating, it then appears again.
                    nav_to_fn(toplevel, secondlevel, reset_action, _final=True)
        # todo move to element on the active tab to clear the menubox
        sel.wait_for_ajax()
コード例 #2
0
ファイル: menu.py プロジェクト: amavinag/cfme_tests
    def f(_):
        # Can't do this currently because silly menu traps us
        # if is_page_active(toplevel, secondlevel):
        #     return
        if callable(toplevel):
            top_level = toplevel()
        else:
            top_level = toplevel

        if secondlevel is not None:
            if callable(secondlevel):
                second_level = secondlevel()
            else:
                second_level = secondlevel

            if secondlevel.startswith('/'):
                active_loc = (TOP_LEV_ACTIVE + SECOND_LEV_ACTIVE_HREF).format(
                    top_level, second_level)
                inactive_loc = (TOP_LEV_INACTIVE + SECOND_LEV_INACTIVE_HREF).format(
                    top_level, second_level)
            else:
                active_loc = (TOP_LEV_ACTIVE + SECOND_LEV_ACTIVE).format(top_level, second_level)
                inactive_loc = (TOP_LEV_INACTIVE + SECOND_LEV_INACTIVE).format(
                    top_level, second_level)
            el = "{} | {}".format(active_loc, inactive_loc)

            try:
                href = sel.get_attribute(el, 'href')
                sel.execute_script('document.location.href="{}"'.format(href))
            except NoSuchElementException:
                raise
        else:
            active_loc = TOP_LEV_ACTIVE.format(top_level)
            inactive_loc = TOP_LEV_INACTIVE.format(top_level)
            el = "{} | {}".format(active_loc, inactive_loc)

            try:
                href = sel.get_attribute(el, 'href')
                sel.execute_script('document.location.href="{}"'.format(href))
            except NoSuchElementException:
                raise
        sel.wait_for_ajax()
        if reset_action is not None:
            try:
                if callable(reset_action):
                    reset_action()
                else:
                    sel.click(reset_action)
            except NoSuchElementException:
                if _final:
                    # We have tried to renavigate but still some problem. Never mind and explode.
                    raise
                else:
                    # Work around the problem when the display selector disappears after returning
                    # from VM summary view. Can be fixed by renavigating, it then appears again.
                    nav_to_fn(toplevel, secondlevel, reset_action, _final=True)
        # todo move to element on the active tab to clear the menubox
        sel.wait_for_ajax()
コード例 #3
0
ファイル: form_buttons.py プロジェクト: jaryn/cfme_tests
def change_stored_password():
    try:
        if version.current_version() > '5.5':
            sel.execute_script(
                sel.get_attribute(
                    sel.element('//a[@id="change_stored_password"]'), 'onClick'))
    except NoSuchElementException:
        logger.info('Change stored PW not found, probably no creds already')
        return
コード例 #4
0
def change_stored_password():
    if sel.is_displayed(_stored_pw_script):
        sel.execute_script(
            sel.get_attribute(sel.element(_stored_pw_script), 'onClick'))
        sel.wait_for_ajax()  # To play safe
    elif sel.is_displayed(_stored_pw_angular):
        sel.click(_stored_pw_angular)
    else:
        logger.info("Probably no creds")
コード例 #5
0
def change_stored_password():
    if version.current_version() > '5.5':
        if sel.is_displayed(_stored_pw_script):
            sel.execute_script(
                sel.get_attribute(sel.element(_stored_pw_script), 'onClick'))
            sel.wait_for_ajax()  # To play safe
        elif sel.is_displayed(_stored_pw_angular):
            sel.click(_stored_pw_angular)
        else:
            logger.info("Probably no creds")
コード例 #6
0
def old_select(root, sub=None, invokes_alert=False):
    """ Clicks on a button by calling the dhtmlx toolbar callEvent.

    Args:
        root: The root button's name as a string.
        sub: The sub button's name as a string. (optional)
        invokes_alert: If ``True``, then the behaviour is little bit different. After the last
            click, no ajax wait and no move away is done to be able to operate the alert that
            appears after click afterwards. Defaults to ``False``.
    Returns: ``True`` if everything went smoothly
    Raises: :py:class:`cfme.exceptions.ToolbarOptionGreyedOrUnavailable`
    """
    # wait for ajax on select to prevent pickup up a toolbar button in the middle of a page change
    sel.wait_for_ajax()
    if isinstance(root, dict):
        root = version.pick(root)
    if sub is not None and isinstance(sub, dict):
        sub = version.pick(sub)

    root_obj = version.pick({
        '5.4': 'miq_toolbars',
        '5.5.0.7': 'ManageIQ.toolbars'
    })

    if sub:
        search = sub_loc(sub)
    else:
        search = root_loc(root)

    eles = sel.elements(search)

    for ele in eles:
        idd = sel.get_attribute(ele, 'idd')
        if idd:
            break
    else:
        raise ToolbarOptionGreyedOrUnavailable(
            "Toolbar button {}/{} is greyed or unavailable!".format(root, sub))

    buttons = sel.execute_script('return {}'.format(root_obj))
    tb_name = None
    for tb_key, tb_obj in buttons.iteritems():
        for btn_key, btn_obj in tb_obj['buttons'].iteritems():
            if btn_obj['name'] == idd:
                tb_name = tb_key
    if not tb_name:
        raise ToolbarOptionGreyedOrUnavailable(
            "Toolbar button {}/{} is greyed or unavailable!".format(root, sub))

    sel.execute_script("{}['{}']['obj'].callEvent('onClick', ['{}'])".format(
        root_obj, tb_name, idd))

    if not invokes_alert:
        sel.wait_for_ajax()
    return True
コード例 #7
0
ファイル: toolbar.py プロジェクト: MattLombana/cfme_tests
def old_select(root, sub=None, invokes_alert=False):
    """ Clicks on a button by calling the dhtmlx toolbar callEvent.

    Args:
        root: The root button's name as a string.
        sub: The sub button's name as a string. (optional)
        invokes_alert: If ``True``, then the behaviour is little bit different. After the last
            click, no ajax wait and no move away is done to be able to operate the alert that
            appears after click afterwards. Defaults to ``False``.
    Returns: ``True`` if everything went smoothly
    Raises: :py:class:`cfme.exceptions.ToolbarOptionGreyedOrUnavailable`
    """
    # wait for ajax on select to prevent pickup up a toolbar button in the middle of a page change
    sel.wait_for_ajax()
    if isinstance(root, dict):
        root = version.pick(root)
    if sub is not None and isinstance(sub, dict):
        sub = version.pick(sub)

    root_obj = version.pick({'5.4': 'miq_toolbars',
        '5.5.0.7': 'ManageIQ.toolbars'})

    if sub:
        search = sub_loc(sub)
    else:
        search = root_loc(root)

    eles = sel.elements(search)

    for ele in eles:
        idd = sel.get_attribute(ele, 'idd')
        if idd:
            break
    else:
        raise ToolbarOptionGreyedOrUnavailable(
            "Toolbar button {}/{} is greyed or unavailable!".format(root, sub))

    buttons = sel.execute_script('return {}'.format(root_obj))
    tb_name = None
    for tb_key, tb_obj in buttons.iteritems():
        for btn_key, btn_obj in tb_obj['buttons'].iteritems():
            if btn_obj['name'] == idd:
                tb_name = tb_key
    if not tb_name:
        raise ToolbarOptionGreyedOrUnavailable(
            "Toolbar button {}/{} is greyed or unavailable!".format(root, sub))

    sel.execute_script(
        "{}['{}']['obj'].callEvent('onClick', ['{}'])".format(root_obj, tb_name, idd))

    if not invokes_alert:
        sel.wait_for_ajax()
    return True
コード例 #8
0
ファイル: vm.py プロジェクト: dgur/integration_tests
def date_retire_element(fill_data):
    """We need to call this function that will mimic clicking the calendar, picking the date and
    the subsequent callbacks from the server"""
    # TODO: Move the code in the Calendar itself? I did not check other calendars
    if isinstance(fill_data, date):
        date_str = '{}/{}/{}'.format(fill_data.month, fill_data.day,
                                     fill_data.year)
    else:
        date_str = str(fill_data)
    sel.execute_script(
        js.update_retirement_date_function_script +
        "updateDate(arguments[0]);", date_str)
コード例 #9
0
ファイル: vm.py プロジェクト: akrzos/cfme_tests
def date_retire_element(fill_data):
    """We need to call this function that will mimic clicking the calendar, picking the date and
    the subsequent callbacks from the server"""
    # TODO: Move the code in the Calendar itself? I did not check other calendars
    if isinstance(fill_data, date):
        date_str = '{}/{}/{}'.format(fill_data.month, fill_data.day, fill_data.year)
    else:
        date_str = str(fill_data)
    sel.execute_script(
        js.update_retirement_date_function_script +
        "updateDate(arguments[0]);",
        date_str
    )
コード例 #10
0
ファイル: menu.py プロジェクト: pombredanne/cfme_tests
    def f(_):
        # Can't do this currently because silly menu traps us
        # if is_page_active(toplevel, secondlevel):
        #     return
        if callable(toplevel):
            top_level = toplevel()
        else:
            top_level = toplevel

        if secondlevel is not None:
            if callable(secondlevel):
                second_level = secondlevel()
            else:
                second_level = secondlevel

            if secondlevel.startswith('/'):
                active_loc = (TOP_LEV_ACTIVE + SECOND_LEV_ACTIVE_HREF).format(
                    top_level, second_level)
                inactive_loc = (TOP_LEV_INACTIVE + SECOND_LEV_INACTIVE_HREF).format(
                    top_level, second_level)
            else:
                active_loc = (TOP_LEV_ACTIVE + SECOND_LEV_ACTIVE).format(top_level, second_level)
                inactive_loc = (TOP_LEV_INACTIVE + SECOND_LEV_INACTIVE).format(
                    top_level, second_level)
            el = "{} | {}".format(active_loc, inactive_loc)

            try:
                href = sel.get_attribute(el, 'href')
                sel.execute_script('document.location.href="{}"'.format(href))
            except NoSuchElementException:
                raise
        else:
            active_loc = TOP_LEV_ACTIVE.format(top_level)
            inactive_loc = TOP_LEV_INACTIVE.format(top_level)
            el = "{} | {}".format(active_loc, inactive_loc)

            try:
                href = sel.get_attribute(el, 'href')
                sel.execute_script('document.location.href="{}"'.format(href))
            except NoSuchElementException:
                raise
        sel.wait_for_ajax()
        if reset_action is not None:
            if callable(reset_action):
                reset_action()
            else:
                sel.click(reset_action)
        # todo move to element on the active tab to clear the menubox
        sel.wait_for_ajax()
コード例 #11
0
ファイル: jstimelines.py プロジェクト: vrutkovs/cfme_tests
def _list_events():
    try:
        soutput = sel.execute_script(
            'return tl._bands[0]._eventSource._events._events._a')
        return soutput
    except sel.WebDriverException:
        return []
コード例 #12
0
ファイル: menu.py プロジェクト: anewmanRH/cfme_tests
    def _try_nav(el, toplevel, secondlevel, thirdlevel=None):
        try:
            href = sel.get_attribute(el, 'href')
        except NoSuchElementException as e:
            # Make our own exception
            if thirdlevel is None:
                item = '{} / {}'.format(toplevel, secondlevel)
            else:
                item = '{} / {} / {}'.format(toplevel, secondlevel, thirdlevel)

            message = '\n'.join([
                'An error happened during selecting of the menu item: {}'.format(item),
                str(e).rstrip(),  # An extra newline at the end.
            ])

            raise MenuItemNotFound(message)

        sel.execute_script('document.location.href = arguments[0];', href)
        sel.wait_for_ajax()
コード例 #13
0
def pf_select(root, sub=None, invokes_alert=False):
    """ Clicks on a button by calling the click event with the jquery trigger.

    Args:
        root: The root button's name as a string.
        sub: The sub button's name as a string. (optional)
        invokes_alert: If ``True``, then the behaviour is little bit different. After the last
            click, no ajax wait and no move away is done to be able to operate the alert that
            appears after click afterwards. Defaults to ``False``.
    Returns: ``True`` if everything went smoothly
    Raises: :py:class:`cfme.exceptions.ToolbarOptionGreyedOrUnavailable`
    """

    sel.wait_for_ajax()
    if isinstance(root, dict):
        root = version.pick(root)
    if isinstance(sub, dict):
        sub = version.pick(sub)

    if sub:
        q_sub = quoteattr(sub).replace("'", "\\'")
        sel.execute_script(
            "return $('a:contains({})').trigger('click')".format(q_sub))
    else:
        q_root = quoteattr(root).replace("'", "\\'")
        try:
            sel.element("//button[@data-original-title = {0}] | "
                        "//a[@data-original-title = {0}]".format(q_root))
            sel.execute_script(
                "return $('*[data-original-title={}]').trigger('click')".
                format(q_root))
        except sel.NoSuchElementException:
            try:
                sel.element("//button[@title={}]".format(q_root))
                sel.execute_script(
                    "return $('button[title={}]').trigger('click')".format(
                        q_root))
            except sel.NoSuchElementException:
                try:
                    sel.element(
                        "//button[contains(@title, {})]".format(q_root))
                    sel.execute_script(
                        "return $('button:contains({})').trigger('click')".
                        format(q_root))
                except sel.NoSuchElementException:
                    # The view selection buttons?
                    sel.click(
                        "//li/a[@title={}]/*[self::i or self::img]/../..".
                        format(q_root))

    if not invokes_alert:
        sel.wait_for_ajax()
    return True
コード例 #14
0
ファイル: toolbar.py プロジェクト: MattLombana/cfme_tests
def pf_select(root, sub=None, invokes_alert=False):
    """ Clicks on a button by calling the click event with the jquery trigger.

    Args:
        root: The root button's name as a string.
        sub: The sub button's name as a string. (optional)
        invokes_alert: If ``True``, then the behaviour is little bit different. After the last
            click, no ajax wait and no move away is done to be able to operate the alert that
            appears after click afterwards. Defaults to ``False``.
    Returns: ``True`` if everything went smoothly
    Raises: :py:class:`cfme.exceptions.ToolbarOptionGreyedOrUnavailable`
    """

    sel.wait_for_ajax()
    if isinstance(root, dict):
        root = version.pick(root)
    if isinstance(sub, dict):
        sub = version.pick(sub)

    if sub:
        q_sub = quoteattr(sub).replace("'", "\\'")
        sel.execute_script(
            "return $('a:contains({})').trigger('click')".format(q_sub))
    else:
        q_root = quoteattr(root).replace("'", "\\'")
        try:
            sel.element("//button[@data-original-title = {0}] | "
                        "//a[@data-original-title = {0}]".format(q_root))
            sel.execute_script(
                "return $('*[data-original-title={}]').trigger('click')".format(q_root))
        except sel.NoSuchElementException:
            try:
                sel.element("//button[@title={}]".format(q_root))
                sel.execute_script(
                    "return $('button[title={}]').trigger('click')".format(q_root))
            except sel.NoSuchElementException:
                try:
                    sel.element("//button[contains(@title, {})]".format(q_root))
                    sel.execute_script(
                        "return $('button:contains({})').trigger('click')".format(q_root))
                except sel.NoSuchElementException:
                    # The view selection buttons?
                    sel.click("//li/a[@title={}]/*[self::i or self::img]/../..".format(q_root))

    if not invokes_alert:
        sel.wait_for_ajax()
    return True
コード例 #15
0
 def data(self):
     result = []
     for row in sel.elements("./div/table/tbody/tr/td", root=self.root):
         # Regular expressions? Boring.
         desc, date = sel.text(row).encode("utf-8").strip().rsplit("\n", 1)
         date = date.split(":", 1)[-1].strip()
         date = parsetime.from_iso_with_utc(date)
         url_source = sel.element("./..", root=row).get_attribute("onclick")
         getter_script = re.sub(r"^window.location\s*=\s*([^;]+;)", "return \\1", url_source)
         try:
             url = sel.execute_script(getter_script)
         except sel.WebDriverException:
             url = None
         result.append((desc, date, url))
     return result
コード例 #16
0
ファイル: dashboard.py プロジェクト: petrblaho/cfme_tests
 def data(self):
     result = []
     for row in sel.elements("./div/table/tbody/tr/td", root=self.root):
         # Regular expressions? Boring.
         desc, date = sel.text(row).encode("utf-8").strip().rsplit("\n", 1)
         date = date.split(":", 1)[-1].strip()
         date = parsetime.from_iso_with_utc(date)
         url_source = sel.element("./..", root=row).get_attribute("onclick")
         getter_script = re.sub(r"^window.location\s*=\s*([^;]+;)", "return \\1", url_source)
         try:
             url = sel.execute_script(getter_script)
         except sel.WebDriverException:
             url = None
         result.append((desc, date, url))
     return result
コード例 #17
0
ファイル: login.py プロジェクト: vprusa/cfme_tests
def _js_auth_fn():
    # In case clicking on login or hitting enter is broken, this can still let you log in
    # This shouldn't be used in automation, though.
    sel.execute_script('miqAjaxAuth();')
コード例 #18
0
ファイル: ui.py プロジェクト: anewmanRH/cfme_tests
    def pre_navigate(self, _tries=0):
        if _tries > 2:
            # Need at least three tries:
            # 1: login_admin handles an alert or CannotContinueWithNavigation appears.
            # 2: Everything should work. If not, NavigationError.
            raise exceptions.NavigationError(self.obj._name)

        ensure_browser_open()

        # check for MiqQE javascript patch on first try and patch the appliance if necessary
        from utils.appliance import current_miqqe_version
        if store.current_appliance.miqqe_version != current_miqqe_version:
            store.current_appliance.patch_with_miqqe()
            browser().quit()
            self.go(_tries)

        try:
            execute_script('miqSparkleOff();')
        except:  # Diaper OK (mfalesni)
            # miqSparkleOff undefined, so it's definitely off.
            pass

        # Check if the page is blocked with blocker_div. If yes, let's headshot the browser right
        # here
        if (
                is_displayed("//div[@id='blocker_div' or @id='notification']", _no_deeper=True)
                or is_displayed(".modal-backdrop.fade.in", _no_deeper=True)):
            logger.warning("Page was blocked with blocker div on start of navigation, recycling.")
            quit()
            self.go(_tries)

        # Check if modal window is displayed
        if (is_displayed(
                "//div[contains(@class, 'modal-dialog') and contains(@class, 'modal-lg')]",
                _no_deeper=True)):
            logger.warning("Modal window was open; closing the window")
            click("//button[contains(@class, 'close') and contains(@data-dismiss, 'modal')]")

        # Check if jQuery present
        try:
            execute_script("jQuery")
        except Exception as e:
            if "jQuery" not in str(e):
                logger.error("Checked for jQuery but got something different.")
                logger.exception(e)
            # Restart some workers
            logger.warning("Restarting UI and VimBroker workers!")
            with store.current_appliance.ssh_client as ssh:
                # Blow off the Vim brokers and UI workers
                ssh.run_rails_command("\"(MiqVimBrokerWorker.all + MiqUiWorker.all).each &:kill\"")
            logger.info("Waiting for web UI to come back alive.")
            sleep(10)   # Give it some rest
            store.current_appliance.wait_for_web_ui()
            quit()
            ensure_browser_open()
            self.go(_tries)

        # Same with rails errors
        rails_e = get_rails_error()
        if rails_e is not None:
            logger.warning("Page was blocked by rails error, renavigating.")
            logger.error(rails_e)
            # RHEL7 top does not know -M and -a
            logger.debug('Top CPU consumers:')
            logger.debug(store.current_appliance.ssh_client.run_command(
                'top -c -b -n1 | head -30').output)
            logger.debug('Top Memory consumers:')
            logger.debug(store.current_appliance.ssh_client.run_command(
                'top -c -b -n1 -o "%MEM" | head -30').output)  # noqa
            logger.debug('Managed Providers:')
            logger.debug(store.current_appliance.managed_providers)
            quit()  # Refresh the session, forget loaded summaries, ...
            ensure_browser_open()
            self.go(_tries)
コード例 #19
0
ファイル: menu.py プロジェクト: lukas-bednar/cfme_tests
 def _try_nav(el):
     href = sel.get_attribute(el, 'href')
     sel.execute_script('document.location.href = arguments[0];', href)
     sel.wait_for_ajax()
コード例 #20
0
def _list_events():
    try:
        soutput = sel.execute_script('return tl._bands[0]._eventSource._events._events._a')
        return soutput
    except sel.WebDriverException:
        return []
コード例 #21
0
ファイル: login.py プロジェクト: richardfontana/cfme_tests
def _js_auth_fn():
    # In case clicking on login or hitting enter is broken, this can still let you log in
    # This shouldn't be used in automation, though.
    sel.execute_script('miqAjaxAuth();')
コード例 #22
0
ファイル: menu.py プロジェクト: MattLombana/cfme_tests
 def _try_nav(el):
     href = sel.get_attribute(el, 'href')
     sel.execute_script('document.location.href = arguments[0];', href)
     sel.wait_for_ajax()
コード例 #23
0
ファイル: login.py プロジェクト: seandst/cfme_tests
def _js_auth_fn():
    """
    Convenience internal function to click the login locator submit button.
    """
    sel.execute_script('miqAjaxAuth();')