Skip to content

Commit

Permalink
feat: omit a message when a session is created automatically (#33)
Browse files Browse the repository at this point in the history
* omit a message when a session is created automatically

* improve docs around local/global sessions
  • Loading branch information
ashbythorpe authored Oct 13, 2024
1 parent 41eff65 commit 71b65e3
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 10 deletions.
5 changes: 5 additions & 0 deletions R/aaa_env.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ get_session <- function(create = TRUE, .env = rlang::caller_env()) {
session <- get_from_env("session")

if (is.null(session) && create) {
cli::cli_inform(c(
"Can't find an existing selenider session.",
"i" = "Creating a new session."
))

selenider_session(.env = .env)
} else {
session
Expand Down
2 changes: 2 additions & 0 deletions R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#' @details
#' Both functions allow the starting point for chains of selectors to be made
#' more concise. Both use [get_session()] to get the global session object.
#' If you want to pass in a session, use [find_element()]/[find_elements()]
#' instead.
#'
#' @returns
#' `s()` returns a `selenider_element` object.
Expand Down
15 changes: 10 additions & 5 deletions R/session.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#' Start a session
#'
#' @description
#' Create a session in selenider, setting it as the local session unless
#' otherwise specified, allowing the session to be accessed globally in the
#' environment where it was defined.
#' Create a session in selenider. If you create a session in the global
#' environment it will be made available to other functions (like
#' [open_url()]) without having to pass it in, and will close automatically
#' when the R session is closed. Alternatively, if it is created inside a
#' function, it will be closed as soon as the function finishes executing. To
#' customise this, use the `.env` and `local` arguments.
#'
#' @param session The package to use as a backend: either "chromote",
#' "selenium". By default, chromote is used, since this tends to be faster
Expand All @@ -29,11 +32,13 @@
#' * A list/environment containing the [selenium::SeleniumSession] object,
#' the Selenium server object, or both.
#' @param local Whether to set the session as the local session object,
#' using [local_session()].
#' using [local_session()]. If this is `FALSE`, you will have to pass this
#' into the `session` argument of other functions (like [open_url()]), and
#' close the session manually using [close_session()].
#' @param .env Passed into [local_session()], to define the
#' environment in which the session is used. Change this if you want to
#' create the session inside a function and then use it outside the
#' function.
#' function (see Examples). Use [rlang::caller_env()] in this case.
#' @param view,selenium_manager,quiet `r lifecycle::badge("deprecated")`
#' Use the `options` argument instead.
#'
Expand Down
2 changes: 2 additions & 0 deletions man/s.Rd

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

15 changes: 10 additions & 5 deletions man/selenider_session.Rd

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

0 comments on commit 71b65e3

Please sign in to comment.