Exemple #1
0
def get_test_params():
    tests_to_execute = collect_tests()
    pytest_args = []
    if get_core_args().rerun:
        failed_tests_file = os.path.join(PathManager.get_working_dir(), "lastfail.txt")
        tests_dir = os.path.join(PathManager.get_tests_dir(), get_core_args().target)
        failed_tests = []
        with open(failed_tests_file, "r") as f:
            for line in f:
                failed_tests.append(line.rstrip("\n"))
        f.close()
        # Read first line to see if these tests apply to current target.
        if tests_dir in failed_tests[0]:
            pytest_args = failed_tests
        else:
            logging.error(
                "The -a flag cannot be used now because the last failed tests don't match current target."
            )
    else:
        if len(tests_to_execute) > 0:
            for running in tests_to_execute:
                pytest_args.append(running)
        else:
            exit_iris("No tests to execute.", status=1)
    return pytest_args
Exemple #2
0
def launch_control_center():
    profile_path = os.path.join(PathManager.get_working_dir(), "cc_profile")
    fx_path = PathManager.get_local_firefox_path()
    if fx_path is None:
        logger.error("Can't find local Firefox installation, aborting Iris run.")
        return False, None

    args = ["http://127.0.0.1:%s" % get_core_args().port]
    process_args = {"stream": None}
    profile = MozProfile(profile=profile_path, preferences=get_fx_prefs())
    if OSHelper.is_windows():
        process = subprocess.Popen(
            [
                fx_path,
                "-no-remote",
                "-new-tab",
                args,
                "--wait-for-browser",
                "-foreground",
                "-profile",
                profile.profile,
            ],
            shell=False,
        )

    else:
        fx_runner = FirefoxRunner(
            binary=fx_path, profile=profile, cmdargs=args, process_args=process_args
        )
        fx_runner.start()
    logger.debug("Launching web server for directory %s" % PathManager.get_working_dir())
    server = LocalWebServer(PathManager.get_working_dir(), get_core_args().port)
    server.stop()
    time.sleep(Settings.DEFAULT_UI_DELAY)

    if OSHelper.is_mac():
        type(text="q", modifier=KeyModifier.CMD)
    elif OSHelper.is_windows():
        type(text="w", modifier=[KeyModifier.CTRL, KeyModifier.SHIFT])
    else:
        type(text="q", modifier=KeyModifier.CTRL)
    if OSHelper.is_windows():
        if process.pid is not None:
            try:
                logger.debug("Closing Firefox process ID: %s" % process.pid)
                process = psutil.Process(process.pid)
                for proc in process.children(recursive=True):
                    proc.kill()
                process.kill()
            except psutil.NoSuchProcess:
                pass
    else:
        try:
            fx_runner.stop()
        except Exception as e:
            logger.debug("Error stopping fx_runner")
            logger.debug(e)

    return server.result
Exemple #3
0
def show_control_center():
    if get_core_args().control:
        return True
    elif get_core_args().target is None:
        exit_iris(
            "No target specified, e.g.: \n\niris your_target\n\nClosing Iris.", status=1
        )
        return False
    else:
        return False
Exemple #4
0
    def firefox(self, request):
        profile_type = request.node.own_markers[0].kwargs.get('profile')
        preferences = request.node.own_markers[0].kwargs.get('preferences')
        profile = FirefoxProfile.make_profile(profile_type, preferences)

        fx = target_args.firefox
        locale = get_core_args().locale
        app = FX_Collection.get(fx, locale)

        if not app:
            FX_Collection.add(fx, locale)
            app = FX_Collection.get(fx, locale)

        if target_args.update_channel:
            FirefoxUtils.set_update_channel_pref(app.path,
                                                 target_args.update_channel)

        is_rerun = False
        if len(Target.completed_tests):
            if Target.completed_tests[-1].file_name == request.node.fspath:
                logger.debug('Rerun detected:')
                logger.debug(Target.completed_tests[-1].file_name)
                logger.debug(request.node.fspath)
                is_rerun = True
        if not is_rerun and len(Target.completed_tests) > 0:
            logger.debug('Incrementing index')
            Target.index += 1

        args = {
            'total': len(request.node.session.items),
            'current': Target.index,
            'title': os.path.basename(request.node.fspath)
        }

        return FXRunner(app, profile, args)
