Пример #1
0
    def __manual_page_check(self, *args):
        if not args:
            instructions = DEFAULT_VALIDATION_MESSAGE  # self.verify()
        else:
            instructions = str(args[0])
            if len(args) > 1:
                pass

        question = "Approve?"  # self.verify("")
        if instructions and "?" not in instructions:
            question = instructions + " <> Approve?"
        elif instructions and "?" in instructions:
            question = instructions

        wait_time_before_verify = WAIT_TIME_BEFORE_VERIFY
        if self.verify_delay:
            wait_time_before_verify = float(self.verify_delay)
        # Allow a moment to see the full page before the dialog box pops up
        time.sleep(wait_time_before_verify)

        use_jqc = False
        self.wait_for_ready_state_complete()
        if js_utils.is_jquery_confirm_activated(self.driver):
            use_jqc = True
        else:
            js_utils.activate_jquery_confirm(self.driver)
            get_jqc = None
            try:
                get_jqc = self.execute_script("return jconfirm")
                get_jqc = get_jqc["instances"]
                use_jqc = True
            except Exception:
                use_jqc = False

        if use_jqc:
            # Use the jquery_confirm library for manual page checks
            self.__jq_confirm_dialog(question)
            time.sleep(0.02)
            waiting_for_response = True
            while waiting_for_response:
                time.sleep(0.05)
                jqc_open = self.execute_script(
                    "return jconfirm.instances.length")
                if str(jqc_open) == "0":
                    break
            time.sleep(0.1)
            status = None
            try:
                status = self.execute_script("return $jqc_status")
            except Exception:
                status = "Failure!"
                pre_status = self.execute_script(
                    "return jconfirm.lastClicked.hasClass('btn-green')")
                if pre_status:
                    status = "Success!"
        else:
            # Fallback to plain js confirm dialogs if can't load jquery_confirm
            if self.browser == 'ie':
                text = self.execute_script(
                    '''if(confirm("%s")){return "Success!"}
                    else{return "Failure!"}''' % question)
            elif self.browser == 'chrome':
                self.execute_script('''if(confirm("%s"))
                    {window.master_qa_result="Success!"}
                    else{window.master_qa_result="Failure!"}''' % question)
                time.sleep(0.05)
                self.__wait_for_special_alert_absent()
                text = self.execute_script('return window.master_qa_result')
            else:
                try:
                    self.execute_script('''if(confirm("%s"))
                        {window.master_qa_result="Success!"}
                        else{window.master_qa_result="Failure!"}''' % question)
                except WebDriverException:
                    # Fix for https://github.com/mozilla/geckodriver/issues/431
                    pass
                time.sleep(0.05)
                self.__wait_for_special_alert_absent()
                text = self.execute_script('return window.master_qa_result')
            status = text

        self.manual_check_count += 1
        try:
            current_url = self.driver.current_url
        except Exception:
            current_url = self.execute_script("return document.URL")
        if "Success!" in str(status):
            self.manual_check_successes += 1
            self.page_results_list.append(
                '"%s","%s","%s","%s","%s","%s","%s","%s"' %
                (self.manual_check_count, "Success", "-", current_url,
                 self.browser, self.__get_timestamp()[:-3], instructions, "*"))
            return 1
        else:
            bad_page_name = "failed_check_%s.png" % self.manual_check_count
            self.save_screenshot(bad_page_name, folder=LATEST_REPORT_DIR)
            self.page_results_list.append(
                '"%s","%s","%s","%s","%s","%s","%s","%s"' %
                (self.manual_check_count, "FAILED!",
                 bad_page_name, current_url, self.browser,
                 self.__get_timestamp()[:-3], instructions, "*"))
            return 0
