in reply to Re^7: Testing javascript on Dancer2 psgi sites
in thread Testing javascript on Dancer2 psgi sites

I did a little more research on Plack::Test. So it turns out you can use it to start up a server with $Plack::Test::Impl like so:

use lib 'lib'; BEGIN { $ENV{'DANCER_ENVIRONMENT'} = 'testing' } use Log::Log4perl qw(:easy); use VoteTracker; use Test::More; use Test::HTML::Content; use Plack::Test; use WWW::Mechanize::Chrome; $Plack::Test::Impl = "Server"; Log::Log4perl->easy_init($ERROR); my $app = VoteTracker->to_app; my $test = Plack::Test->create($app); my $port = $test->port; my $mech = WWW::Mechanize::Chrome->new( headless => 1, report_js_error +s => 1, ); $mech->allow( javascript => 1 ); $mech->get("http://localhost:$port/path/to/page"); xpath_ok($mech->content, '//h1[text()="Hello"]', 'Has proper title'); done_testing;

So this is great. One thing I noticed, however, is that WWW::Mechanize::Chrome is really slow to load. If each test script fires up Chrome, it will take an exceedingly long time to run the tests. Is there a way I can share the Chrome instance across each test?

Update:I've never used it before but I'm thinking Test::Class might be what the doctor ordered to pull this off, right?

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

Replies are listed 'Best First'.
Re^9: Testing javascript on Dancer2 psgi sites
by Corion (Patriarch) on Jan 08, 2018 at 07:58 UTC

    Yes, launching and tearing down WWW::Mechanize::Chrome is slow.

    You could look at keeping a Chrome process around and (re)connect to it on every test run. This is basically possible through the (undocumented as I now see) tab parameter, which takes a regular expression or the word 'current'. Keeping a Chrome process around is mostly untested though, as I usually find it too cumbersome to deal with left-over state from previous test runs, like cookies or other data.