Repository: servo/servo
File: etc/blink-perf-test-runner/main.py (Python)

Code before:
    print("Trying to create driver")
    options = ArgOptions()
    options.set_capability("browserName", "servo")
    driver = None
    start_time = time.time()
    while driver is None and time.time() - start_time < timeout:
        try:
            driver = webdriver.Remote(command_executor="http://127.0.0.1:7000", options=options)
        except (ConnectionError, ProtocolError):
            time.sleep(0.2)
        except Exception as e:
            print(f"Unexpected exception when creating webdriver: {e}, {type(e)}")
            time.sleep(1)
    print(
        "Established Webdriver connection in",
    )
    return driver


def start_servo(servo_path: str) -> webdriver.Remote | None:
    """Start servo and create webdriver"""
    subprocess.Popen(
        [
            servo_path,
            "--webdriver",
            "--pref=network_http_proxy_uri=http://127.0.0.1:3128",
        ]
    )
    return create_driver()


def kill_servo():
    subprocess.Popen(["killall", "servo"])


def test(s: str, driver: webdriver.Remote) -> tuple[str, str, str] | AbortReason:
    """Run a test by loading a website, and returning (avg, min, max).
    This will run for MAX_WAIT_TIME seconds and return as soon as the avg line exists in the log element"""

    print("Running: " + canonical_test_path(s))
    try:
        driver.get(s)
        for i in range(MAX_WAIT_TIME):
            element = driver.find_element(By.ID, "log")
            text = element.text
            result_lines = text.split("\n")
            # get the avg line or return None if it doesn't exist yet
            avg_line = next(filter(lambda x: "avg" in x, result_lines), None)
            min_line = next(filter(lambda x: "min" in x, result_lines), None)
            max_line = next(filter(lambda x: "max" in x, result_lines), None)
            if avg_line is not None and min_line is not None and max_line is not None:

Review comment (suggestion):
This should be removed. I believe you anyway patched servo so that it will now respect `http_proxy`.
```suggestion
```

Code after:
]


def create_driver(webdriver_port: int, timeout: int = 3) -> webdriver.Remote | None:
    """Create the webdriver connection."""
    print("Trying to create driver")
    options = ArgOptions()
    options.set_capability("browserName", "servo")
    driver = None
    start_time = time.time()
    while driver is None and time.time() - start_time < timeout:
        try:
            driver = webdriver.Remote(command_executor=f"http://127.0.0.1:{webdriver_port}", options=options)
        except (ConnectionError, ProtocolError):
            time.sleep(0.2)
        except Exception as e:
            print(f"Unexpected exception when creating webdriver: {e}, {type(e)}")
            time.sleep(1)
    print(
        "Established Webdriver connection",
    )
    return driver


def start_servo(webdriver_port: int, servo_path: str) -> webdriver.Remote | None:
    """Start servo and create webdriver"""
    try:
        subprocess.Popen(
            [
                servo_path,
                f"--webdriver={webdriver_port}",
            ]
        )
    except FileNotFoundError:
        print("The servo binary does not exist")
        return sys.exit(1)
    return create_driver(webdriver_port)


def kill_servo():
    subprocess.Popen(["killall", "servo"])


def test(s: str, driver: webdriver.Remote) -> tuple[str, str, str] | AbortReason:
    """Run a test by loading a website, and returning (avg, min, max).
    This will run for MAX_WAIT_TIME seconds and return as soon as the avg line exists in the log element"""

    print("Running: " + canonical_test_path(s, None))
    try:
        driver.get(s)
        for i in range(MAX_WAIT_TIME):