app <- ShinyDriver$new(path = ".", loadTimeout = 5000, checkNames = TRUE, debug = c("none", "all", ShinyDriver$debugLogTypes)) app$stop() app$getDebugLog(type = c("all", ShinyDriver$debugLogTypes))
app$getValue(name, iotype = c("auto", "input", "output")) app$setValue(name, value, iotype = c("auto", "input", "output")) app$sendKeys(name = NULL, keys)
app$get_windows_size() app$setWindowSize(width, height)
app$getUrl() app$goBack() app$refresh() app$getTitle() app$getSource() app$takeScreenshot(file = NULL)
app$findElement(css = NULL, linkText = NULL, partialLinkText = NULL, xpath = NULL)
app$findElements(css = NULL, linkText = NULL, partialLinkText = NULL, xpath = NULL)
app$waitFor(expr, checkInterval = 100, timeout = 3000)
app$listWidgets()
app$checkUniqueWidgetNames()
app$findWidget(name, iotype = c("auto", "input", "output"))
app$expectUpdate(output, ..., timeout = 3000, iotype = c("auto", "input", "output"))
ShinyDriver
instance.app.R
file or a server.R
and ui.R
pair.$sendKeys
it can
be NULL
, in which case the keys are sent to the active
HTML element.shinytest
finds the widgets by their name, so this need not be specified,
but Shiny allows input and output widgets with identical names.sendKeys
method of the webdriver
package.NULL
, then
it will be shown on the R graphics device.<a>
HTML elements based on their
innerText
.<a>
HTML elements based on their
innerText
. It uses partial matching.expectUpdate
these can be named arguments.
The argument names correspond to Shiny input widgets: each input
widget will be set to the specified value.ShinyDriver$new()
function creates a ShinyDriver
object. It starts
the Shiny app in a new R session, and it also starts a phantomjs
headless browser that connects to the app. It waits until the app is
ready to use. It waits at most loadTimeout
milliseconds, and if
the app is not ready, then it throws an error. You can increase
loadTimeout
for slow loading apps. Currently it supports apps
that are defined in a single app.R
file, or in a server.R
and ui.R
pair.
app$stop()
stops the app, i.e. the external R process that runs
the app, and also the phantomjs instance.
app$getDebugLog()
queries one or more of the debug logs:
shiny_console
, browser
or shinytest
.
app$getValue()
finds a widget and queries its value. See
the getValue
method of the Widget
class.
app$setInputs()
sets the value of inputs. The arguments must all
be named; an input with each name will be assigned the given value.
app$uploadFile()
uploads a file to a file input. The argument must
be named and the value must be the path to a local file; that file will be
uploaded to a file input with that name.
app$getAllValues()
returns a named list of all inputs, outputs,
and error values.
app$setValue()
finds a widget and sets its value. See the
setValue
method of the Widget
class.
app$sendKeys
sends the specified keys to the HTML element of the
widget.
app$getWindowSize()
returns the current size of the browser
window, in a list of two integer scalars named ‘width’ and
‘height’.
app$setWindowSize()
sets the size of the browser window to the
specified width and height.
app$getUrl()
returns the current URL.
app$goBack()
“presses” the browser's ‘back’
button.
app$refresh()
“presses” the browser's ‘refresh’
button.
app$getTitle()
returns the title of the page. (More precisely
the document title.)
app$getSource()
returns the complete HTML source of the current
page, in a character scalar.
app$takeScreenshot()
takes a screenshot of the current page
and writes it to a file, or (if file
is NULL
) shows it
on the R graphics device. The output file has PNG format.
app$findElement()
find an HTML element on the page, using a
CSS selector or an XPath expression. The return value is an
Element
object from the webdriver
package.
app$findElements()
finds potentially multiple HTML elements,
and returns them in a list of Element
objects
from the webdriver
package.
app$waitFor()
waits until a JavaScript expression evaluates
to true
, or a timeout happens. It returns TRUE
is the
expression evaluated to true
, possible after some waiting.
app$listWidgets()
lists the names of all input and output
widgets. It returns a list of two character vectors, named input
and output
.
app$checkUniqueWidgetNames()
checks if Shiny widget names
are unique.
app$findWidget()
finds the corresponding HTML element of a Shiny
widget. It returns a Widget
object.
expectUpdate()
is one of the main functions to test Shiny apps.
It performs one or more update operations via the browser, and then
waits for the specified output widgets to update. The test succeeds if
all specified output widgets are updated before the timeout. For
updates that involve a lot of computation, you increase the timeout.
## Not run: ------------------------------------
# ## https://github.com/rstudio/shiny-examples/tree/master/050-kmeans-example
# app <- ShinyDriver$new("050-kmeans-example")
# expectUpdate(app, xcol = "Sepal.Width", output = "plot1")
# expectUpdate(app, ycol = "Petal.Width", output = "plot1")
# expectUpdate(app, clusters = 4, output = "plot1")
## ---------------------------------------------
Run the code above in your browser using DataLab