Beispiel #1
0
def _run_in_all_iframes_internal(code: SelectorCall,
                                 result_evaluator: ResultEvaluator,
                                 error_messages: List[str] = None,
                                 checked_frames=None) -> ProcessingCall:
    error_happened = False
    error_messages = error_messages if error_messages is not None else []
    checked_frames = checked_frames if checked_frames is not None else set()

    result = None
    result_found = False

    try:
        result = code()

        result, result_found = result_evaluator(result)

        if result_found:
            return result, result_found, error_happened, error_messages
    except Exception as e:
        print(e)
        error_messages.append(str(e))
        error_happened = True

    for iframe_element in Element('iframe').element_list():
        if iframe_element in checked_frames:
            continue

        checked_frames.add(iframe_element)

        try:
            get_germanium().switch_to.frame(iframe_element)
        except Exception:
            # it's ok to have switching failing if the iframes are being
            # switcharoeed
            continue

        iframe_result, \
        iframe_result_found, \
        iframe_error_happened, \
        iframe_error_messages = \
            _run_in_all_iframes_internal(code,
                                         result_evaluator,
                                         error_messages,
                                         checked_frames)

        error_happened |= iframe_error_happened

        if iframe_result_found and not result_found:
            return iframe_result, \
                   iframe_result_found, \
                   error_happened, \
                   error_messages

    return result, result_found, error_happened, error_messages
Beispiel #2
0
def run_in_all_iframes(
        code: SelectorCall,
        result_evaluator: ResultEvaluator = None) -> ProcessingCall:
    get_germanium().switch_to.default_content()

    def default_result_evaluator(result):
        return result, result

    if not result_evaluator:
        result_evaluator = default_result_evaluator

    return _run_in_all_iframes_internal(code, result_evaluator)
Beispiel #3
0
def after_scenario(context, scenario):
    if 'fast_live_reload_process' in context:
        context.fast_live_reload_process.kill()
        print("PROCESS KILLED")

    if get_germanium():
        close_browser()
    def authenticate(self,
                     username,
                     password,
                     wait_disappear=True,
                     *argv,
                     **kw):
        """
        Fills in the username and password into the alert.
        If the germanium parameter is not set it will use instead the
        `germanium.static.get_germanium` instance.
        :param wait_disappear: Wait for the alert to not exist anymore.
        :param password:
        :param username:
        :param argv:
        :param kw:
        :return:
        """
        from germanium.static import S, get_germanium
        alert = S(self).element(*argv, **kw)

        wait(lambda: alert.autenticate(username, password) or True, timeout=1)
        get_germanium()._last_alert = None

        if wait_disappear:
            wait(self.not_exists)
    def send_keys(self, text, *argv, **kw):
        """
        Types the given keys into the alert.
        If the germanium parameter is not set it will use instead the
        `germanium.static.get_germanium` instance.
        :param text: The text to type into.
        :param argv:
        :param germanium:
        :param kw:
        :return:
        """
        from germanium.static import S, get_germanium
        alert = S(self).element(*argv, **kw)

        alert.send_keys(text)
        get_germanium()._last_alert = None
    def accept(self, wait_disappear=True, *argv, **kw):
        """
        Accepts the current alert from the germanium instance. If the germanium parameter
        is not set it will use instead the `germanium.static.get_germanium` instance.
        :param wait_disappear: Wait for the alert to not exist anymore.
        :param argv:
        :param germanium:
        :param kw:
        :return:
        """
        from germanium.static import S, get_germanium
        alert = S(self).element(*argv, **kw)

        wait(lambda: alert.accept() or True, timeout=1)
        get_germanium()._last_alert = None

        if wait_disappear:
            wait(self.not_exists)
Beispiel #7
0
def after_scenario(context, scenario):
    context.fast_live_reload_process.kill()
    print("PROCESS KILLED")

    if get_germanium():
        close_browser()