diff --git a/R/actions.R b/R/actions.R index 4824c5e1..e45352af 100644 --- a/R/actions.R +++ b/R/actions.R @@ -11,7 +11,7 @@ #' @param x A `selenider_element` object. #' @param js Whether to click the element using JavaScript. For `elem_right_click()`, #' this is ignored if Selenium is being used, since right clicking using -#' RSelenium does not seem to work (so JavaScript is used instead). +#' selenium does not seem to work (so JavaScript is used instead). #' @param timeout How long to wait for the element to exist. #' #' @returns `x`, invisibly. diff --git a/R/docs.R b/R/docs.R index 3917a6fe..12716693 100644 --- a/R/docs.R +++ b/R/docs.R @@ -4,11 +4,10 @@ #' `selenider` has a few options, allowing you to specify the session and browser to use #' without having to tell [selenider_session()] this information every time. #' -#' * `selenider.session` - The package to use as a backend: either "chromote" or -#' "selenium". +#' * `selenider.session` - The package to use as a backend: either "chromote", +#' "selenium" or "rselenium". #' * `selenider.browser` - The name of the browser to run the session in; one of -#' "chrome", "firefox", "phantomjs" or "internet explorer" (only on -#' Windows). +#' "chrome", "firefox", "edge", "safari", or another valid browser name. #' #' @name selenider-config NULL diff --git a/R/find_actual_element.R b/R/find_actual_element.R index e1deec35..73152a8e 100644 --- a/R/find_actual_element.R +++ b/R/find_actual_element.R @@ -3,10 +3,10 @@ #' @param x The parent element. #' @param using The type of the selector (e.g. "css selector", "xpath"). #' @param value The value of the selector as a string. -#' @param driver The [chromote::ChromoteSession] or [RSelenium::remoteDriver]. +#' @param driver The [chromote::ChromoteSession] or [selenium::SeleniumSession]. #' #' @returns -#' A backendNodeId (chromote) or a webElement (RSelenium) +#' A backendNodeId (chromote) or a WebElement (selenium) #' #' @noRd find_actual_element <- function(x, using, value, driver) { diff --git a/R/get_actual_element.R b/R/get_actual_element.R index 85038881..617bd540 100644 --- a/R/get_actual_element.R +++ b/R/get_actual_element.R @@ -2,15 +2,15 @@ #' #' @description #' Turn a lazy selenium element or element collection into a backendNodeId (chromote) -#' or an [RSelenium::webElement]. Use this to perform certain actions on the +#' or an [selenium::WebElement]. Use this to perform certain actions on the #' element that are not implemented in selenider. #' #' `get_actual_element()` turns a `selenider_element` object into a single -#' backendNodeId or [RSelenium::webElement] object. The function will wait for the object +#' backendNodeId or [selenium::WebElement] object. The function will wait for the object #' to exist in the DOM. #' #' `get_actual_elements()` turns a `selenider_elements` object into a list -#' of [RSelenium::webElement] objects, waiting for any parent objects to +#' of [selenium::WebElement] objects, waiting for any parent objects to #' exist in the DOM. #' #' @param x A `selenider_element` or `selenider_elements` object, produced by @@ -18,7 +18,7 @@ #' @param timeout The timeout to use while asserting that the item exists. If #' NULL, the timeout of the `selenider_element` will be used. #' -#' @returns An integer (backendNodeId), or an [RSelenium::webElement] object. +#' @returns An integer (backendNodeId), or a [selenium::WebElement] object. #' `get_actual_elements()` returns a list of such objects. #' #' @seealso @@ -29,7 +29,7 @@ #' for the operations that can be performed using a backend node id. Note that #' this requires the [chromote::ChromoteSession] object, which can be retrieved using #' `$driver`. -#' * The documentation for [RSelenium::webElement()] to see the things you can +#' * The documentation for [selenium::WebElement()] to see the things you can #' do with a webElement. #' #' @examplesIf selenider::selenider_available(online = FALSE) @@ -60,7 +60,7 @@ #' if (inherits(driver, "ChromoteSession")) { #' driver$DOM$describeNode(backendNodeId = elems[[1]]) #' } else { -#' elems[[1]]$describeElement() +#' elems[[1]]$get_rect() #' } #' #' \dontshow{ diff --git a/R/utils-errors.R b/R/utils-errors.R index bd57966b..ed2c60df 100644 --- a/R/utils-errors.R +++ b/R/utils-errors.R @@ -160,7 +160,7 @@ stop_default_browser <- function(call = rlang::caller_env()) { stop_no_dependencies <- function(call = rlang::caller_env()) { cli::cli_abort(c( - "One of {.pkg chromote} or {.pkg RSelenium} must be installed to use {.pkg selenider}." + "One of {.pkg chromote} or {.pkg selenium} must be installed to use {.pkg selenider}." ), class = "selenider_error_dependencies", call = call) } diff --git a/R/utils.R b/R/utils.R index 96151aee..5bb56d45 100644 --- a/R/utils.R +++ b/R/utils.R @@ -44,7 +44,7 @@ get_with_timeout <- function(timeout, .f, ...) { #' #' If `session` is `"selenium"`, we check: #' -#' * Whether `RSelenium` is installed. +#' * Whether `selenium` is installed. #' * Whether we can find a valid browser that is supported by `RSelenium`. #' #' @returns @@ -88,7 +88,7 @@ selenider_available <- function(session = c("chromote", "selenium"), online = TR error = function(e) FALSE ) } else { - rlang::is_installed("RSelenium") && + rlang::is_installed("selenium") && !is.null(find_browser_and_version()$browser) } } @@ -300,4 +300,3 @@ selenider_cleanup <- function(env = rlang::caller_env()) { # nocov start try_fetch(withr::deferred_run(env), error = function(e) rlang::abort(c("Error in withr::deferred_run()"), parent = e)) return(invisible()) } # nocov end - diff --git a/man/elem_click.Rd b/man/elem_click.Rd index 0e555440..aadc2a36 100644 --- a/man/elem_click.Rd +++ b/man/elem_click.Rd @@ -17,7 +17,7 @@ elem_right_click(x, js = FALSE, timeout = NULL) \item{js}{Whether to click the element using JavaScript. For \code{elem_right_click()}, this is ignored if Selenium is being used, since right clicking using -RSelenium does not seem to work (so JavaScript is used instead).} +selenium does not seem to work (so JavaScript is used instead).} \item{timeout}{How long to wait for the element to exist.} } diff --git a/man/get_actual_element.Rd b/man/get_actual_element.Rd index 27703b9b..c4d401e3 100644 --- a/man/get_actual_element.Rd +++ b/man/get_actual_element.Rd @@ -17,20 +17,20 @@ get_actual_elements(x, timeout = NULL) NULL, the timeout of the \code{selenider_element} will be used.} } \value{ -An integer (backendNodeId), or an \link[RSelenium:webElement-class]{RSelenium::webElement} object. +An integer (backendNodeId), or a \link[selenium:WebElement]{selenium::WebElement} object. \code{get_actual_elements()} returns a list of such objects. } \description{ Turn a lazy selenium element or element collection into a backendNodeId (chromote) -or an \link[RSelenium:webElement-class]{RSelenium::webElement}. Use this to perform certain actions on the +or an \link[selenium:WebElement]{selenium::WebElement}. Use this to perform certain actions on the element that are not implemented in selenider. \code{get_actual_element()} turns a \code{selenider_element} object into a single -backendNodeId or \link[RSelenium:webElement-class]{RSelenium::webElement} object. The function will wait for the object +backendNodeId or \link[selenium:WebElement]{selenium::WebElement} object. The function will wait for the object to exist in the DOM. \code{get_actual_elements()} turns a \code{selenider_elements} object into a list -of \link[RSelenium:webElement-class]{RSelenium::webElement} objects, waiting for any parent objects to +of \link[selenium:WebElement]{selenium::WebElement} objects, waiting for any parent objects to exist in the DOM. } \examples{ @@ -62,7 +62,7 @@ elems <- ss("p") |> if (inherits(driver, "ChromoteSession")) { driver$DOM$describeNode(backendNodeId = elems[[1]]) } else { - elems[[1]]$describeElement() + elems[[1]]$get_rect() } \dontshow{ @@ -80,7 +80,7 @@ elements. for the operations that can be performed using a backend node id. Note that this requires the \link[chromote:ChromoteSession]{chromote::ChromoteSession} object, which can be retrieved using \verb{$driver}. -\item The documentation for \code{\link[RSelenium:webElement-class]{RSelenium::webElement()}} to see the things you can +\item The documentation for \code{\link[selenium:WebElement]{selenium::WebElement()}} to see the things you can do with a webElement. } } diff --git a/man/selenider-config.Rd b/man/selenider-config.Rd index 2ffaf3dd..3d45378c 100644 --- a/man/selenider-config.Rd +++ b/man/selenider-config.Rd @@ -7,10 +7,9 @@ \code{selenider} has a few options, allowing you to specify the session and browser to use without having to tell \code{\link[=selenider_session]{selenider_session()}} this information every time. \itemize{ -\item \code{selenider.session} - The package to use as a backend: either "chromote" or -"selenium". +\item \code{selenider.session} - The package to use as a backend: either "chromote", +"selenium" or "rselenium". \item \code{selenider.browser} - The name of the browser to run the session in; one of -"chrome", "firefox", "phantomjs" or "internet explorer" (only on -Windows). +"chrome", "firefox", "edge", "safari", or another valid browser name. } } diff --git a/man/selenider_available.Rd b/man/selenider_available.Rd index 0acbfda7..b1ea635d 100644 --- a/man/selenider_available.Rd +++ b/man/selenider_available.Rd @@ -42,7 +42,7 @@ If \code{session} is \code{"chromote"}, we also check: If \code{session} is \code{"selenium"}, we check: \itemize{ -\item Whether \code{RSelenium} is installed. +\item Whether \code{selenium} is installed. \item Whether we can find a valid browser that is supported by \code{RSelenium}. } } diff --git a/tests/testthat/helper-devtools.R b/tests/testthat/helper-devtools.R index abce115a..47f3e6c0 100644 --- a/tests/testthat/helper-devtools.R +++ b/tests/testthat/helper-devtools.R @@ -3,6 +3,8 @@ test_selenider <- function(x, selenium_chrome = TRUE, selenium_firefox = TRUE, + rselenium_chrome = TRUE, + rselenium_firefox = TRUE, chromote = TRUE, chromote_view = TRUE, manual = TRUE) { @@ -23,6 +25,24 @@ test_selenider <- function(x, ), rlang::ns_env("devtools")$test()) } + if (rselenium_chrome) { + # Avoid explicit dependency on devtools + cli::cli_alert_info("Running tests using rselenium and Chrome") + withr::with_envvar(c( + withr::with_envvar(c( + "SELENIDER_SESSION" = "rselenium", + "SELENIDER_BROWSER" = "chrome" + ), rlang::ns_env("devtools")$test()) + } + + if (rselenium_firefox) { + cli::cli_alert_info("Running tests using Selenium and Firefox") + withr::with_envvar(c( + "SELENIDER_SESSION" = "rselenium", + "SELENIDER_BROWSER" = "firefox" + ), rlang::ns_env("devtools")$test()) + } + if (chromote) { cli::cli_alert_info("Running tests using Chromote") withr::with_envvar(c( diff --git a/vignettes/selenider.Rmd b/vignettes/selenider.Rmd index ccdc2d7b..b75d4d78 100644 --- a/vignettes/selenider.Rmd +++ b/vignettes/selenider.Rmd @@ -46,18 +46,18 @@ automatically when the script finishes running. One thing to remember is that if you start a session inside a function, it will be closed automatically when the function finishes running. If you want to use the session outside the function, you need to use the `.env` argument. For example, let's say we want a wrapper -function around `selenider_session()` that always uses RSelenium: +function around `selenider_session()` that always uses selenium: ```{r} # Bad (unless you only need to use the session inside the function) my_selenider_session <- function(...) { - selenider_session("RSelenium", ...) + selenider_session("selenium", ...) # The session will be closed here } # Good - the session will be open in the caller environment/function my_selenider_session <- function(..., .env = rlang::caller_env()) { - selenider_session("RSelenium", ..., .env = .env) + selenider_session("selenium", ..., .env = .env) } ```