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 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(";"[0])[1] except Exception as e: raise APIHelperError("Failed to retrieve preference value.\n{}".format(e)) close_tab() return value
def create_region_for_url_bar(): """Create region for the right side of the url bar.""" try: hamburger_menu_pattern = NavBar.HAMBURGER_MENU show_history_pattern = LocationBar.HISTORY_DROPMARKER select_location_bar() return RegionUtils.create_region_from_patterns(show_history_pattern, hamburger_menu_pattern, padding_top=20, padding_bottom=20) except FindError: raise APIHelperError("Could not create region for URL bar.")
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() time.sleep(Settings.DEFAULT_UI_DELAY) paste(url) time.sleep(Settings.DEFAULT_UI_DELAY) type(Key.ENTER) except Exception: raise APIHelperError("No active window found, cannot navigate to page.")
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()