Exemple #5
0
    def pytest_sessionstart(self, session):
        global core_args
        core_args = get_core_args()
        global target_args
        BaseTarget.pytest_sessionstart(self, session)
        self.validate_config()
        try:
            port = core_args.port

            logger.info(
                "Starting local web server on port %s for directory %s" %
                (port, self.local_web_root))
            web_server_process = Process(target=LocalWebServer,
                                         args=(self.local_web_root, port))
            self.process_list.append(web_server_process)
            web_server_process.start()

            fx = self.args.firefox
            locale = core_args.locale
            app = FX_Collection.get(fx, locale)

            if not app:
                FX_Collection.add(fx, locale)
                app = FX_Collection.get(fx, locale)
            self.values = {
                "fx_version": app.version,
                "fx_build_id": app.build_id,
                "channel": app.channel
            }
        except IOError:
            logger.critical(
                "Unable to launch local web server, aborting Iris.")
            exit(1)
        logger.info("Loading more test images...")
    def __init__(self, app: FirefoxApp, profile: FirefoxProfile = None, args=None):

        if profile is None:
            profile = FirefoxProfile()
        self.application = app
        self.url = "http://127.0.0.1:{}".format(get_core_args().port)
        self.profile = profile
        if args is not None:
            query_string = "?"
            for arg in args:
                value_pair = "%s=%s&" % (arg, args[arg])
                query_string += value_pair
            self.url += query_string[:-1]
Exemple #7
0
    def create_working_directory():
        """Creates working directory."""
        path = get_core_args().workdir
        if not os.path.exists(path):
            logger.debug("Creating working directory %s" % path)
            os.makedirs(path)
        if not os.path.exists(os.path.join(path, "data")):
            os.makedirs(os.path.join(path, "data"))

        if args.clear:
            master_run_directory = os.path.join(path, "runs")
            if os.path.exists(master_run_directory):
                shutil.rmtree(master_run_directory, ignore_errors=True)
                PathManager.create_run_directory()
            run_file = os.path.join(path, "data", "runs.json")
            if os.path.exists(run_file):
                os.remove(run_file)
                PathManager.create_runs_file()
            cache_builds_directory = os.path.join(path, "cache")
            if os.path.exists(cache_builds_directory):
                shutil.rmtree(cache_builds_directory, ignore_errors=True)
Exemple #8
0
def get_active_root():
    """
    Determine location of targets/tests dynamically, using this priority:
    1. Set by user via runtime flag.
    2. Set by user via environment variable.
    3. Using the Pipfile to locate active project.
    4. If none of the above, default to package root and show a warning.
    """

    path = get_core_args().code_root
    if path is not None:
        path = os.path.realpath(path)
        logger.debug("Code root found in -q arg: %s" % path)
        return trim_path(path)

    try:
        path = os.environ["IRIS_CODE_ROOT"]
        if path is not None:
            path = os.path.realpath(path)
            if os.path.exists(path):
                logger.debug("Code root found in environment variable: %s" %
                             path)
                return trim_path(path)
    except KeyError:
        logger.debug(
            "No code root found in environment variables, trying other methods."
        )

    cmd = subprocess.run("pipenv --where",
                         shell=True,
                         stdout=subprocess.PIPE,
                         timeout=5)
    path = os.path.realpath(cmd.stdout.decode("utf-8").strip())
    if os.path.exists(path):
        logger.debug("Code root set using location of Pipfile: %s" % path)
        return trim_path(path)
    else:
        path_warning()
        return os.path.realpath(os.path.dirname(__file__) + "/../..")
