This class starts a Shiny app in a new R session, along with a phantom.js
headless browser that can be used to simulate user actions. This provides
a full simulation of a Shiny app so that you can test user interactions
with a live app.
new()ShinyDriver$new(
path = ".",
loadTimeout = NULL,
checkNames = TRUE,
debug = c("none", "all", shinytest::ShinyDriver$debugLogTypes),
phantomTimeout = 5000,
seed = NULL,
cleanLogs = TRUE,
shinyOptions = list(),
renderArgs = NULL,
options = list()
)pathPath to a directory containing a Shiny app, i.e. a
single app.R file or a server.R-ui.R pair.
loadTimeoutHow long to wait for the app to load, in ms. This includes the time to start R. Defaults to 5s when running locally and 10s when running on CI.
checkNamesCheck if widget names are unique?
debugStart the app in debugging mode? In debugging mode debug messages are printed to the console.
phantomTimeoutHow long to wait when connecting to phantomJS process, in ms
seedAn optional random seed to use before starting the application. For apps that use R's random number generator, this can make their behavior repeatable.
cleanLogsWhether to remove the stdout and stderr logs when the Shiny process object is garbage collected.
shinyOptionsA list of options to pass to shiny::runApp().
renderArgsPassed to rmarkdown::run() for interactive .Rmds.
optionsA list of base::options() to set in the driver's child
process.
stop()Stop the app, the terminate external R process that runs the app and the phantomjs instance.
getValue()Finds a widget and queries its value. See the getValue() method of
Widget for more details.
ShinyDriver$getValue(name, iotype = c("auto", "input", "output"))setValue()Finds a widget and sets its value. It's a shortcut for findElement()
plus setValue(); see the Widget documentation for more details.
ShinyDriver$setValue(name, value, iotype = c("auto", "input", "output"))click()Find a widget and click it. It's a shortcut for findElement()
plus click(); see the Widget documentation for more details.
ShinyDriver$click(name, iotype = c("auto", "input", "output"))sendKeys()Sends the specified keys to specific HTML element. Shortcut for
findWidget() plus sendKeys().
nameName of a shiny widget.
keysKeys to send to the widget or the app. See webdriver::key for how to specific special keys.
getWindowSize()Get current size of the browser window, as list of integer scalars
named width and height.
getDebugLog()Query one or more of the debug logs.
ShinyDriver$getDebugLog(type = c("all", ShinyDriver$debugLogTypes))takeScreenshot()Takes a screenshot of the current page and writes it to a PNG file or shows on current graphics device.
fileFile name to save the screenshot to. If NULL, then
it will be shown on the R graphics device.
idIf not-NULL, will take a screenshot of element with this id.
parentIf TRUE, will take screenshot of parent of id; this
is useful if you also want to capture the label attached to a Shiny
control.
findElement()Find an HTML element on the page, using a CSS selector, XPath expression,
or link text (for <a> tags). If multiple elements are matched, only
the first is returned.
cssCSS selector to find an HTML element.
linkTextFind <a> HTML elements based on exact innerText
partialLinkTextFind <a> HTML elements based on partial innerText
xpathFind HTML elements using XPath expressions.
findElements()Find all elements matching CSS selection, xpath, or link text.
cssCSS selector to find an HTML element.
linkTextFind <a> HTML elements based on exact innerText
partialLinkTextFind <a> HTML elements based on partial innerText
xpathFind HTML elements using XPath expressions.
A list of webdriver::Elements.
waitFor()Waits until a JavaScript expression evaluates to true or the
timeout is exceeded.
waitForShiny()Waits until Shiny is not busy, i.e. the reactive graph has finished
updating. This is useful, for example, if you've resized the window with
setWindowSize() and want to make sure all plot redrawing is complete
before take a screenshot.
waitForValue()Waits until the input or output with name name is not one of
ignored values, or the timeout is reached.
This function can be useful in helping determine if an application has initialized or finished processing a complex reactive situation.
nameName of a shiny widget.
ignoreList of possible values to ignore when checking for updates.
iotypeType of the Shiny widget. Usually shinytest finds the widgets by their name, so this is only needed if you use the same name for an input and output widget.
timeoutAmount of time to wait before giving up (milliseconds).
checkIntervalHow often to check for the condition, in ms.
findWidget()Finds the a Shiny input or output control.
ShinyDriver$findWidget(name, iotype = c("auto", "input", "output"))nameName of a shiny widget.
iotypeType of the Shiny widget. Usually shinytest finds the widgets by their name, so this is only needed if you use the same name for an input and output widget.
A Widget.
expectUpdate()It performs one or more update operations via the browser, thens
waits for the specified output(s) to update. The test succeeds if
all specified output widgets are updated before the timeout.
For updates that involve a lot of computation, increase the timeout.
ShinyDriver$expectUpdate(
output,
...,
timeout = 3000,
iotype = c("auto", "input", "output")
)outputName of output control to check.
...Name-value pairs used to update inputs.
timeoutAmount of time to wait before giving up (milliseconds).
iotypeType of the Shiny widget. Usually shinytest finds the widgets by their name, so this is only needed if you use the same name for an input and output widget.
setInputs()Sets input values.
ShinyDriver$setInputs(
...,
wait_ = TRUE,
values_ = TRUE,
timeout_ = 3000,
allowInputNoBinding_ = FALSE,
priority_ = c("input", "event")
)...Name-value pairs, name1 = value1, name2 = value2 etc.
Enput with name name1 will be assigned value value1.
wait_Wait until all reactive updates have completed?
values_If TRUE, will return final updated values of inputs.
timeout_Amount of time to wait before giving up (milliseconds).
allowInputNoBinding_When setting the value of an input, allow it to set the value of an input even if that input does not have an input binding.
priority_Sets the event priority. For expert use only: see https://shiny.rstudio.com/articles/communicating-with-js.html#values-vs-events for details.
uploadFile()Uploads a file to a file input.
...Name-path pairs, e.g. name1 = path1. The file located at
path1 will be uploaded to file input with name name1.
wait_Wait until all reactive updates have completed?
values_If TRUE, will return final updated values of download
control.
timeout_Amount of time to wait before giving up (milliseconds).
snapshotInit()Download a snapshot. Generally, you should not call this function
yourself; it will be generated by recordTest() as needed.
snapshot()Take a snapshot. Generally, you should not call this function
yourself; it will be generated by recordTest() as needed.
snapshotDownload()Snapshot a file download action. Generally, you should not call this
function yourself; it will be generated by recordTest() as needed.
idOutput id of shiny::downloadButton()/shiny::downloadLink()
filenameFile name to save file to. The default, NULL,
generates an ascending sequence of names: 001.download,
002.download, etc.