def create_download_dir_capabilities_for_chrome(path_to_download,
                                                    **extensions_files):
        """
        Example use
        | ${capabilities} |	create_download_dir_capabilities_for_chrome	| Artifacts |
        | Open Browser Extension | https://support.spatialkey.com/spatialkey-sample-csv-data/ |	gc | desired_capabilities=${capabilities} |
        | Click Element	 | //a[contains(@href,'sample.csv.zip')] |
        """

        path_to_download_check = validate_create_artifacts_dir(
            path_to_download)

        chrome_options = ChromeOptions()
        prefs = {
            "download.default_directory": path_to_download_check,
            "directory_upgrade": "true"
        }

        chrome_options.add_experimental_option("prefs", prefs)
        chrome_options.add_argument("--disable-web-security")
        for single_extension in extensions_files:
            chrome_options.add_extension(single_extension)

        logger.info("Chrome Capabilities set download dir '" +
                    path_to_download_check + "'")
        return chrome_options.to_capabilities()
コード例 #2
0
    def capture_page_screenshot_extension(prefix="", postfix="", add_time_stamp=True, add_test_case_name=True, add_file_path_to_list="${list of screenshots}",
            output_dir="Artifacts/Screenshots"):
        output_dir_normalized = validate_create_artifacts_dir(output_dir)

        if add_time_stamp:
            current_time = " " + DateTime.get_current_date(result_format="%Y.%m.%d_%H.%M.%S")
        else:
            current_time = ""
        if add_test_case_name:
            test_case_name = bi().get_variable_value("${TEST_NAME}")
        else:
            test_case_name = ""

        output_file = output_dir_normalized + "/" + prefix + test_case_name + postfix + current_time + ".png"
        output_file_normalized = os.path.normpath(output_file)

        # s2l()_current_browser().get_screenshot_as_file(output_file_normalized)
        s2l().capture_page_screenshot(output_file_normalized)

        results = bi().run_keyword_and_return_status("Variable Should Exist", add_file_path_to_list)

        if not results:
            bi()._get_var_name(add_file_path_to_list)
            list_with_files = bi().create_list(output_file_normalized)
            bi().set_test_variable(add_file_path_to_list, list_with_files)
        else:
            list_with_files = bi().create_list(output_file_normalized)
            list_with_files = bi().run_keyword("Combine Lists", add_file_path_to_list, list_with_files)
            bi().set_test_variable(add_file_path_to_list, list_with_files)

        return output_file_normalized
    def create_download_dir_profile_for_firefox(path_to_download,
                                                mime_types_file=None,
                                                *extensions_files):
        """
        Example use
        | ${profile} | Create Download Dir Profile For Firefox | Artifacts | Resources/mimeTypes.rdf | Resources/webdriver_element_locator-2.0-fx.xpi | Resources/selenium_ide-2.9.1-fx.xpi |
        | Open Browser Extension | https://support.spatialkey.com/spatialkey-sample-csv-data/ | ff_profile_dir=${profile} |
        | Click Element | //a[contains(@href,'sample.csv.zip')]  |
        """
        path_to_download_check = validate_create_artifacts_dir(
            path_to_download)

        fp = FirefoxProfile()
        fp.set_preference("browser.download.folderList", 2)
        fp.set_preference("browser.download.manager.showWhenStarting", False)
        fp.set_preference("browser.download.manager.alertOnEXEOpen", False)
        fp.set_preference("browser.download.dir", path_to_download_check)
        fp.set_preference("xpinstall.signatures.required", False)
        fp.set_preference("browser.helperApps.alwaysAsk.force", False)
        fp.set_preference(
            "browser.helperApps.neverAsk.saveToDisk",
            "application/msword;application/csv;text/csv;image/png;image/jpeg;application/pdf;text/html;text/plain;application/octet-stream"
        )
        fp.set_preference("pdfjs.disabled", True)
        fp.update_preferences()
        for single_extension in extensions_files:
            fp.add_extension(single_extension)
        if mime_types_file is not None:
            from shutil import copy2
            copy2(os.path.normpath(mime_types_file), fp.profile_dir)
        logger.info("Firefox Profile Created in dir '" + fp.profile_dir + "'")
        return fp.profile_dir