class LocalWeb(object):
    """Constants that represent URLs and images for local content. """

    _ip_host = "127.0.0.1"
    _domain_host = "localhost.allizom.org"
    _port = get_core_args().port
    """Simple blank HTML page."""
    BLANK_PAGE = "http://%s:%s/blank.htm" % (_ip_host, _port)
    BLANK_PAGE_2 = "http://%s:%s/blank.htm" % (_domain_host, _port)
    """Local Firefox site."""
    FIREFOX_TEST_SITE = "http://%s:%s/firefox/" % (_ip_host, _port)
    FIREFOX_TEST_SITE_2 = "http://%s:%s/firefox/" % (_domain_host, _port)
    FIREFOX_LOGO = Pattern("firefox_logo.png").similar(0.6)
    FIREFOX_IMAGE = Pattern("firefox_full.png")
    FIREFOX_BOOKMARK = Pattern("firefox_bookmark.png")
    FIREFOX_BOOKMARK_SMALL = Pattern("firefox_bookmark_small.png")
    """Local Firefox Focus site."""
    FOCUS_TEST_SITE = "http://%s:%s/focus/" % (_ip_host, _port)
    FOCUS_TEST_SITE_2 = "http://%s:%s/focus/" % (_domain_host, _port)
    FOCUS_LOGO = Pattern("focus_logo.png")
    FOCUS_IMAGE = Pattern("focus_full.png")
    FOCUS_BOOKMARK = Pattern("focus_bookmark.png")
    FOCUS_BOOKMARK_SMALL = Pattern("focus_bookmark_small.png")
    """Local Mozilla site."""
    MOZILLA_TEST_SITE = "http://%s:%s/mozilla/" % (_ip_host, _port)
    MOZILLA_TEST_SITE_2 = "http://%s:%s/mozilla/" % (_domain_host, _port)
    MOZILLA_LOGO = Pattern("mozilla_logo.png")
    MOZILLA_IMAGE = Pattern("mozilla_full.png")
    MOZILLA_BOOKMARK = Pattern("mozilla_bookmark.png")
    MOZILLA_BOOKMARK_SMALL = Pattern("mozilla_bookmark_small.png")
    MOZILLA_BOOKMARK_HISTORY_SIDEBAR = Pattern(
        "mozilla_bookmark_history_sidebar.png")
    MOZILLA_BOOKMARK_LIBRARY_HISTORY_LIST = Pattern(
        "mozilla_bookmark_library_history_list.png")
    """Local Pocket site."""
    POCKET_TEST_SITE = "http://%s:%s/pocket/" % (_ip_host, _port)
    POCKET_TEST_SITE_2 = "http://%s:%s/pocket/" % (_domain_host, _port)
    POCKET_LOGO = Pattern("pocket_logo.png")
    POCKET_IMAGE = Pattern("pocket_full.png")
    POCKET_BOOKMARK = Pattern("pocket_bookmark.png")
    POCKET_BOOKMARK_SMALL = Pattern("pocket_bookmark_small.png")
    """Soap Wiki Test Site"""
    SOAP_WIKI_TEST_SITE = "http://%s:%s/soap_wiki_test_site/" % (_ip_host,
                                                                 _port)
    SOAP_WIKI_1_OF_2_MATCHES = Pattern("1_of_2_matches.png")
    SOAP_WIKI_2_OF_2_MATCHES = Pattern("2_of_2_matches.png")
    SOAP_WIKI_CLEANING_SEE_SELECTED_LABEL = Pattern(
        "cleaning_see_selected_label.png")
    SOAP_WIKI_OPERATING_ALL = Pattern("operating_all.png")
    SOAP_WIKI_OPERATING_ALL_HIGHLIGHTED = Pattern(
        "operating_all_highlighted.png")
    SOAP_WIKI_OPERATING_DISPARATE = Pattern("operating_disparate.png")
    SOAP_WIKI_OPERATING_DISPARATE_HIGHLIGHTED = Pattern(
        "operating_disparate_highlighted.png")
    SOAP_WIKI_SEE_LABEL = Pattern("see_label.png")
    SOAP_WIKI_SEE_LABEL_UNHIGHLITED = Pattern("see_label_unhighlited.png")
    SOAP_WIKI_SOAP_ENVELOPE_LABEL_SELECTED = Pattern(
        "soap_envelope_label_selected.png")
    SOAP_WIKI_SOAP_LABEL = Pattern("soap_label.png")
    SOAP_WIKI_SOAP_LINK_HIGHLIGHTED = Pattern("soap_link_highlighted.png")
    SOAP_WIKI_SOAP_XML_LABEL = Pattern("soap_xml_label.png")
    SOAP_WIKI_TEST_LABEL_PATTERN = Pattern("test_label_pattern.png")
    """Local files samples."""
    SAMPLE_FILES = "http://%s:%s/files/" % (_ip_host, _port)
    """about:preferences#privacy"""
    ABOUT_PREFERENCES_PRIVACY_ADDRESS = Pattern(
        "about_preferences_privacy_address.png")
    """CNN Site"""
    CNN_LOGO = Pattern("cnn_logo.png")
    CNN_BLOCKED_CONTENT_ADV = Pattern("cnn_blocked_content.png")
    """Iris Core elements"""
    IRIS_LOGO = Pattern("iris_logo.png")
    IRIS_LOGO_ACTIVE_TAB = Pattern("iris_logo_active_tab.png")
    IRIS_LOGO_INACTIVE_TAB = Pattern("iris_logo_inactive_tab.png")
    """Download site"""
    DOWNLOAD_TEST_SITE = "https://irisfirefoxtestfiles.netlify.com"
