mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
run_in_headless_android_emulator: add port forwarding for webdriver
This commit is contained in:
parent
f5ff709c79
commit
33234affc9
2 changed files with 25 additions and 2 deletions
|
@ -57,6 +57,7 @@ def main(avd_name, apk_path, *args):
|
||||||
|
|
||||||
logcat_args = ["RustAndroidGlueStdouterr:D", "*:S", "-v", "raw"]
|
logcat_args = ["RustAndroidGlueStdouterr:D", "*:S", "-v", "raw"]
|
||||||
with terminate_on_exit(adb + ["logcat"] + logcat_args) as logcat:
|
with terminate_on_exit(adb + ["logcat"] + logcat_args) as logcat:
|
||||||
|
forward_webdriver(adb, args)
|
||||||
logcat.wait()
|
logcat.wait()
|
||||||
|
|
||||||
|
|
||||||
|
@ -119,6 +120,28 @@ def write_args(adb, args):
|
||||||
check_call(adb + ["shell", "echo %s >> %s" % (shell_quote(arg), params_file)])
|
check_call(adb + ["shell", "echo %s >> %s" % (shell_quote(arg), params_file)])
|
||||||
|
|
||||||
|
|
||||||
|
def forward_webdriver(adb, args):
|
||||||
|
webdriver_port = extract_arg("--webdriver", args)
|
||||||
|
if webdriver_port is not None:
|
||||||
|
wait_for_tcp_server(adb, webdriver_port)
|
||||||
|
port = "tcp:%s" % webdriver_port
|
||||||
|
check_call(adb + ["forward", port, port])
|
||||||
|
sys.stderr.write("Forwarding WebDriver port %s to the emulator\n" % webdriver_port)
|
||||||
|
|
||||||
|
|
||||||
|
def extract_arg(name, args):
|
||||||
|
previous_arg_matches = False
|
||||||
|
for arg in args:
|
||||||
|
if previous_arg_matches:
|
||||||
|
return arg
|
||||||
|
previous_arg_matches = arg == name
|
||||||
|
|
||||||
|
|
||||||
|
def wait_for_tcp_server(adb, port):
|
||||||
|
while call(adb + ["shell", "nc -z 127.0.0.1 %s" % port]) != 0:
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
# Copied from Python 3.3+'s shlex.quote()
|
# Copied from Python 3.3+'s shlex.quote()
|
||||||
def shell_quote(arg):
|
def shell_quote(arg):
|
||||||
# use single quotes, and put single quotes into double quotes
|
# use single quotes, and put single quotes into double quotes
|
||||||
|
|
|
@ -57,8 +57,8 @@ class ServoWebDriverProtocol(Protocol):
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
"""Connect to browser via WebDriver."""
|
"""Connect to browser via WebDriver."""
|
||||||
# Largish timeout for the case where we're booting an Android emulator.
|
# Large timeout for the case where we're booting an Android emulator.
|
||||||
wait_for_service((self.host, self.port), timeout=120)
|
wait_for_service((self.host, self.port), timeout=300)
|
||||||
|
|
||||||
self.session = webdriver.Session(self.host, self.port, extension=ServoCommandExtensions)
|
self.session = webdriver.Session(self.host, self.port, extension=ServoCommandExtensions)
|
||||||
self.session.start()
|
self.session.start()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue