rstudio / shinytest

Automated testing for shiny apps
https://rstudio.github.io/shinytest/
Other
225 stars 55 forks source link

dismissed modals still shown in screenshot #384

Closed jey1401 closed 3 years ago

jey1401 commented 3 years ago

Hi,

Here is a sample app that is tested with the following scenario:

  1. take snapshot
  2. click button to show modal
  3. take snapshot # screenshot shows modal
  4. click "dismiss"
  5. take snapshot # screenshot still shows modal (or animation while closing or grayed screen)

There are two issues:

  1. the click on dismiss button is not recorded;
  2. the 3rd screenshot still (partially, sometimes) shows the modal.

The app code:

library(shiny)

ui <- fluidPage(
    actionButton("b", "push to create modal")
)

server <- function(input, output) {

    observeEvent(input$b, {
        showModal(
            modalDialog("Hi there.")
        )
    })
}

shinyApp(ui = ui, server = server)

Here is the test code:

app <- ShinyDriver$new("../../", seed = 42)
app$snapshotInit("mytest")

app$snapshot()
app$setInputs(b = "click")
app$snapshot()
app$findElement("button[data-dismiss=\"modal\"]")$click() # this is added by hand
app$snapshot()

Thanks

wch commented 3 years ago

The modal takes a bit of time to fade away, so you may need to add a Sys.sleep() after triggering the click. You might want to use a relatively long wait (like 2 seconds), to be safe.

As for recording the click, the recorder app unfortunately doesn't detect the modal dismiss button click because it's not a Shiny input event.

jey1401 commented 3 years ago

Thanks for the quick answer !