Skip to content

Commit

Permalink
Merge pull request #115 from quickstrom/explicit-browser-binary-option
Browse files Browse the repository at this point in the history
Allow specifying browser binary
  • Loading branch information
owickstrom committed Nov 9, 2022
2 parents 17c65ac + 5a7ffde commit 19ffd6d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
1 change: 0 additions & 1 deletion nix/nixpkgs.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import (fetchTarball
"https://github.com/NixOS/nixpkgs/archive/1f3ebb2bd1a353a42e8f833895c26d8415c7b791.tar.gz") {
config.allowUnfree = true;
}
4 changes: 3 additions & 1 deletion quickstrom/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def root(ctx, color, log_level, include):
@click.argument('module')
@click.argument('origin')
@click.option('-B', '--browser', default='firefox')
@click.option('--browser-binary')
@click.option('--headless/--headful', default=True)
@click.option('-S',
'--capture-screenshots/--no-capture-screenshots',
Expand All @@ -103,7 +104,7 @@ def root(ctx, color, log_level, include):
multiple=True,
type=(str, str, str),
help='set a cookie based on three values, e.g. --cookie domain name value')
def check(module: str, origin: str, browser: executor.Browser, headless: bool,
def check(module: str, origin: str, browser: executor.Browser, browser_binary: Optional[str], headless: bool,
capture_screenshots: bool, console_report_on_success: bool,
reporter: List[str], interpreter_log_file: Optional[str], driver_log_file: Optional[str],
json_report_file: str, json_report_files_directory: str,
Expand Down Expand Up @@ -150,6 +151,7 @@ def get_interpreter_log_file():
results = executor.Check(module,
origin_url.geturl(),
browser,
browser_binary,
cast(List[str],
global_options['includes']),
headless,
Expand Down
8 changes: 3 additions & 5 deletions quickstrom/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class Check():
module: str
origin: str
browser: Browser
browser_binary: Optional[str]
include_paths: List[str]
headless: bool
capture_screenshots: bool
Expand Down Expand Up @@ -364,12 +365,10 @@ def new_driver(self):
if self.browser == 'chrome':
options = chrome_options.Options()
options.headless = self.headless
browser_path = which("google-chrome-stable") or which(
"google-chrome") or which("chrome") or which("chromium")
browser_path = self.browser_binary or which("chromium") or which("google-chrome-stable") or which("google-chrome") or which("chrome")
options.binary_location = browser_path # type: ignore
options.add_argument('--no-sandbox')
options.add_argument("--single-process")
# options.add_argument("--disable-dev-shm-usage")
chromedriver_path = which('chromedriver')
if not chromedriver_path:
raise Exception("chromedriver not found in PATH")
Expand All @@ -379,8 +378,7 @@ def new_driver(self):
elif self.browser == 'firefox':
options = firefox_options.Options()
options.headless = self.headless
binary = FirefoxBinary(which("firefox"))
# options.binary = FirefoxBinary(which("firefox")) # type: ignore
binary = FirefoxBinary(self.browser_binary or which("firefox"))
geckodriver_path = which('geckodriver')
if not geckodriver_path:
raise Exception("geckodriver not found in PATH")
Expand Down
9 changes: 8 additions & 1 deletion quickstrom/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ class TraceActions():
class TraceState():
state: State


@dataclass
class TraceError():
error: str


TraceElement = Union[TraceActions, TraceState, TraceError]

Trace = List[TraceElement]
Expand Down Expand Up @@ -81,10 +83,12 @@ class End():
class Done():
results: List[Result]


@dataclass
class Aborted():
error_message: str


@dataclass
class RequestAction():
action: Action
Expand All @@ -111,10 +115,12 @@ class Events():
events: List[Action]
state: State


@dataclass
class Error():
error_message: str


def message_writer(fp: IO[str]):
dumps: Callable[[Any],
str] = lambda obj: json.dumps(obj, cls=_ProtocolEncoder)
Expand Down Expand Up @@ -167,7 +173,8 @@ def _decode_hook(d: Any) -> Any:
if d['tag'] == 'RequestAction':
return RequestAction(action=d['action'], version=d['version'])
if d['tag'] == 'AwaitEvents':
return AwaitEvents(await_timeout=d['awaitTimeout'], version=d['version'])
return AwaitEvents(await_timeout=d['awaitTimeout'],
version=d['version'])
elif d['tag'] == 'End':
return End()
elif d['tag'] == 'Done':
Expand Down
2 changes: 1 addition & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ in pkgs.mkShell {
pkgs.geckodriver
pkgs.firefox
pkgs.chromedriver
pkgs.google-chrome
pkgs.chromium

specstrom
pkgs.nodePackages.pyright
Expand Down

0 comments on commit 19ffd6d

Please sign in to comment.