Search code examples
rgwidgetstestthat

gWidget : is there a way to emulate user actions in testthat?


In my package, I'm using testthat and gWidgetRGtk2, I would like to know if there is a way to emulate user actions from the code line, for instance in the following I'm testing an action where the user pushes a button. So far I've been unable to test that part of the code, so I have to manually test all that.

require(gWidgets)
options("guiToolkit"="RGtk2")

win <- gwindow("Hello World", visible=TRUE)
obj <- gbutton("Hello world", container = gwindow(),
 handler = function(h,...) assign("test",1,.GlobalEnv))

require(testthat)
test_that("Test button click",{
     # Something here to emulate pushing button      
      expect_equivalent(test,1)
    })

How can I emulate the user's action ?


Solution

  • After searching quite thoroughly I think the answer is to call the handler function in the test. I didn't find any way to access the the invoke_change_handler from the source code.