Пример #1
0
async def run_driver_async() -> Connection:
    package_path = get_file_dirname()
    driver_name = compute_driver_name()
    driver_executable = package_path / "drivers" / driver_name

    # Sourced from: https://github.com/pytest-dev/pytest/blob/49827adcb9256c9c9c06a25729421dcc3c385edc/src/_pytest/faulthandler.py#L73-L80
    def _get_stderr_fileno() -> int:
        try:
            return sys.stderr.fileno()
        except io.UnsupportedOperation:
            # pytest-xdist monkeypatches sys.stderr with an object that is not an actual file.
            # https://docs.python.org/3/library/faulthandler.html#issue-with-file-descriptors
            # This is potentially dangerous, but the best we can do.
            return sys.__stderr__.fileno()

    proc = await asyncio.create_subprocess_exec(
        str(driver_executable),
        stdin=asyncio.subprocess.PIPE,
        stdout=asyncio.subprocess.PIPE,
        stderr=_get_stderr_fileno(),
        limit=32768,
    )
    assert proc.stdout
    assert proc.stdin
    connection = Connection(proc.stdout, proc.stdin, create_remote_object,
                            asyncio.get_event_loop())
    return connection
Пример #2
0
def main() -> None:
    if "install" not in sys.argv:
        print('Run "python -m playwright install" to complete installation')
        return
    package_path = get_file_dirname()
    driver_name = compute_driver_name()
    driver_executable = package_path / "drivers" / driver_name
    print("Installing the browsers...")
    subprocess.check_call(f"{driver_executable} install", shell=True)

    print("Playwright is now ready for use")
Пример #3
0
def compute_driver_executable() -> Path:
    package_path = get_file_dirname()
    platform = sys.platform
    if platform == "darwin":
        return package_path / "drivers" / "driver-darwin"
    elif platform == "linux":
        return package_path / "drivers" / "driver-linux"
    elif platform == "win32":
        result = package_path / "drivers" / "driver-win32-amd64.exe"
        if result.exists():
            return result
        return package_path / "drivers" / "driver-win32.exe"
    return package_path / "drivers" / "driver-linux"
Пример #4
0
async def run_driver_async() -> Connection:
    package_path = get_file_dirname()
    driver_name = compute_driver_name()
    driver_executable = package_path / "drivers" / driver_name

    proc = await asyncio.create_subprocess_exec(
        str(driver_executable),
        stdin=asyncio.subprocess.PIPE,
        stdout=asyncio.subprocess.PIPE,
        stderr=asyncio.subprocess.PIPE,
        limit=32768,
    )
    assert proc.stdout
    assert proc.stdin
    connection = Connection(proc.stdout, proc.stdin, create_remote_object,
                            asyncio.get_event_loop())
    return connection
Пример #5
0
import asyncio
import gzip
import mimetypes
import socket
import threading
from contextlib import closing
from http import HTTPStatus

from autobahn.twisted.websocket import WebSocketServerFactory, WebSocketServerProtocol
from OpenSSL import crypto
from twisted.internet import reactor, ssl
from twisted.web import http

from playwright.path_utils import get_file_dirname

_dirname = get_file_dirname()


def _find_free_port():
    with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
        s.bind(("", 0))
        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        return s.getsockname()[1]


class Server:
    protocol = "http"

    def __init__(self):
        self.PORT = _find_free_port()
        self.EMPTY_PAGE = f"{self.protocol}://localhost:{self.PORT}/empty.html"
Пример #6
0
def compute_driver_executable() -> Path:
    package_path = get_file_dirname()
    platform = sys.platform
    if platform == "win32":
        return package_path / "driver" / "playwright-cli.exe"
    return package_path / "driver" / "playwright-cli"