From a94cfc24af8fe45a04224041ffda0978e1ea341b Mon Sep 17 00:00:00 2001 From: Ashby Thorpe Date: Thu, 2 Nov 2023 19:29:55 +0000 Subject: [PATCH] Use remote-debugging-port for Chrome and selenium --- R/session.R | 32 ++++++++++++++++++++++++++------ R/utils-errors.R | 2 +- tests/testthat/test-actions.R | 3 +++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/R/session.R b/R/session.R index 74c55537..dde89ab8 100644 --- a/R/session.R +++ b/R/session.R @@ -415,17 +415,37 @@ create_selenium_client <- function(browser, port = 4444L, host = "localhost", .. } ) + opts <- if (browser == "chrome" && !"capabilities" %in% ...names()) { + list(`goog:chromeOptions` = list( + args = list( + "remote-debugging-port=9222" + ) + )) + } else { + NULL + } + if (!res) { stop_connect_selenium_server(timeout = 20) } rlang::try_fetch( - selenium::SeleniumSession$new( - browser = browser, - port = port, - host = host, - ... - ), + if (!is.null(opts)) { + selenium::SeleniumSession$new( + browser = browser, + port = port, + host = host, + capabilities = opts, + ... + ) + } else { + selenium::SeleniumSession$new( + browser = browser, + port = port, + host = host, + ... + ) + }, error = function(e) { stop_selenium_session(e) } diff --git a/R/utils-errors.R b/R/utils-errors.R index 51f7a39d..bd57966b 100644 --- a/R/utils-errors.R +++ b/R/utils-errors.R @@ -187,7 +187,7 @@ stop_connect_selenium_server <- function(timeout = NULL, error = NULL, call = rl stop_selenium_session <- function(error, call = rlang::caller_env()) { cli::cli_abort(c( "A Selenium session could not be started" - ), class = "selenider_error_selenium_session", parent = error) + ), class = "selenider_error_selenium_session", parent = error, call = call) } stop_connect_rselenium_server <- function(count, error = NULL, res = NULL, driver = NULL, call = rlang::caller_env()) { diff --git a/tests/testthat/test-actions.R b/tests/testthat/test-actions.R index 23b8f1f7..fbd181dd 100644 --- a/tests/testthat/test-actions.R +++ b/tests/testthat/test-actions.R @@ -97,6 +97,9 @@ test_that("JavaScript actions work", { }) test_that("elem_scroll_to() works", { + if (Sys.getenv("SELENIDER_BROWSER") == "firefox") { + skip("Local files don't work on Firefox") + } session <- selenider_test_session() html <- "