From: Phlip Date: 2004-03-17T08:24:34+09:00 Subject: Re: GUI testing on unix > I am curious to if there exists any GUI testing packages for unix. > What about fxruby, gnome, qt, fltk ? Write tests in Ruby that create your forms and manipulate the controls thru Tk's native interface. http://www.rubygarden.org/ruby?SvgCanvas This is the most efficient way, except one cannot use event_generate unless the window displays. To get around this, use bind_info to drill down into the Proc object bound to an event, and call that directly: oval.bind('Button-1') { |event| doc(event) } puts oval.bindinfo('Button-1')[0][0].inspect() puts oval.bindinfo('Button-1')[0][1].inspect() maybeMainloop() The bindinfo() returns an array of arrays. inspecting inside them reveals: # "%# %a %b %c %d %f %h %k %m %o %p %s %t %w %x %y %A %B %D %E %K %N %R %S %T %W %X %Y" That tells us one leaf element of the binding info is a Ruby Proc - a handle to a block - and the next element is a big string representing its 27 arguments. Those match the 27 members of the event object - in the order that TkComm::initialize() used them. So, configure the bound block again, so it prints out the value of every member of the event - using the ordering we researched. Then click on it one more time: assert_equal(oval.class.name(), 'TkcOval') oval.bind('Button-1') { |event| p event.serial p event.above p event.num p event.count p event.detail .. p event.type p event.widget p event.x_root p event.y_root } # puts oval.bindinfo('Button-1')[0][0].inspect() # puts oval.bindinfo('Button-1')[0][1].inspect() maybeMainloop(true) All those p calls (which are secretly puts *.inspect() calls) give us enough data to format this list of arguments: 58, "??", 1, 0, "??", false, 0, 1, "NotifyNormal", false, "PlaceOnTop", 8, 114773445, 0, 80, 26, "??", 209, 1, false, "??", 1, "0x0", "0x0", 4, @canvas, 209, 207 Now replace the p calls inside the event handler with something testable, and call the Proc from the program, instead of by clicking on the oval: assert_equal('TkcOval', oval.class.name()) iGotClicked = false oval.bind('Button-1') { |event| iGotClicked = true } oval.bindinfo('Button-1')[0][0].call( 58, "??", 1, 0, "??", false, 0, 1, "NotifyNormal", false, "PlaceOnTop", 8, 114773445, 0, 80, 26, "??", 209, 1, false, "??", 1, "0x0", "0x0", 4, @canvas, 209, 207 ) assert(iGotClicked) maybeMainloop() And that test passes. We can now write Test Fixtures that simulate user events as close as possible to the real thing, but without going outside Tk, or taking shortcuts. But most projects can take those shortcuts. -- Phlip http://www.xpsd.org/cgi-bin/wiki?TestFirstUserInterfaces