class Test(FirefoxTest):
    # Set the region from command line flag, if given.
    # Command line flag is for testing en-US locale in IN, ID and CA regions, de locale in RU and ru locale in DE.
    # Otherwise, we'll automatically set the region based on the Firefox locale under test.
    global fx_region_code
    region_arg = Target().get_target_args().region
    if region_arg != "":
        fx_region_code = region_arg
    else:
        regions_by_locales = {
            "en-US": "US",
            "de": "DE",
            "fr": "FR",
            "pl": "PL",
            "it": "IT",
            "pt-BR": "BR",
            "ja": "JA",
            "es-ES": "ES",
            "en-GB": "GB",
            "ru": "DE",
        }
        fx_locale_code = get_core_args().locale
        fx_region_code = regions_by_locales[fx_locale_code]

    @pytest.mark.details(
        description="Default Search Code: Google.",
        locale=["en-US", "de", "fr", "pl", "it", "pt-BR", "ja", "es-ES", "en-GB", "ru"],
        test_case_id="218333",
        test_suite_id="83",
        profile=Profiles.BRAND_NEW,
        preferences={
            "browser.search.region": fx_region_code,
            "browser.search.cohort": "nov17-1",
        },
    )
    def run(self, firefox):
        url = LocalWeb.FOCUS_TEST_SITE
        text_pattern = Pattern("focus_text.png")
        text_pattern_selected = Pattern("focus_text_selected.png")

        change_preference("browser.search.widget.inNavBar", True)
        change_preference("browser.tabs.warnOnClose", True)

        default_search_engine_google_pattern = Pattern(
            "default_search_engine_google.png"
        )
        google_logo_content_search_field_pattern = Pattern(
            "google_logo_content_search_field.png"
        )

        navigate("about:preferences#search")

        default_search_engine_check = exists(
            default_search_engine_google_pattern, FirefoxSettings.FIREFOX_TIMEOUT
        )
        assert default_search_engine_check, "Google is the default search engine."

        # Perform a search using the awesome bar and then clear the content from it.
        select_location_bar()
        type("test", interval=0.25)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        type(Key.ENTER)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        select_location_bar()
        url_text = copy_to_clipboard()

        if (
            FirefoxUtils.get_firefox_channel(firefox.application.path) == "beta"
            or FirefoxUtils.get_firefox_channel(firefox.application.path) == "release"
        ):
            if fx_region_code != "US":
                assert (
                    url_text
                    == "https://www.google.com/search?client=firefox-b-d&q=test"
                ), (
                    "Client search code is correct for searches from awesome bar, region "
                    + fx_region_code
                    + "."
                )
            else:
                assert (
                    url_text
                    == "https://www.google.com/search?client=firefox-b-1-d&q=test"
                ), (
                    "Client search code is correct for searches from awesome bar, region "
                    + fx_region_code
                    + "."
                )
        elif FirefoxUtils.get_firefox_channel(firefox.application.path) == "esr":
            if fx_region_code != "US":
                assert (
                    url_text
                    == "https://www.google.com/search?client=firefox-b-e&q=test"
                ), (
                    "Client search code is correct for searches from awesome bar, region "
                    + fx_region_code
                    + "."
                )
            else:
                assert (
                    url_text
                    == "https://www.google.com/search?client=firefox-b-1-e&q=test"
                ), (
                    "Client search code is correct for searches from awesome bar, region "
                    + fx_region_code
                    + "."
                )

        select_location_bar()
        type(Key.DELETE)

        # Perform a search using the search bar.
        select_search_bar()
        type("test", interval=0.25)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        type(Key.ENTER)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        select_location_bar()
        url_text = copy_to_clipboard()

        if (
            FirefoxUtils.get_firefox_channel(firefox.application.path) == "beta"
            or FirefoxUtils.get_firefox_channel(firefox.application.path) == "release"
        ):
            if fx_region_code != "US":
                assert (
                    url_text
                    == "https://www.google.com/search?client=firefox-b-d&q=test"
                ), (
                    "Client search code is correct for searches from search bar, region "
                    + fx_region_code
                    + "."
                )
            else:
                assert (
                    url_text
                    == "https://www.google.com/search?client=firefox-b-1-d&q=test"
                ), (
                    "Client search code is correct for searches from search bar, region "
                    + fx_region_code
                    + "."
                )

        elif FirefoxUtils.get_firefox_channel(firefox.application.path) == "esr":
            if fx_region_code != "US":
                assert (
                    url_text
                    == "https://www.google.com/search?client=firefox-b-e&q=test"
                ), (
                    "Client search code is correct for searches from search bar, region "
                    + fx_region_code
                    + "."
                )
            else:
                assert (
                    url_text
                    == "https://www.google.com/search?client=firefox-b-1-e&q=test"
                ), (
                    "Client search code is correct for searches from search bar, region "
                    + fx_region_code
                    + "."
                )

        # Highlight some text and right click it.
        new_tab()

        navigate(url)

        focus_page_loaded = exists(
            text_pattern, FirefoxSettings.HEAVY_SITE_LOAD_TIMEOUT
        )
        assert focus_page_loaded, "Page successfully loaded, focus text found."

        double_click(text_pattern)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        right_click(text_pattern_selected)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        repeat_key_down(3)
        type(Key.ENTER)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        select_location_bar()
        url_text = copy_to_clipboard()

        if (
            FirefoxUtils.get_firefox_channel(firefox.application.path) == "beta"
            or FirefoxUtils.get_firefox_channel(firefox.application.path) == "release"
        ):
            if fx_region_code != "US":
                assert (
                    url_text
                    == "https://www.google.com/search?client=firefox-b-d&q=Focus"
                ), ("Client search code is correct, region " + fx_region_code + ".")
            else:
                assert (
                    url_text
                    == "https://www.google.com/search?client=firefox-b-1-d&q=Focus"
                ), ("Client search code is correct, region " + fx_region_code + ".")
        elif FirefoxUtils.get_firefox_channel(firefox.application.path) == "esr":
            if fx_region_code != "US":
                assert (
                    url_text
                    == "https://www.google.com/search?client=firefox-b-e&q=Focus"
                ), ("Client search code is correct, region " + fx_region_code + ".")
            else:
                assert (
                    url_text
                    == "https://www.google.com/search?client=firefox-b-1-e&q=Focus"
                ), ("Client search code is correct, region " + fx_region_code + ".")

        # Perform a search from about:newtab page, content search field.
        new_tab()

        google_logo_found = exists(
            google_logo_content_search_field_pattern, FirefoxSettings.FIREFOX_TIMEOUT
        )
        assert google_logo_found, "Google logo from content search field found."

        click(google_logo_content_search_field_pattern)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        type("beats", interval=0.25)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        type(Key.ENTER)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        select_location_bar()
        url_text = copy_to_clipboard()

        if (
            FirefoxUtils.get_firefox_channel(firefox.application.path) == "beta"
            or FirefoxUtils.get_firefox_channel(firefox.application.path) == "release"
        ):
            if fx_region_code != "US":
                assert (
                    url_text
                    == "https://www.google.com/search?client=firefox-b-d&q=beats"
                ), (
                    "Client search code is correct for searches from about:newtab page, content search field, "
                    "region " + fx_region_code + "."
                )
            else:
                assert (
                    url_text
                    == "https://www.google.com/search?client=firefox-b-1-d&q=beats"
                ), (
                    "Client search code is correct for searches from about:newtab page, content search field, "
                    "region " + fx_region_code + "."
                )
        elif FirefoxUtils.get_firefox_channel(firefox.application.path) == "esr":
            if fx_region_code != "US":
                assert (
                    url_text
                    == "https://www.google.com/search?client=firefox-b-e&q=beats"
                ), (
                    "Client search code is correct for searches from about:newtab pageq, region "
                    + fx_region_code
                    + "."
                )
            else:
                assert (
                    url_text
                    == "https://www.google.com/search?client=firefox-b-1-e&q=beats"
                ), (
                    "Client search code is correct for searches from about:newtab page, region "
                    + fx_region_code
                    + "."
                )