Пример #2
0
    def manual_page_check(self, *args):
        if not args:
            instructions = DEFAULT_VALIDATION_MESSAGE  # self.verify()
        else:
            instructions = str(args[0])
            if len(args) > 1:
                pass

        question = "Approve?"  # self.verify("")
        if instructions and "?" not in instructions:
            question = instructions + " <> Approve?"
        elif instructions and "?" in instructions:
            question = instructions

        use_jqc = False
        self.wait_for_ready_state_complete()
        if js_utils.is_jquery_confirm_activated(self.driver):
            use_jqc = True
        else:
            js_utils.activate_jquery_confirm(self.driver)
            get_jqc = None
            try:
                get_jqc = self.execute_script("return jconfirm")
                get_jqc = get_jqc["instances"]
                use_jqc = True
            except Exception:
                use_jqc = False

        if use_jqc:
            wait_time_before_verify = WAIT_TIME_BEFORE_VERIFY
            if self.verify_delay:
                wait_time_before_verify = float(self.verify_delay)
            # Allow a moment to see the full page before the dialog box pops up
            time.sleep(wait_time_before_verify)

            # Use the jquery_confirm library for manual page checks
            self.jq_confirm_dialog(question)
            time.sleep(0.02)
            waiting_for_response = True
            while waiting_for_response:
                time.sleep(0.05)
                jqc_open = self.execute_script(
                    "return jconfirm.instances.length")
                if str(jqc_open) == "0":
                    break
            time.sleep(0.1)
            status = None
            try:
                status = self.execute_script("return $jqc_status")
            except Exception:
                status = "Failure!"
                pre_status = self.execute_script(
                    "return jconfirm.lastClicked.hasClass('btn-green')")
                if pre_status:
                    status = "Success!"
        else:
            # Fallback to plain js confirm dialogs if can't load jquery_confirm
            if self.browser == 'ie':
                text = self.execute_script(
                    '''if(confirm("%s")){return "Success!"}
                    else{return "Failure!"}''' % question)
            elif self.browser == 'chrome':
                self.execute_script('''if(confirm("%s"))
                    {window.master_qa_result="Success!"}
                    else{window.master_qa_result="Failure!"}''' % question)
                time.sleep(0.05)
                self.wait_for_special_alert_absent()
                text = self.execute_script('return window.master_qa_result')
            else:
                try:
                    self.execute_script(
                        '''if(confirm("%s"))
                        {window.master_qa_result="Success!"}
                        else{window.master_qa_result="Failure!"}''' % question)
                except WebDriverException:
                    # Fix for https://github.com/mozilla/geckodriver/issues/431
                    pass
                time.sleep(0.05)
                self.wait_for_special_alert_absent()
                text = self.execute_script('return window.master_qa_result')
            status = text

        self.manual_check_count += 1
        try:
            current_url = self.driver.current_url
        except Exception:
            current_url = self.execute_script("return document.URL")
        if "Success!" in str(status):
            self.manual_check_successes += 1
            self.page_results_list.append(
                '"%s","%s","%s","%s","%s","%s","%s","%s"' % (
                    self.manual_check_count,
                    "Success",
                    "-",
                    current_url,
                    self.browser,
                    self.get_timestamp()[:-3],
                    instructions,
                    "*"))
            return 1
        else:
            bad_page_name = "failed_check_%s.png" % self.manual_check_count
            self.save_screenshot(bad_page_name, folder=LATEST_REPORT_DIR)
            self.page_results_list.append(
                '"%s","%s","%s","%s","%s","%s","%s","%s"' % (
                    self.manual_check_count,
                    "FAILED!",
                    bad_page_name,
                    current_url,
                    self.browser,
                    self.get_timestamp()[:-3],
                    instructions,
                    "*"))
            return 0
