예제 #1
0
def before_all(context):
    atexit.register(cleanup, context, True)

    # We set these to None explicity so that the cleanup code can run
    # through without error. It assumes that these fields exist.
    context.builder = None
    context.driver = None
    context.wm = None
    context.display = None
    context.server = None
    context.tunnel = None
    context.sc_tunnel_tempdir = None

    setup_screenshots(context)

    context.selenium_quit = os.environ.get("SELENIUM_QUIT")
    userdata = context.config.userdata
    context.builder = builder = Builder(conf_path, userdata)
    desired_capabilities = {}
    ssh_tunnel = None
    dump_config(builder)
    if userdata.get("check_selenium_config", False):
        exit(0)

    browser_to_tag_value = {
        "INTERNETEXPLORER": "ie",
        "CHROME": "ch",
        "FIREFOX": "ff"
    }

    values = {
        'browser': browser_to_tag_value[builder.config.browser],
    }

    platform = builder.config.platform
    if platform.startswith("OS X "):
        values['platform'] = 'osx'
    elif platform.startswith("WINDOWS "):
        values['platform'] = 'win'
    elif platform == "LINUX" or platform.startswith("LINUX "):
        values['platform'] = 'linux'

    # We have some cases that need to match a combination of platform
    # and browser
    values['platform_browser'] = values['platform'] + "," + values['browser']

    context.active_tag_matcher = ActiveTagMatcher(values)

    server_thread = start_server(context)

    if not builder.remote:
        visible = context.selenium_quit in ("never", "on-success")
        context.display = Display(visible=visible, size=(1024, 768))
        context.display.start()
        builder.update_ff_binary_env('DISPLAY')
        context.wm = subprocess.Popen(["openbox", "--sm-disable"])
    else:
        context.display = None
        context.wm = None

        ssh_tunnel = builder.WED_SSH_TUNNEL
        if not ssh_tunnel:
            sc_tunnel_id = os.environ.get("SC_TUNNEL_ID")
            if not sc_tunnel_id:
                user, key = builder.SAUCELABS_CREDENTIALS.split(":")
                context.tunnel, sc_tunnel_id, \
                    context.sc_tunnel_tempdir = \
                    outil.start_sc(builder.SC_TUNNEL_PATH, user, key)
            desired_capabilities["tunnel-identifier"] = sc_tunnel_id
        else:
            context.tunnel = \
                subprocess.Popen(
                    ["ssh", ssh_tunnel["ssh_to"],
                     "-R", str(ssh_tunnel["ssh_port"]) + ":localhost:" +
                     context.server_port, "-N"])

    driver = builder.get_driver(desired_capabilities)
    context.driver = driver
    context.util = selenic.util.Util(driver,
                                     # Give more time if we are remote.
                                     4 if builder.remote else 2)
    # Without this, window sizes vary depending on the actual browser
    # used.
    context.initial_window_size = {"width": 1020, "height": 700}
    context.initial_window_handle = driver.current_window_handle
    assert_true(driver.desired_capabilities["nativeEvents"],
                "Wed's test suite require that native events be available; "
                "you may have to use a different version of your browser, "
                "one for which Selenium supports native events.")

    behave_wait = os.environ.get("BEHAVE_WAIT_BETWEEN_STEPS")
    context.behave_wait = behave_wait and float(behave_wait)

    context.behave_captions = os.environ.get("BEHAVE_CAPTIONS")

    context.selenium_logs = os.environ.get("SELENIUM_LOGS", False)

    server_thread.join()

    # IE 10 has a problem with self-signed certificates. Selenium
    # cannot tell IE 10 to ignore these problems. Here we work around
    # the issue. This problem occurs only if we are using an SSH
    # tunnel rather than sauce connect.
    if ssh_tunnel and context.util.ie \
       and context.builder.config.version == "10":
        driver.get(builder.WED_SERVER + "/blank")
        # Tried using, execute_script. Did not seem to work.
        driver.get(
            "javascript:((link = document.getElementById("
            "'overridelink')) && link.click())")

    context.start_time = time.time()