class Test(FirefoxTest):
    # Set the region from command line flag, if given.
    # Command line flag is for testing en-US locale in IN, ID and CA regions, de locale in RU and ru locale in DE.
    # Otherwise, we'll automatically set the region based on the Firefox locale under test.
    global fx_region_code
    region_arg = Target().get_target_args().region
    if region_arg != '':
        fx_region_code = region_arg
    else:
        regions_by_locales = {
            'en-US': 'US',
            'de': 'DE',
            'fr': 'FR',
            'pl': 'PL',
            'it': 'IT',
            'pt-BR': 'BR',
            'ja': 'JA',
            'es-ES': 'ES',
            'en-GB': 'GB',
            'ru': 'DE'
        }
        fx_locale_code = get_core_args().locale
        fx_region_code = regions_by_locales[fx_locale_code]

    @pytest.mark.details(description='Default Search Code: Google.',
                         locale=[
                             'en-US', 'de', 'fr', 'pl', 'it', 'pt-BR', 'ja',
                             'es-ES', 'en-GB', 'ru'
                         ],
                         test_case_id='218333',
                         test_suite_id='83',
                         profile=Profiles.BRAND_NEW,
                         preferences={
                             'browser.search.region': fx_region_code,
                             'browser.search.cohort': 'nov17-1'
                         })
    def run(self, firefox):
        url = LocalWeb.FOCUS_TEST_SITE
        text_pattern = Pattern('focus_text.png')
        text_pattern_selected = Pattern('focus_text_selected.png')

        change_preference('browser.search.widget.inNavBar', True)
        change_preference('browser.tabs.warnOnClose', True)

        default_search_engine_google_pattern = Pattern(
            'default_search_engine_google.png').similar(0.6)
        google_logo_content_search_field_pattern = Pattern(
            'google_logo_content_search_field.png')

        navigate('about:preferences#search')

        default_search_engine_check = exists(
            default_search_engine_google_pattern,
            FirefoxSettings.FIREFOX_TIMEOUT)
        assert default_search_engine_check, 'Google is the default search engine.'

        # Perform a search using the awesome bar and then clear the content from it.
        select_location_bar()
        type('test', interval=0.25)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        type(Key.ENTER)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        select_location_bar()
        url_text = copy_to_clipboard()

        if FirefoxUtils.get_firefox_channel(firefox.application.path) == 'beta' \
                or FirefoxUtils.get_firefox_channel(firefox.application.path) == 'release':
            if fx_region_code != 'US':
                assert url_text == 'https://www.google.com/search?client=firefox-b-d&q=test', \
                    'Client search code is correct for searches from awesome bar, region ' + fx_region_code + '.'
            else:
                assert url_text == 'https://www.google.com/search?client=firefox-b-1-d&q=test', \
                    'Client search code is correct for searches from awesome bar, region ' + fx_region_code + '.'
        elif FirefoxUtils.get_firefox_channel(
                firefox.application.path) == 'esr':
            if fx_region_code != 'US':
                assert url_text == 'https://www.google.com/search?client=firefox-b-e&q=test', \
                    'Client search code is correct for searches from awesome bar, region ' + fx_region_code + '.'
            else:
                assert url_text == 'https://www.google.com/search?client=firefox-b-1-e&q=test', \
                    'Client search code is correct for searches from awesome bar, region ' + fx_region_code + '.'

        select_location_bar()
        type(Key.DELETE)

        # Perform a search using the search bar.
        select_search_bar()
        type('test', interval=0.25)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        type(Key.ENTER)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        select_location_bar()
        url_text = copy_to_clipboard()

        if FirefoxUtils.get_firefox_channel(firefox.application.path) == 'beta' or \
                FirefoxUtils.get_firefox_channel(firefox.application.path) == 'release':
            if fx_region_code != 'US':
                assert url_text == 'https://www.google.com/search?client=firefox-b-d&q=test', \
                                   'Client search code is correct for searches from search bar, region ' + \
                                   fx_region_code + '.'
            else:
                assert url_text == 'https://www.google.com/search?client=firefox-b-1-d&q=test',\
                    'Client search code is correct for searches from search bar, region ' + fx_region_code + '.'

        elif FirefoxUtils.get_firefox_channel(
                firefox.application.path) == 'esr':
            if fx_region_code != 'US':
                assert url_text == 'https://www.google.com/search?client=firefox-b-e&q=test', \
                    'Client search code is correct for searches from search bar, region ' + fx_region_code + '.'
            else:
                assert url_text == 'https://www.google.com/search?client=firefox-b-1-e&q=test', \
                    'Client search code is correct for searches from search bar, region ' + fx_region_code + '.'

        # Highlight some text and right click it.
        new_tab()

        navigate(url)

        focus_page_loaded = exists(text_pattern,
                                   FirefoxSettings.HEAVY_SITE_LOAD_TIMEOUT)
        assert focus_page_loaded, 'Page successfully loaded, focus text found.'

        double_click(text_pattern)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        right_click(text_pattern_selected)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        repeat_key_down(3)
        type(Key.ENTER)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        select_location_bar()
        url_text = copy_to_clipboard()

        if FirefoxUtils.get_firefox_channel(firefox.application.path) == 'beta' or \
                FirefoxUtils.get_firefox_channel(firefox.application.path) == 'release':
            if fx_region_code != 'US':
                assert url_text == 'https://www.google.com/search?client=firefox-b-d&q=Focus', \
                    'Client search code is correct, region ' + fx_region_code + '.'
            else:
                assert url_text == 'https://www.google.com/search?client=firefox-b-1-d&q=Focus', \
                    'Client search code is correct, region ' + fx_region_code + '.'
        elif FirefoxUtils.get_firefox_channel(
                firefox.application.path) == 'esr':
            if fx_region_code != 'US':
                assert url_text == 'https://www.google.com/search?client=firefox-b-e&q=Focus', \
                    'Client search code is correct, region ' + fx_region_code + '.'
            else:
                assert url_text == 'https://www.google.com/search?client=firefox-b-1-e&q=Focus', \
                    'Client search code is correct, region ' + fx_region_code + '.'

        # Perform a search from about:newtab page, content search field.
        new_tab()

        google_logo_found = exists(google_logo_content_search_field_pattern,
                                   FirefoxSettings.FIREFOX_TIMEOUT)
        assert google_logo_found, 'Google logo from content search field found.'

        click(google_logo_content_search_field_pattern)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        type('beats', interval=0.25)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        type(Key.ENTER)
        time.sleep(FirefoxSettings.TINY_FIREFOX_TIMEOUT)
        select_location_bar()
        url_text = copy_to_clipboard()

        if FirefoxUtils.get_firefox_channel(firefox.application.path) == 'beta' or \
                FirefoxUtils.get_firefox_channel(firefox.application.path) == 'release':
            if fx_region_code != 'US':
                assert url_text == 'https://www.google.com/search?client=firefox-b-d&q=beats',\
                    'Client search code is correct for searches from about:newtab page, content search field, ' \
                    'region ' + fx_region_code + '.'
            else:
                assert url_text == 'https://www.google.com/search?client=firefox-b-1-d&q=beats',\
                    'Client search code is correct for searches from about:newtab page, content search field, ' \
                    'region ' + fx_region_code + '.'
        elif FirefoxUtils.get_firefox_channel(
                firefox.application.path) == 'esr':
            if fx_region_code != 'US':
                assert url_text == 'https://www.google.com/search?client=firefox-b-e&q=beats', \
                    'Client search code is correct for searches from about:newtab pageq, region ' + fx_region_code + '.'
            else:
                assert url_text == 'https://www.google.com/search?client=firefox-b-1-e&q=beats', \
                    'Client search code is correct for searches from about:newtab page, region ' + fx_region_code + '.'