コード例 #4
0
    def log_variable_to_file(name,
                             comment="",
                             output_file="Artifacts/variables.csv"):
        log_file = validate_create_artifacts_dir(output_file)
        logger.debug("Log to file " + log_file)
        fieldnames = [
            'Time', 'Test Case Name', 'Variable Name', 'Variable Value',
            'Comment'
        ]
        current_time = DateTime.get_current_date(
            result_format="%Y.%m.%d %H:%M:%S")
        test_case_name = str(bi().get_variable_value("${TEST_NAME}"))
        suite_name = str(bi().get_variable_value("${SUITE_NAME}"))
        variable_value = name

        # TODO
        # get variable name is not working
        # variable_name = _Variables._get_var_name(bi(),str(name))
        # bi().get_variable_value("${" + variable_name + "}", "Missing!!!")

        with open(log_file, 'a') as csv_file:
            writer_csv = csv.writer(csv_file, dialect='excel')
            if os.stat(log_file).st_size < 10:
                writer_csv.writerow(fieldnames)
            writer_csv.writerow([
                current_time, suite_name + "." + test_case_name, name,
                variable_value, comment
            ])
    def create_download_dir_profile_for_firefox(path_to_download, mime_types_file=None, *extensions_files):
        """
        Example use
        | ${profile} | Create Download Dir Profile For Firefox | Artifacts | Resources/mimeTypes.rdf | Resources/webdriver_element_locator-2.0-fx.xpi | Resources/selenium_ide-2.9.1-fx.xpi |
        | Open Browser Extension | https://support.spatialkey.com/spatialkey-sample-csv-data/ | ff_profile_dir=${profile} |
        | Click Element | //a[contains(@href,'sample.csv.zip')]  |
        """
        path_to_download_check = validate_create_artifacts_dir(path_to_download)

        fp = FirefoxProfile()
        fp.set_preference("browser.download.folderList", 2)
        fp.set_preference("browser.download.manager.showWhenStarting", False)
        fp.set_preference("browser.download.manager.alertOnEXEOpen", False)
        fp.set_preference("browser.download.dir", path_to_download_check)
        fp.set_preference("xpinstall.signatures.required", False)
        fp.set_preference("browser.helperApps.alwaysAsk.force", False)
        fp.set_preference("browser.helperApps.neverAsk.saveToDisk",
            "application/msword;application/csv;text/csv;image/png;image/jpeg;application/pdf;text/html;text/plain;application/octet-stream")
        fp.set_preference("pdfjs.disabled", True)
        fp.update_preferences()
        for single_extension in extensions_files:
            fp.add_extension(single_extension)
        if mime_types_file is not None:
            from shutil import copy2
            copy2(os.path.normpath(mime_types_file), fp.profile_dir)
        logger.info("Firefox Profile Created in dir '" + fp.profile_dir + "'")
        return fp.profile_dir
    def capture_page_screenshot_extension(prefix="", postfix="", add_time_stamp=True, add_test_case_name=True, add_file_path_to_list="${list of screenshots}",
            output_dir="Artifacts/Screenshots"):
        output_dir_normalized = validate_create_artifacts_dir(output_dir)

        if add_time_stamp:
            current_time = " " + DateTime.get_current_date(result_format="%Y.%m.%d_%H.%M.%S")
        else:
            current_time = ""
        if add_test_case_name:
            test_case_name = bi().get_variable_value("${TEST_NAME}")
        else:
            test_case_name = ""

        output_file = output_dir_normalized + "/" + prefix + test_case_name + postfix + current_time + ".png"
        output_file_normalized = os.path.normpath(output_file)

        # s2l()_current_browser().get_screenshot_as_file(output_file_normalized)
        s2l().capture_page_screenshot(output_file_normalized)

        results = bi().run_keyword_and_return_status("Variable Should Exist", add_file_path_to_list)

        if not results:
            bi()._get_var_name(add_file_path_to_list)
            list_with_files = bi().create_list(output_file_normalized)
            bi().set_test_variable(add_file_path_to_list, list_with_files)
        else:
            list_with_files = bi().create_list(output_file_normalized)
            list_with_files = bi().run_keyword("Combine Lists", add_file_path_to_list, list_with_files)
            bi().set_test_variable(add_file_path_to_list, list_with_files)

        return output_file_normalized
    def log_variable_to_file(self,
                             name,
                             comment="",
                             output_file="Artifacts/variables.csv"):
        log_file = validate_create_artifacts_dir(output_file)
        logger.debug("Log to file " + log_file)
        fieldnames = [
            "Time",
            "Test Case Name",
            "Variable Name",
            "Variable Value",
            "Comment",
        ]
        current_time = DateTime.get_current_date(
            result_format="%Y.%m.%d %H:%M:%S")
        test_case_name = str(bi().get_variable_value("${TEST_NAME}"))
        suite_name = str(bi().get_variable_value("${SUITE_NAME}"))
        variable_value = name

        with open(log_file, "a") as csv_file:
            writer_csv = csv.writer(csv_file, dialect="excel")
            if os.stat(log_file).st_size < 10:
                writer_csv.writerow(fieldnames)
            writer_csv.writerow([
                current_time,
                suite_name + "." + test_case_name,
                name,
                variable_value,
                comment,
            ])
    def log_variable_to_file(name, comment="", output_file="Artifacts/variables.csv"):
        log_file = validate_create_artifacts_dir(output_file)
        logger.debug("Log to file " + log_file)
        fieldnames = ['Time', 'Test Case Name', 'Variable Name', 'Variable Value', 'Comment']
        current_time = DateTime.get_current_date(result_format="%Y.%m.%d %H:%M:%S")
        test_case_name = str(bi().get_variable_value("${TEST_NAME}"))
        suite_name = str(bi().get_variable_value("${SUITE_NAME}"))
        variable_value = name

        # TODO
        # get variable name is not working
        # variable_name = _Variables._get_var_name(bi(),str(name))
        # bi().get_variable_value("${" + variable_name + "}", "Missing!!!")

        with open(log_file, 'ab') as csv_file:
            writer_csv = csv.writer(csv_file, dialect='excel')
            if os.stat(log_file).st_size < 10:
                writer_csv.writerow(fieldnames)
            writer_csv.writerow([current_time, suite_name + "." + test_case_name, name, variable_value, comment])
    def create_download_dir_capabilities_for_chrome(path_to_download, **extensions_files):
        """
        Example use
        | ${capabilities} |	create_download_dir_capabilities_for_chrome	| Artifacts |
        | Open Browser Extension | https://support.spatialkey.com/spatialkey-sample-csv-data/ |	gc | desired_capabilities=${capabilities} |
        | Click Element	 | //a[contains(@href,'sample.csv.zip')] |
        """

        path_to_download_check = validate_create_artifacts_dir(path_to_download)

        chrome_options = ChromeOptions()
        prefs = {"download.default_directory": path_to_download_check, "directory_upgrade": "true"}

        chrome_options.add_experimental_option("prefs", prefs)
        chrome_options.add_argument("--disable-web-security")
        for single_extension in extensions_files:
            chrome_options.add_extension(single_extension)

        logger.info("Chrome Capabilities set download dir '" + path_to_download_check + "'")
        return chrome_options.to_capabilities()