Пример #3
0
def jquery_confirm_button_dialog(driver, message, buttons, options=None):
    js_utils.activate_jquery_confirm(driver)
    # These defaults will be overwritten later if set
    theme = constants.JqueryConfirm.DEFAULT_THEME
    border_color = constants.JqueryConfirm.DEFAULT_COLOR
    width = constants.JqueryConfirm.DEFAULT_WIDTH
    if options:
        for option in options:
            if option[0].lower() == "theme":
                theme = option[1]
            elif option[0].lower() == "color":
                border_color = option[1]
            elif option[0].lower() == "width":
                width = option[1]
            else:
                raise Exception('Unknown option: "%s"' % option[0])
    if not message:
        message = ""
    key_row = ""
    if len(buttons) == 1:  # There's only one button as an option
        key_row = "keys: ['enter', 'y', '1'],"  # Shortcut: "Enter","Y","1"
    b_html = """button_%s: {
        btnClass: 'btn-%s',
        text: '<b>%s</b>',
        %s
        action: function(){
            jqc_status = '%s';
            $jqc_status = jqc_status;
            jconfirm.lastButtonText = jqc_status;
        }
    },"""
    all_buttons = ""
    btn_count = 0
    for button in buttons:
        btn_count += 1
        text = button[0]
        text = js_utils.escape_quotes_if_needed(text)
        if len(buttons) > 1 and text.lower() == "yes":
            key_row = "keys: ['y'],"
            if btn_count < 10:
                key_row = "keys: ['y', '%s']," % btn_count
        elif len(buttons) > 1 and text.lower() == "no":
            key_row = "keys: ['n'],"
            if btn_count < 10:
                key_row = "keys: ['n', '%s']," % btn_count
        elif len(buttons) > 1:
            if btn_count < 10:
                key_row = "keys: ['%s']," % btn_count
        color = button[1]
        if not color:
            color = "blue"
        new_button = b_html % (btn_count, color, text, key_row, text)
        all_buttons += new_button

    content = '<div></div><font color="#0066ee">%s</font>' % (message)
    content = js_utils.escape_quotes_if_needed(content)
    overlay_opacity = "0.32"
    if theme.lower() == "supervan":
        overlay_opacity = "0.56"
    if theme.lower() == "bootstrap":
        overlay_opacity = "0.64"
    if theme.lower() == "modern":
        overlay_opacity = "0.5"
    if theme.lower() == "material":
        overlay_opacity = "0.4"
    jqcd = """jconfirm({
            boxWidth: '%s',
            useBootstrap: false,
            containerFluid: true,
            bgOpacity: %s,
            type: '%s',
            theme: '%s',
            animationBounce: 1,
            typeAnimated: true,
            animation: 'scale',
            draggable: true,
            dragWindowGap: 1,
            container: 'body',
            title: '%s',
            content: '<div></div>',
            buttons: {
                %s
            }
        });""" % (
        width,
        overlay_opacity,
        border_color,
        theme,
        content,
        all_buttons,
    )
    driver.execute_script(jqcd)
Пример #4
0
def jquery_confirm_full_dialog(driver, message, buttons, options=None):
    js_utils.activate_jquery_confirm(driver)
    # These defaults will be overwritten later if set
    theme = constants.JqueryConfirm.DEFAULT_THEME
    border_color = constants.JqueryConfirm.DEFAULT_COLOR
    width = constants.JqueryConfirm.DEFAULT_WIDTH

    if not message:
        message = ""
    btn_count = 0
    b_html = """button_%s: {
            btnClass: 'btn-%s',
            text: '%s',
            action: function(){
            jqc_input = this.$content.find('.jqc_input').val();
            $jqc_input = this.$content.find('.jqc_input').val();
            jconfirm.lastInputText = jqc_input;
            $jqc_status = '%s';
            }
        },"""
    b1_html = """formSubmit: {
            btnClass: 'btn-%s',
            text: '%s',
            action: function(){
            jqc_input = this.$content.find('.jqc_input').val();
            $jqc_input = this.$content.find('.jqc_input').val();
            jconfirm.lastInputText = jqc_input;
            jqc_status = '%s';
            $jqc_status = jqc_status;
            jconfirm.lastButtonText = jqc_status;
            }
        },"""
    one_button_trigger = ""
    if len(buttons) == 1:
        # If there's only one button, allow form submit with "Enter/Return"
        one_button_trigger = "jc.$$formSubmit.trigger('click');"
    all_buttons = ""
    for button in buttons:
        text = button[0]
        text = js_utils.escape_quotes_if_needed(text)
        color = button[1]
        if not color:
            color = "blue"
        btn_count += 1
        if len(buttons) == 1:
            new_button = b1_html % (color, text, text)
        else:
            new_button = b_html % (btn_count, color, text, text)
        all_buttons += new_button
    if options:
        for option in options:
            if option[0].lower() == "theme":
                theme = option[1]
            elif option[0].lower() == "color":
                border_color = option[1]
            elif option[0].lower() == "width":
                width = option[1]
            else:
                raise Exception('Unknown option: "%s"' % option[0])

    content = '<div></div><font color="#0066ee">%s</font>' % (message)
    content = js_utils.escape_quotes_if_needed(content)
    overlay_opacity = "0.32"
    if theme.lower() == "supervan":
        overlay_opacity = "0.56"
    if theme.lower() == "bootstrap":
        overlay_opacity = "0.64"
    if theme.lower() == "modern":
        overlay_opacity = "0.5"
    if theme.lower() == "material":
        overlay_opacity = "0.4"
    jqcd = """jconfirm({
            boxWidth: '%s',
            useBootstrap: false,
            containerFluid: true,
            bgOpacity: %s,
            type: '%s',
            theme: '%s',
            animationBounce: 1,
            typeAnimated: true,
            animation: 'scale',
            draggable: true,
            dragWindowGap: 1,
            container: 'body',
            title: '%s',
            content: '<div></div>' +
            %s,
            buttons: {
                %s
            },
            onContentReady: function () {
            var jc = this;
            this.$content.find('form.jqc_form').on('submit', function (e) {
                // User submits the form by pressing "Enter" in the field
                e.preventDefault();
                %s
            });
            }
        });""" % (
        width,
        overlay_opacity,
        border_color,
        theme,
        content,
        form_code,
        all_buttons,
        one_button_trigger,
    )
    driver.execute_script(jqcd)
Пример #5
0
def jquery_confirm_text_dialog(driver, message, button=None, options=None):
    js_utils.activate_jquery_confirm(driver)
    # These defaults will be overwritten later if set
    theme = constants.JqueryConfirm.DEFAULT_THEME
    border_color = constants.JqueryConfirm.DEFAULT_COLOR
    width = constants.JqueryConfirm.DEFAULT_WIDTH

    if not message:
        message = ""
    if button:
        if not type(button) is list and not type(button) is tuple:
            raise Exception('"button" should be a (text, color) tuple!')
        if len(button) != 2:
            raise Exception('"button" should be a (text, color) tuple!')
    else:
        button = ("Submit", "blue")
    if options:
        for option in options:
            if option[0].lower() == "theme":
                theme = option[1]
            elif option[0].lower() == "color":
                border_color = option[1]
            elif option[0].lower() == "width":
                width = option[1]
            else:
                raise Exception('Unknown option: "%s"' % option[0])
    btn_text = button[0]
    btn_color = button[1]
    if not btn_color:
        btn_color = "blue"
    content = '<div></div><font color="#0066ee">%s</font>' % (message)
    content = js_utils.escape_quotes_if_needed(content)
    overlay_opacity = "0.32"
    if theme.lower() == "supervan":
        overlay_opacity = "0.56"
    if theme.lower() == "bootstrap":
        overlay_opacity = "0.64"
    if theme.lower() == "modern":
        overlay_opacity = "0.5"
    if theme.lower() == "material":
        overlay_opacity = "0.4"
    jqcd = """jconfirm({
            boxWidth: '%s',
            useBootstrap: false,
            containerFluid: true,
            bgOpacity: %s,
            type: '%s',
            theme: '%s',
            animationBounce: 1,
            typeAnimated: true,
            animation: 'scale',
            draggable: true,
            dragWindowGap: 1,
            container: 'body',
            title: '%s',
            content: '<div></div>' +
            %s,
            buttons: {
                formSubmit: {
                btnClass: 'btn-%s',
                text: '%s',
                action: function () {
                    jqc_input = this.$content.find('.jqc_input').val();
                    $jqc_input = this.$content.find('.jqc_input').val();
                    jconfirm.lastInputText = jqc_input;
                    $jqc_status = '%s';  // There is only one button
                },
            },
            },
            onContentReady: function () {
            var jc = this;
            this.$content.find('form.jqc_form').on('submit', function (e) {
                // User submits the form by pressing "Enter" in the field
                e.preventDefault();
                jc.$$formSubmit.trigger('click');  // Click the button
            });
            }
        });""" % (
        width,
        overlay_opacity,
        border_color,
        theme,
        content,
        form_code,
        btn_color,
        btn_text,
        btn_text,
    )
    driver.execute_script(jqcd)