Exemple #12
0
 def get_web_asset_dir(asset_file_name):
     resource = "/tests/{}".format(asset_file_name)
     return "http://127.0.0.1:%s" % get_core_args().port + resource
Exemple #13
0
def main():
    args = get_core_args()
    set_code_paths(args)
    initialize_logger()
    migrate_data()
    validate_config_ini(args)
    if verify_config(args):
        pytest_args = None
        settings = None
        if show_control_center():
            try:
                init_control_center()
            except FileNotFoundError:
                path_warning('Control Center assets')
                exit_iris('', status=1)
            user_result = launch_control_center()
            logger.debug(user_result)
            if user_result != "cancel":
                # Extract list of tests
                if "tests" not in user_result:
                    exit_iris("No tests chosen, closing Iris.", status=0)

                pytest_args = user_result["tests"]

                # Extract target from response and update core arg for target
                set_core_arg("target", user_result["target"])

                # Extract settings from response
                args = get_core_args()
                settings = user_result["args"]
            else:
                # User cancelled or otherwise failed to select tests,
                # so we will shut down Iris.
                exit_iris("User cancelled run, closing Iris.", status=0)

        try:
            try:
                target_plugin = get_target(args.target)
            except Exception:
                exit_iris("\nUnknown target %s, closing Iris." % args.target, status=1)
            if settings is not None:
                logger.debug("Passing settings to target: %s" % settings)
                target_plugin.update_settings(settings)

            if pytest_args is None:
                pytest_args = get_test_params()
            if len(pytest_args) == 0:
                exit_iris("No tests found.", status=1)

            pytest_args.append("-vs")
            pytest_args.append("-r ")
            pytest_args.append("-s")
            pytest_args.append("--force-flaky")
            pytest_args.append("--max-runs")
            pytest_args.append(str(get_core_args().max_tries))

            initialize_platform(args)
            pytest.main(pytest_args, plugins=[target_plugin])
        except ImportError as e:
            exit_iris(
                "Could not load plugin for %s target, error: %s" % (args.target, e),
                status=1,
            )
    else:
        logger.error("Failed platform verification.")
        exit(1)