コード例 #10
0
 def csv_set_output_file(self, file_name="Artifacts/output.csv"):
     self.OUTPUT_FILE_CSV = validate_create_artifacts_dir(file_name)
コード例 #11
0
 def _append_to_file(self, text):
     full_log_file_path = validate_create_artifacts_dir(
         self.OUTPUT_FILE_LOG_SQL)
     mode = 'a' if os.path.exists(full_log_file_path) else 'w'
     with open(full_log_file_path, mode) as output:
         output.write(text)
コード例 #12
0
 def set_sql_log_output_file(self,
                             path="Artifacts/log_of_sql_execution.sql"):
     self.OUTPUT_FILE_LOG_SQL = validate_create_artifacts_dir(path)
コード例 #13
0
 def csv_set_output_file(self, file_name="Artifacts/output.csv"):
     self.OUTPUT_FILE_CSV = validate_create_artifacts_dir(file_name)
コード例 #14
0
 def _append_to_file(self, text):
     full_log_file_path = validate_create_artifacts_dir(self.OUTPUT_FILE_LOG_SQL)
     mode = 'a' if os.path.exists(full_log_file_path) else 'w'
     with open(full_log_file_path, mode) as output:
         output.write(text)
コード例 #15
0
 def set_sql_log_output_file(self, path="Artifacts/log_of_sql_execution.sql"):
     self.OUTPUT_FILE_LOG_SQL = validate_create_artifacts_dir(path)
コード例 #16
0
 def _append_to_file(self, text):
     full_log_file_path = validate_create_artifacts_dir(self.OUTPUT_FILE_LOG_SQL)
     modeFile = "a" if os.path.exists(full_log_file_path) else "w"
     with codecs.open(full_log_file_path, modeFile, "utf-8") as output:
         output.write(text)