def get_pref_value(pref_name): """Returns the value of a provided preference from 'about:config' page. :param pref_name: Preference's name. :return: Preference's value. """ new_tab() select_location_bar() paste("about:config") type(Key.ENTER) time.sleep(Settings.DEFAULT_UI_DELAY) type(Key.SPACE) time.sleep(Settings.DEFAULT_UI_DELAY) paste(pref_name) time.sleep(Settings.DEFAULT_UI_DELAY_LONG) type(Key.TAB) time.sleep(Settings.DEFAULT_UI_DELAY_LONG) try: value = copy_to_clipboard().split("\t")[1] except Exception as e: raise APIHelperError( "Failed to retrieve preference value.\n{}".format(e)) close_tab() return value
def check_preference(pref_name, value): """Check the value for a specific preference. :param pref_name: Preference to be searched. :param value: Preference's value to be checked. :return: None. """ new_tab() select_location_bar() paste("about:config") time.sleep(Settings.DEFAULT_UI_DELAY) type(Key.ENTER) time.sleep(Settings.DEFAULT_UI_DELAY) type(Key.SPACE) time.sleep(Settings.DEFAULT_UI_DELAY) paste(pref_name) time.sleep(Settings.DEFAULT_UI_DELAY_LONG) type(Key.TAB) time.sleep(Settings.DEFAULT_UI_DELAY_LONG) try: retrieved_value = copy_to_clipboard().split("\t")[1] except Exception as e: raise APIHelperError("Failed to retrieve preference value. %s" % e.message) if retrieved_value == value: return True else: return False
def navigate(url): """Navigates, via the location bar, to a given URL. :param url: The string to type into the location bar. :return: None. """ try: select_location_bar() paste(url) time.sleep(Settings.DEFAULT_UI_DELAY_SHORT) type(Key.ENTER) except Exception: raise APIHelperError("No active window found, cannot navigate to page.")
def change_preference(pref_name, value): """Change the value for a specific preference. :param pref_name: Preference to be changed. :param value: Preference's value after the change. :return: None. """ if not isinstance(value, str): value = str(value).lower() try: new_tab() navigate("about:config") time.sleep(Settings.DEFAULT_UI_DELAY_LONG) type(Key.SPACE) time.sleep(Settings.DEFAULT_UI_DELAY) paste(pref_name) time.sleep(Settings.DEFAULT_UI_DELAY) type(Key.TAB) time.sleep(Settings.DEFAULT_UI_DELAY) try: retrieved_value = copy_to_clipboard().split("\t")[1] except Exception: raise APIHelperError("Failed to retrieve preference value.") if retrieved_value == value: logger.debug("Flag is already set to value:" + value) return None else: type(Key.ENTER) if not (value == "true" or value == "false"): try: paste(value) type(Key.ENTER) except FindError: pass close_tab() except Exception: raise APIHelperError( "Could not set value: %s to preference: %s" % (value, pref_name) )
def change_preference(pref_name, value): """Change the value for a specific preference. :param pref_name: Preference to be changed. :param value: Preference's value after the change. :return: None. """ try: new_tab() navigate("about:config") time.sleep(Settings.DEFAULT_UI_DELAY_LONG) type(Key.SPACE) time.sleep(Settings.DEFAULT_UI_DELAY) paste(pref_name) time.sleep(Settings.DEFAULT_UI_DELAY) type(Key.TAB) time.sleep(Settings.DEFAULT_UI_DELAY) try: retrieved_value = copy_to_clipboard() except Exception: raise APIHelperError("Failed to retrieve preference value.") if retrieved_value == value: logger.debug("Flag is already set to value:" + value) return None else: type(Key.ENTER) dialog_box_pattern = Pattern("preference_dialog_icon.png") try: wait(dialog_box_pattern, 3) paste(value) type(Key.ENTER) except FindError: pass close_tab() except Exception: raise APIHelperError( "Could not set value: %s to preference: %s" % (value, pref_name) )
def get_support_info(): """Returns support information as a JSON object from 'about:support' page.""" copy_raw_data_to_clipboard = Pattern( "about_support_copy_raw_data_button.png") new_tab() select_location_bar() paste("about:support") type(Key.ENTER) time.sleep(Settings.DEFAULT_UI_DELAY) try: click(copy_raw_data_to_clipboard) time.sleep(Settings.DEFAULT_UI_DELAY_LONG) json_text = get_clipboard() return json.loads(json_text) except Exception as e: raise APIHelperError( "Failed to retrieve support information value.\n{}".format(e)) finally: close_tab()
def get_telemetry_info(): """Returns telemetry information as a JSON object from 'about:telemetry' page. """ copy_raw_data_to_clipboard_pattern = Pattern( "copy_raw_data_to_clipboard.png") raw_json_pattern = Pattern("raw_json.png") raw_data_pattern = Pattern("raw_data.png") new_tab() paste("about:telemetry") type(Key.ENTER) try: wait(raw_json_pattern, 10) logger.debug("'RAW JSON' button is present on the page.") click(raw_json_pattern) except (FindError, ValueError): raise APIHelperError("'RAW JSON' button not present in the page.") try: wait(raw_data_pattern, 10) logger.debug("'Raw Data' button is present on the page.") click(raw_data_pattern) except (FindError, ValueError): close_tab() raise APIHelperError("'Raw Data' button not present in the page.") try: click(copy_raw_data_to_clipboard_pattern) time.sleep(Settings.DEFAULT_UI_DELAY) json_text = get_clipboard() return json.loads(json_text) except Exception: raise APIHelperError( "Failed to retrieve raw message information value.") finally: close_tab()