0

I want to use the R package shinytest to test my R/Shiny application. Now, I facing one strange issue after another. It seams that the JavaScript Interpreter of "shinytest" or which runs in the background can not work with Promise, neither simple things like 'a'.startsWith('a') does not work.

Can I switch the backend of shinytest or can I somehow add the missing JavaScript features?

In the following you see a minimal example, the app itself has no meaning, but the executing Javascript inside the test suite shows that simple calls fails.

To run the example you may need to install the "globals" package. Like renv::install("globals").

Example:

library(shiny)
library(shinytest)

# you may need to run: 
# renv::install("globals")


ui <- fluidPage(
  titlePanel("Hello Shiny!"),
  sidebarLayout(
    sidebarPanel(),
    mainPanel()
  )
)


# Define server logic required to draw a histogram ----
server <- function(input, output) {}


# See above for the definitions of ui and server
app <- shinyApp(ui = ui, server = server)

testapp <- ShinyDriver$new(app, debug="all")

testapp$executeScript("console.log('Hello')")
print(testapp$getDebugLog("browser"))
testapp$executeScript("console.log('a'.startsWith('b'))")
print(testapp$getDebugLog("browser"))
testapp$executeScript("console.log(Promise)")
print(testapp$getDebugLog("browser"))


The last print statements should always return correct output. But the error messages are:

B/I 12:26:40.26 Hello (:)> testapp$executeScript("console.log('a'.startsWith('b'))")
Error in session_makeRequest(self, private, endpoint, data, params, headers) : 
  undefined is not a function (evaluating ''a'.startsWith('b')')
> print(testapp$getDebugLog("browser"))
> testapp$executeScript("console.log(Promise)")
Error in session_makeRequest(self, private, endpoint, data, params, headers) : 
  Can't find variable: Promise

This means that Promises are not available in this shinytest package.

Allan Karlson
  • 453
  • 11
  • 23
  • 1
    The package is using old `PhantomJS` and Promise is not supported, for solution, this might help: https://stackoverflow.com/questions/47011686/cant-find-variable-promise-in-phantomjs – lz100 Nov 18 '21 at 18:14
  • Thank you @lz100 for your help. Did you already once switched the backend of shinytest? Besides fixing the missing JS support, is there another recommendation to test UI in shiny like shinytest but with a more modern backend. – Allan Karlson Nov 19 '21 at 07:53
  • No, I don't use this package often. Maybe you can try [Chromote](https://github.com/rstudio/chromote) – lz100 Nov 19 '21 at 17:20

0 Answers0