Exemple #14
0
 def work_dir(self):
     if get_core_args().workdir is None:
         return get_working_dir()
     else:
         return get_core_args().workdir
import sys
import pytest
from unittest.mock import patch
from moziris.util import arg_parser

with patch.object(sys, "argv", ["iris", "sample", "-n"]):
    default_config = arg_parser.get_core_args()


class TestIrisConfigDefault:
    def test_default_target(self):
        target = default_config.target
        assert target == "sample", "target = {}".format(target)

    def test_default_rerun(self):
        rerun = default_config.rerun
        assert rerun is False

    def test_default_highlight(self):
        highlight = default_config.highlight
        assert highlight is False

    def test_default_clear(self):
        clear = default_config.clear
        assert clear is False

    def test_default_test_directory(self):
        test_directory = default_config.directory
        assert test_directory == "", "directory = {}".format(test_directory)

    def test_default_email_report(self):
Exemple #16
0
 def get_working_dir():
     """Returns the path to the root of the directory where local data is stored."""
     PathManager.create_working_directory()
     return get_core_args().workdir
class Test(FirefoxTest):
    # Set the region from command line argument, if given. Otherwise, set the region based on Firefox locale.
    # Use -g <region> for testing the English locales of Firefox in the four Yandex regions; RU, BY, KZ and TR.
    global fx_region_code
    region_arg = Target().get_target_args().region
    if region_arg != "":
        fx_region_code = region_arg
    else:
        regions_by_locales = {
            "ru": "RU",
            "be": "BY",
            "kk": "KZ",
            "tr": "TR",
            "en-US": "RU",
            "en-GB": "RU",
            "en-CA": "RU",
        }
        fx_locale_code = get_core_args().locale
        fx_region_code = regions_by_locales[fx_locale_code]

    @pytest.mark.details(
        description="Default Search Code: Yandex: Russia.",
        locale=["ru", "be", "kk", "tr", "en-US", "en-GB", "en-CA"],
        test_case_id="218336",
        test_suite_id="83",
        profile=Profiles.BRAND_NEW,
        preferences={
            "browser.search.region": fx_region_code,
            "browser.search.cohort": "jan18-1"
        },
        blocked_by={
            "id": "4490",
            "platform": OSPlatform.ALL
        },
    )
    def run(self, firefox):
        url = LocalWeb.FOCUS_TEST_SITE
        text_pattern = Pattern("focus_text.png")
        text_pattern_selected = Pattern("focus_text_selected.png")

        change_preference("browser.search.widget.inNavBar", True)
        change_preference("browser.tabs.warnOnClose", True)

        default_search_engine_yandex_pattern = Pattern(
            "default_search_engine_yandex.png")
        yandex_logo_content_search_field_pattern = Pattern(
            "yandex_logo_content_search_field.png")

        navigate("about:preferences#search")

        expected = exists(default_search_engine_yandex_pattern,
                          FirefoxSettings.FIREFOX_TIMEOUT)
        assert expected, "Yandex is the default search engine."

        # Perform a search using the awesome bar and then clear the content from it.
        select_location_bar()
        type("test", interval=0.25)
        type(Key.ENTER)
        time.sleep(Settings.DEFAULT_UI_DELAY_LONG)
        select_location_bar()
        url_text = copy_to_clipboard()

        assert "/search/?clid=2186621&text=test" in url_text, (
            "Client search code is correct for searches from"
            "awesomebar, region " + fx_region_code + ".")

        select_location_bar()
        type(Key.DELETE)

        # Perform a search using the search bar.
        select_search_bar()
        type("test", interval=0.25)
        type(Key.ENTER)
        time.sleep(Settings.DEFAULT_UI_DELAY_LONG)
        select_location_bar()
        url_text = copy_to_clipboard()

        assert "/search/?clid=2186618&text=test" in url_text, (
            "Client search code is correct for searches from "
            "search bar, region " + fx_region_code + ".")

        # Highlight some text and right click it.
        new_tab()
        navigate(url)
        expected = exists(LocalWeb.FOCUS_LOGO, 10)
        assert expected, "Page successfully loaded, Focus logo found."

        double_click(text_pattern)
        time.sleep(Settings.DEFAULT_UI_DELAY_SHORT)
        right_click(text_pattern_selected)
        time.sleep(Settings.DEFAULT_UI_DELAY_SHORT)
        repeat_key_down(3)
        type(Key.ENTER)
        time.sleep(Settings.DEFAULT_UI_DELAY_LONG)
        select_location_bar()
        url_text = copy_to_clipboard()

        assert "/search/?clid=2186623&text=test" in url_text, (
            "Client search code is correct for searches "
            "with context menu, region " + fx_region_code + ".")

        # Perform a search from about:newtab page, content search field.
        new_tab()
        expected = exists(yandex_logo_content_search_field_pattern,
                          FirefoxSettings.FIREFOX_TIMEOUT)
        assert expected, "Yandex logo from content search field found."

        click(yandex_logo_content_search_field_pattern)
        time.sleep(Settings.DEFAULT_UI_DELAY)

        type("beats", interval=0.25)
        type(Key.ENTER)
        time.sleep(Settings.DEFAULT_UI_DELAY)
        select_location_bar()
        url_text = copy_to_clipboard()

        assert "/search/?clid=2186620&text=beats" in url_text, (
            "Client search code is correct for searches "
            "from content search field, region " + fx_region_code + ".")
