Skip to content

Default to screenshot-ing the viewport (and/or make it easier?)  #293

Closed

Description

@cpsievert

I'm not sure if this should be done in shinytest2 or chromote, but the fact that expect_values() calls expect_screenshot() (by default) which calls ChromoteSession$screenshot(), which defaults to selector = "html", which can pretty easily error out with

In addition: Warning message:
In onRejected(reason) :
  An error occurred: Error in onRejected(...): code: -32000
  message: Cannot take screenshot with 0 height.

makes me think that {shinytest2} should default to screenshoting the viewport. Not only does it seem safer, but also probably more intuitive to the average user. Here's some code I wrote recently for this:

https://github.com/rstudio/shinycoreci/blob/b4e06bf17f168cbacda798539688818225dfa9f1/inst/apps/304-bslib-card/tests/testthat/test-shinytest2.R#L25-L35

Activity

  1. cpsievert commented on Dec 12, 2022

    @cpsievert
    ContributorAuthor

    Another random thought....if changing the default is going to be too painful, maybe we could keep it, but fallback to the viewport on error (and emit a warning)?

  2. cpsievert commented on Feb 6, 2023

    @cpsievert
    ContributorAuthor

    Here's a minimal reprex (run shinytest2::record_test() on this and take a screenshot...you should get an error similar to the one above

    library(shiny)
    
    ui <- div(
      style = htmltools::css(height = "400px", background = "red"),
      tags$head(tags$style("html {height: 0}"))
    )
    
    shinyApp(ui, \(...){})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions