Beispiel #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
Beispiel #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