Exemple #18
0
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)
Exemple #19
0
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import importlib
import logging
import os
import sys

from moziris.api.os_helpers import OSHelper
from moziris.api.settings import Settings
from moziris.util.arg_parser import get_core_args
from moziris.util.path_manager import PathManager

logger = logging.getLogger(__name__)
core_args = get_core_args()


def check_target(target: str = None):
    """Checks if provided target exists."""
    # Currently not in use, but maintaining for possible future use.

    if target is None:
        logger.warning("No target provided.")

    local_target_path = os.path.join(PathManager.get_module_dir(), "targets")
    package_target_path = os.path.join(PathManager.get_module_dir(), "moziris",
                                       "targets")

    if os.path.exists(os.path.join(local_target_path, target)):
        return True
Exemple #20
0
        "-i=DEBUG",
        "-k",
        "-l=en-GB",
        "-m=1",
        "-n",
        "-o",
        "-p=8888",
        "--code_root=/iris",
        "-t=testnamehere",
        "-w=testworkingdir",
        "-x=excludeme",
        "-z",
    ],
):

    test_config = arg_parser.get_core_args()


class TestIrisConfigCustom:
    # Check that values are set correctly

    def test_set_target(self):
        target = test_config.target
        assert target == "sample", "target = {}".format(target)

    def test_set_rerun(self):
        rerun = test_config.rerun
        assert rerun

    def test_set_highlight(self):
        highlight = test_config.highlight