예제 #2
0
def before_all(context):
    atexit.register(cleanup, context, True)

    # We set these to None explicity so that the cleanup code can run
    # through without error. It assumes that these fields exist.
    context.builder = None
    context.driver = None
    context.wm = None
    context.display = None
    context.server = None
    context.tunnel = None
    context.sc_tunnel_tempdir = None

    setup_screenshots(context)

    context.selenium_quit = os.environ.get("SELENIUM_QUIT")
    userdata = context.config.userdata
    context.builder = builder = Builder(conf_path, userdata)
    desired_capabilities = {}
    ssh_tunnel = None
    dump_config(builder)
    if userdata.get("check_selenium_config", False):
        exit(0)

    browser_to_tag_value = {
        "INTERNETEXPLORER": "ie",
        "CHROME": "ch",
        "FIREFOX": "ff"
    }

    values = {
        'browser': browser_to_tag_value[builder.config.browser],
    }

    platform = builder.config.platform
    if platform.startswith("OS X "):
        values['platform'] = 'osx'
    elif platform.startswith("WINDOWS "):
        values['platform'] = 'win'
    elif platform == "LINUX" or platform.startswith("LINUX "):
        values['platform'] = 'linux'

    # We have some cases that need to match a combination of platform
    # and browser
    values['platform_browser'] = values['platform'] + "," + values['browser']

    context.active_tag_matcher = ActiveTagMatcher(values)

    server_thread = start_server(context)

    if not builder.remote:
        visible = context.selenium_quit in ("never", "on-success")
        context.display = Display(visible=visible, size=(1024, 768))
        context.display.start()
        builder.update_ff_binary_env('DISPLAY')
        context.wm = subprocess.Popen(["openbox", "--sm-disable"])
    else:
        context.display = None
        context.wm = None

        ssh_tunnel = builder.WED_SSH_TUNNEL
        if not ssh_tunnel:
            sc_tunnel_id = os.environ.get("SC_TUNNEL_ID")
            if not sc_tunnel_id:
                user, key = builder.SAUCELABS_CREDENTIALS.split(":")
                context.tunnel, sc_tunnel_id, \
                    context.sc_tunnel_tempdir = \
                    outil.start_sc(builder.SC_TUNNEL_PATH, user, key)
            desired_capabilities["tunnel-identifier"] = sc_tunnel_id
        else:
            context.tunnel = \
                subprocess.Popen(
                    ["ssh", ssh_tunnel["ssh_to"],
                     "-R", str(ssh_tunnel["ssh_port"]) + ":localhost:" +
                     context.server_port, "-N"])

    driver = builder.get_driver(desired_capabilities)
    context.driver = driver
    context.util = selenic.util.Util(
        driver,
        # Give more time if we are remote.
        4 if builder.remote else 2)
    # Without this, window sizes vary depending on the actual browser
    # used.
    context.initial_window_size = {"width": 1020, "height": 700}
    context.initial_window_handle = driver.current_window_handle
    assert_true(
        driver.desired_capabilities["nativeEvents"],
        "Wed's test suite require that native events be available; "
        "you may have to use a different version of your browser, "
        "one for which Selenium supports native events.")

    behave_wait = os.environ.get("BEHAVE_WAIT_BETWEEN_STEPS")
    context.behave_wait = behave_wait and float(behave_wait)

    context.behave_captions = os.environ.get("BEHAVE_CAPTIONS")

    context.selenium_logs = os.environ.get("SELENIUM_LOGS", False)

    server_thread.join()

    # IE 10 has a problem with self-signed certificates. Selenium
    # cannot tell IE 10 to ignore these problems. Here we work around
    # the issue. This problem occurs only if we are using an SSH
    # tunnel rather than sauce connect.
    if ssh_tunnel and context.util.ie \
       and context.builder.config.version == "10":
        driver.get(builder.WED_SERVER + "/blank")
        # Tried using, execute_script. Did not seem to work.
        driver.get("javascript:((link = document.getElementById("
                   "'overridelink')) && link.click())")

    context.start_time = time.time()
예제 #3
0
파일: environment.py 프로젝트: nenadg/wed
def before_all(context):
    atexit.register(cleanup, context, True)
    dump_config()
    setup_screenshots(context)

    server_thread = start_server(context)

    context.selenium_quit = os.environ.get("SELENIUM_QUIT")

    context.tunnel = None
    context.sc_tunnel_tempdir = None
    desired_capabilities = {}
    ssh_tunnel = None
    if not builder.remote:
        visible = context.selenium_quit in ("never", "on-success")
        context.display = Display(visible=visible, size=(1024, 768))
        context.display.start()
        builder.update_ff_binary_env('DISPLAY')
        context.wm = subprocess.Popen(["openbox", "--sm-disable"])
    else:
        context.display = None
        context.wm = None

        ssh_tunnel = builder.WED_SSH_TUNNEL
        if not ssh_tunnel:
            sc_tunnel_id = os.environ.get("SC_TUNNEL_ID")
            if not sc_tunnel_id:
                user, key = builder.SAUCELABS_CREDENTIALS.split(":")
                context.tunnel, sc_tunnel_id, \
                    context.sc_tunnel_tempdir = \
                    outil.start_sc(builder.SC_TUNNEL_PATH, user, key)
            desired_capabilities["tunnel-identifier"] = sc_tunnel_id
        else:
            context.tunnel = \
                subprocess.Popen(
                    ["ssh", ssh_tunnel["ssh_to"],
                     "-R", str(ssh_tunnel["ssh_port"]) + ":localhost:" +
                     context.server_port, "-N"])

    driver = builder.get_driver(desired_capabilities)
    context.driver = driver
    context.util = selenic.util.Util(driver,
                                     # Give more time if we are remote.
                                     4 if builder.remote else 2)
    context.selenic = builder
    # Without this, window sizes vary depending on the actual browser
    # used.
    context.initial_window_size = {"width": 1020, "height": 700}
    context.initial_window_handle = driver.current_window_handle
    assert_true(driver.desired_capabilities["nativeEvents"],
                "Wed's test suite require that native events be available; "
                "you may have to use a different version of your browser, "
                "one for which Selenium supports native events.")

    behave_wait = os.environ.get("BEHAVE_WAIT_BETWEEN_STEPS")
    context.behave_wait = behave_wait and float(behave_wait)

    context.behave_captions = os.environ.get("BEHAVE_CAPTIONS")

    context.selenium_logs = os.environ.get("SELENIUM_LOGS", False)

    server_thread.join()

    # IE 10 has a problem with self-signed certificates. Selenium
    # cannot tell IE 10 to ignore these problems. Here we work around
    # the issue. This problem occurs only if we are using an SSH
    # tunnel rather than sauce connect.
    if ssh_tunnel and context.util.ie \
       and context.selenic.config.version == "10":
        driver.get(builder.WED_SERVER + "/blank")
        # Tried using, execute_script. Did not seem to work.
        driver.get(
            "javascript:((link = document.getElementById("
            "'overridelink')) && link.click())")

    context.start_time = time.time()