def is_blocked(bug_id): """Checks if a Github issue/Bugzilla bug is blocked or not.""" try: if "issue_" in bug_id: bug = get_github_issue(bug_id) if bug is None: return True if bug.state == "closed": return False else: if OSHelper.get_os() in bug.title: return True return False else: bug = get_bugzilla_bug(bug_id) if bug is None: return True if bug.status in ["CLOSED", "RESOLVED"]: return False else: if bugzilla_os[OSHelper.get_os(). value] == bug.op_sys or bug.platform in [ "All", "Unspecified" ]: return True return False except BugManagerError as e: logger.error(str(e)) return True
def open_about_firefox(): """Open the 'About Firefox' window.""" if OSHelper.get_os() == OSPlatform.MAC: type(Key.F3, modifier=KeyModifier.CTRL) type(Key.F2, modifier=KeyModifier.CTRL) time.sleep(0.5) type(Key.RIGHT) type(Key.DOWN) type(Key.DOWN) type(Key.ENTER) elif OSHelper.get_os() == OSPlatform.WINDOWS: type(Key.ALT) if args.locale != "ar": type(Key.LEFT) else: type(Key.RIGHT) type(Key.ENTER) type(Key.UP) type(Key.ENTER) else: type(Key.F10) time.sleep(Settings.DEFAULT_UI_DELAY_SHORT) if args.locale != "ar": type(Key.LEFT) else: type(Key.RIGHT) type(Key.UP) type(Key.ENTER)
def get_local_firefox_path() -> str or None: """Checks if Firefox is installed on your machine.""" paths = { "osx": [ "/Applications/Firefox.app/Contents/MacOS/firefox", "/Applications/Firefox Developer Edition.app/Contents/MacOS/firefox", "/Applications/Firefox Nightly.app/Contents/MacOS/firefox", ], "win": [ "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe", "C:\\Program Files (x86)\\Firefox Developer Edition\\firefox.exe", "C:\\Program Files (x86)\\Nightly\\firefox.exe", "C:\\Program Files\\Mozilla Firefox\\firefox.exe", "C:\\Program Files\\Firefox Developer Edition\\firefox.exe", "C:\\Program Files\\Nightly\\firefox.exe", ], "linux": ["/usr/bin/firefox", "/usr/lib/firefox/firefox"], } if OSHelper.is_windows(): paths["win"].append(PathManager.get_win_environment_path()) for path in paths[OSHelper.get_os().value]: if os.path.exists(path): return path return None
def generate_test_plan_name(firefox_version: str): """ :param firefox_version: actual version of Firefox :return: name of the test plan name of the test run is generated based on the OS , date and build number this method can be be improved to add more details """ test_plan_name = '[Firefox %s][%s]Iris Test Run %s' % ( firefox_version, OSHelper.get_os().capitalize(), date.today()) logger.debug('Creating Test Plan', test_plan_name) return test_plan_name
def select_location_bar_option(option_number): """Select option from the location bar menu. :param option_number: Option number. :return: None. """ if OSHelper.get_os() == OSPlatform.WINDOWS: for i in range(option_number + 1): type(Key.DOWN) type(Key.ENTER) else: for i in range(option_number - 1): type(Key.DOWN) type(Key.ENTER)
def __init__( self, app, total_tests_run, passed_tests, failed_tests, skipped_tests, errors, total_time, failures, ): self.platform = OSHelper.get_os().value self.app = app self.total_tests_run = total_tests_run self.failed_tests = failed_tests self.passed_tests = passed_tests self.skipped_tests = skipped_tests self.error_tests = errors self.total_duration = total_time self.failures = failures
def get_rule_for_channel(channel, current_version): """ :param channel: Firefox channel. :param current_version: Current Firefox version. :return: Channel's list of rules. """ rules = get_update_rules() if rules is None: return None result_list = [ x for x in rules if x["channel"] == channel and OSHelper.get_os() in x["os"] and check_version(current_version, x["starting_condition"]) ] if len(result_list) == 0: return None elif len(result_list) > 1: logger.warning("Multiple rules for '{}' channel".format(channel)) return result_list[0] return result_list[0]
def pytest_runtest_setup(self, item): BaseTarget.pytest_runtest_setup(self, item) if OSHelper.is_mac(): mouse_reset() if item.name == 'run' and not core_args.override: skip_reason_list = [] values = item.own_markers[0].kwargs is_disabled = 'enabled' in values and not values.get( 'enabled') and not core_args.override is_excluded = 'exclude' in values and OSHelper.get_os( ) in values.get('exclude') incorrect_locale = 'locale' in values and core_args.locale not in values.get( 'locale') incorrect_platform = 'platform' in values and OSHelper.get_os( ) not in values.get('platform') fx_version = self.values.get('fx_version') incorrect_fx_version = 'fx_version' in values and not check_version( fx_version, values.get('fx_version')) if is_disabled: skip_reason_list.append('Test is disabled') if is_excluded: skip_reason_list.append('Test is excluded for {}'.format( OSHelper.get_os())) if 'blocked_by' in values: bug_id = '' platform = OSHelper.get_os() if type(values.get('blocked_by')) is str: bug_id = values.get('blocked_by') elif type(values.get('blocked_by')) is dict: try: bug_id = values.get('blocked_by')['id'] platform = values.get('blocked_by')['platform'] except KeyError as e: logger.debug('Missing key in blocked_by field: %s' % e) logger.debug('Looking up bug #%s...' % bug_id) blocked_platform = OSHelper.get_os() in platform logger.debug('Test has blocking issue: %s' % is_blocked(bug_id)) logger.debug('Test is blocked on this platform: %s' % blocked_platform) if is_blocked(bug_id) and blocked_platform: skip_reason_list.append( 'Test is blocked by [{}] on this platform.'.format( bug_id)) if incorrect_locale: skip_reason_list.append( 'Test doesn\'t support locale [{}]'.format( core_args.locale)) if incorrect_platform: skip_reason_list.append( 'Test doesn\'t support platform [{}]'.format( OSHelper.get_os())) if incorrect_fx_version: skip_reason_list.append( 'Test doesn\'t support Firefox version [{}]'.format( fx_version)) if len(skip_reason_list) > 0: logger.info('Test skipped: - [{}]: {} Reason(s): {}'.format( item.nodeid.split(':')[0], values.get('description'), ', '.join(skip_reason_list))) test_instance = (item, 'SKIPPED', None) test_result = create_result_object(test_instance, 0, 0) self.add_test_result(test_result) Target.index += 1 pytest.skip(item)
def convert_test_list(test_list, only_failures=False): """Takes a flat list of test objects and paths and converts to an object that can be serialized as JSON. :param test_list: List of completed tests :param only_failures: If True, only return failed tests :return: """ test_root = os.path.join(PathManager.get_module_dir(), "tests") tests = [] for test in test_list: test_failed = (True if "FAILED" in test.outcome or "ERROR" in test.outcome else False) original_path = str(test.item.__dict__.get("fspath")) try: target_root = original_path.split(test_root)[1] except IndexError: logger.error("Error parsing test list.") logger.error( "Try resetting your PYTHONPATH before your next run, i.e.:") if OSHelper.get_os().value == "win": logger.error("\tsetx PYTHONPATH %CD%") else: logger.error("\texport PYTHONPATH=$PWD") return tests target = target_root.split(os.sep)[1] test_path = target_root.split("%s%s%s" % (os.sep, target, os.sep))[1] parent = tests details = get_test_markers(test.item) for module in test_path.split(os.sep): test_obj = {"name": module.split(".py")[0]} if "py" not in module: module_exists = False for objects in parent: if objects["name"] == module: parent = objects["children"] module_exists = True break if not module_exists: new_parent = test_obj["children"] = [] if only_failures and test_failed: parent.append(test_obj) elif not only_failures: parent.append(test_obj) parent = new_parent else: if test_failed: test_assert = { "error": test.error.lstrip(), "message": test.message.lstrip(), "call_stack": test.traceback + "\n\n ", "code": get_failing_code(test.node_name, int(test.line)), } test_obj["assert"] = test_assert test_obj["result"] = test.outcome test_obj["time"] = test.test_duration debug_image_directory = os.path.join( PathManager.get_current_run_dir(), test_path.split(".py")[0], "debug_images", ) test_obj["debug_image_directory"] = debug_image_directory test_obj["debug_images"] = get_image_names( debug_image_directory) test_obj["description"] = details.get("description") values = {} for i in details: if i != "description": values[i] = details.get(i) test_obj["values"] = values if only_failures and test_failed: parent.append(test_obj) elif not only_failures: parent.append(test_obj) parent = tests return tests
def create_run_log(app): args = get_core_args() meta = { "run_id": PathManager.get_run_id(), "platform": OSHelper.get_os().value, "config": "%s, %s-bit, %s" % (OSHelper.get_os_version(), OSHelper.get_os_bits(), OSHelper.get_processor()), "locale": args.locale, "args": " ".join(sys.argv), "params": vars(args), "log": os.path.join(PathManager.get_current_run_dir(), "iris_log.log"), } values = {} for i in app.values: values[i] = app.values[i] meta["values"] = values meta["iris_version"] = 2.0 try: repo = git.Repo(PathManager.get_module_dir()) meta["iris_repo"] = repo.working_tree_dir try: meta["iris_branch"] = repo.active_branch.name except: # If we're on a detached head, the active_branch is # undefined and raises an exception. This at least # allows the test run to finish meta["iris_branch"] = "detached" meta["iris_branch_head"] = repo.head.object.hexsha except: # Iris is not running in a Git repo, so don't try to # report on non-existent data. meta["iris_repo"] = "n/a" meta["iris_branch"] = "n/a" meta["iris_branch_head"] = "n/a" meta["python_version"] = get_python_version() failed = 0 passed = 0 skipped = 0 errors = 0 for test in app.completed_tests: if test.outcome == "FAILED": failed = failed + 1 if test.outcome == "PASSED": passed = passed + 1 if test.outcome == "SKIPPED": skipped = skipped + 1 if test.outcome == "ERROR": errors = errors + 1 logger.debug("Updating run.json with completed run data.") meta["total"] = len(app.completed_tests) meta["passed"] = passed meta["failed"] = failed meta["skipped"] = skipped meta["errors"] = errors meta["start_time"] = app.start_time meta["end_time"] = app.end_time meta["total_time"] = app.end_time - app.start_time tests = { "all_tests": convert_test_list(app.completed_tests), "failed_tests": convert_test_list(app.completed_tests, only_failures=True), "flaky_tests": app.flaky_tests, } run_file = os.path.join(PathManager.get_current_run_dir(), "run.json") run_file_data = {"meta": meta, "tests": tests} with open(run_file, "w") as f: json.dump(run_file_data, f, sort_keys=True, indent=True)
class Organize(object): NEW_BOOKMARK = Pattern("newbookmark.png") NEW_FOLDER = Pattern("newfolder.png") NEW_SEPARATOR = Pattern("newseparator.png") if OSHelper.get_os() != OSPlatform.MAC: CLOSE = Pattern("orgClose.png")
def pytest_runtest_setup(self, item): BaseTarget.pytest_runtest_setup(self, item) if OSHelper.is_mac(): mouse_reset() if item.name == "run" and not core_args.override: skip_reason_list = [] values = item.own_markers[0].kwargs is_disabled = "enabled" in values and not values.get( "enabled") and not core_args.override is_excluded = "exclude" in values and OSHelper.get_os( ) in values.get("exclude") incorrect_locale = "locale" in values and core_args.locale not in values.get( "locale") incorrect_platform = "platform" in values and OSHelper.get_os( ) not in values.get("platform") fx_version = self.values.get("fx_version") incorrect_fx_version = "fx_version" in values and not check_version( fx_version, values.get("fx_version")) if is_disabled: skip_reason_list.append("Test is disabled") if is_excluded: skip_reason_list.append("Test is excluded for {}".format( OSHelper.get_os())) if "blocked_by" in values: bug_id = "" platform = OSHelper.get_os() if type(values.get("blocked_by")) is str: bug_id = values.get("blocked_by") elif type(values.get("blocked_by")) is dict: try: bug_id = values.get("blocked_by")["id"] platform = values.get("blocked_by")["platform"] except KeyError as e: logger.debug("Missing key in blocked_by field: %s" % e) logger.debug("Looking up bug #%s..." % bug_id) blocked_platform = OSHelper.get_os() in platform logger.debug("Test has blocking issue: %s" % is_blocked(bug_id)) logger.debug("Test is blocked on this platform: %s" % blocked_platform) if is_blocked(bug_id) and blocked_platform: skip_reason_list.append( "Test is blocked by [{}] on this platform.".format( bug_id)) if incorrect_locale: skip_reason_list.append( "Test doesn't support locale [{}]".format( core_args.locale)) if incorrect_platform: skip_reason_list.append( "Test doesn't support platform [{}]".format( OSHelper.get_os())) if incorrect_fx_version: skip_reason_list.append( "Test doesn't support Firefox version [{}]".format( fx_version)) if len(skip_reason_list) > 0: logger.info("Test skipped: - [{}]: {} Reason(s): {}".format( item.nodeid.split(":")[0], values.get("description"), ", ".join(skip_reason_list))) test_instance = (item, "SKIPPED", None) test_result = create_result_object(test_instance, 0, 0) self.add_test_result(test_result) Target.index += 1 pytest.skip(item)
def _get_image_path(caller, image: str) -> str: """Enforce proper location for all Pattern creation. :param caller: Path of calling Python module. :param image: String filename of image. :return: Full path to image on disk. We will look at all possible paths relative to the calling file, with this priority: - current platform locale folder - common locale folder - current platform root - common root Each directory is scanned for four possible file names, depending on resolution. If we find nothing, we will raise an exception. """ module = os.path.split(caller)[1] module_directory = os.path.split(caller)[0] file_name = image.split(".")[0] names = [image, "*****@*****.**" % file_name] if OSHelper.get_os_version() == "win7": os_version = "win7" else: os_version = OSHelper.get_os().value paths = [] current_locale = Settings.locale platform_directory = os.path.join(module_directory, "images", os_version) if current_locale != "": platform_locale_directory = os.path.join(platform_directory, current_locale) for name in names: paths.append(os.path.join(platform_locale_directory, name)) common_directory = os.path.join(module_directory, "images", "common") if current_locale != "": common_locale_directory = os.path.join(common_directory, current_locale) for name in names: paths.append(os.path.join(common_locale_directory, name)) for name in names: paths.append(os.path.join(platform_directory, name)) for name in names: paths.append(os.path.join(common_directory, name)) found = False image_path = None for path in paths: if os.path.exists(path): found = True image_path = path break logger.debug("Module %s requests image %s" % (module, image)) if found: logger.debug("Found %s" % image_path) return image_path else: raise APIHelperError("Image not found")
def get_images_path(): """Returns images directory path.""" return os.path.join("images", OSHelper.get_os().value)