Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ashbythorpe committed Nov 3, 2023
1 parent 864e4cd commit 5e57d44
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 32 deletions.
2 changes: 1 addition & 1 deletion R/actions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 3 additions & 4 deletions R/docs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions R/find_actual_element.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions R/get_actual_element.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
#'
#' @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
#' [find_element()] / [find_elements()].
#' @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
Expand All @@ -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
#' `<selenider_session>$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)
Expand Down Expand Up @@ -60,7 +60,7 @@
#' if (inherits(driver, "ChromoteSession")) {
#' driver$DOM$describeNode(backendNodeId = elems[[1]])
#' } else {
#' elems[[1]]$describeElement()
#' elems[[1]]$get_rect()
#' }
#'
#' \dontshow{
Expand Down
2 changes: 1 addition & 1 deletion R/utils-errors.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
5 changes: 2 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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

2 changes: 1 addition & 1 deletion man/elem_click.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions man/get_actual_element.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions man/selenider-config.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/selenider_available.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions tests/testthat/helper-devtools.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions vignettes/selenider.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
```

Expand Down

0 comments on commit 5e57d44

Please sign in to comment.