On Tuesday 22 November 2011 18:00:28 Emmanuel Rodriguez wrote:
Aah...finally I got the request to succeed. As it turns out, HTTP::Response::as_string returns a fine HTTP response, except for the leading "HTTP/1.0". If I add that manually, libsoup seems to like the response.I'm glad to see that it's working.
Unfortunately I still had to give up the whole answer-in-process route. Though I could make it create working requests to my HTTP echo server, I was unable to access the request body which made anything but simple GET requests fail. On the other hand I have made great progress with just forking out a Catalyst server and accessing that just like Test::WWW::Selenium::Catalyst does. The for me crucial improvement is, that I use a random port and retry with a different if this port is already used. This allows me to run tests reliably in parallel, speeding up our test suite.
I looked quickly at your code and I have a few suggestions/comments. Most the JS calls that you're doing can be rewritten in perl. WebKit exposes a lot of it's API and it's not needed to use JS to manipulate its DOM.
Thanks for this hint. I converted most of the JS code to Perl and while it took me quite a while to get it right, it now works better than the original stuff.
The same cound be done with click_ok() you should be able to get the DOM element from perl and to send a click event. I haven't tried it yet, if you do let me know.
This is where things get ugly. Unfortunately, Webkit's event generating functions are very limited. I can generate the click event but things like simple KeyPress events are a real problem. I can generate the KeyboardEvent but the keycode is always 0. This is a known bug in Webkit and does not even work in JavaScript. So there's actually no way to synthesize keyboard events. So my new approach is to generate a key event at Gtk3 level and send it to the Webkit widget. After all this would be even more realisitc. But again this is quite difficult. There is a Gtk3::Gdk::Event class available, but no Gtk3::Gdk::Event::Key or Gtk3::Gdk::EventKey or anything like that. From reading the .gir file the latter should exist, but it just doesn't. If it's missing in the bindings, how could I add it? And even if I could create it, I still don't know how to actually set the keycode field in the struct. There's pretty much no documentation and lot's of guess work on how Perl maps to Gtk3...
If you don't want to have a window around you can create an off screen window instead of a real window. This works like a normal window except that you don't see it. Sample: my $window = Gtk3::OffscreenWindow->new(); You can find some sample perl programs that use WebKit in my git repo https://github.com/potyl/Webkit, I hope that it helps.
Thanks. Your examples have been of great value in this adventure :) Again attaching the current state for those interested. I probably should put this stuff into a public repo :) Stefan
Attachment:
Catalyst.pm
Description: Perl program