This is the very rough cut of combining plackup (in the form of Plack::Runner) and Twiggy with WWW::Mechanize::Chrome. I intend to flesh this out a bit and package it into its own module, but for the time being it works well enough for me.

Currently, this sets up / patches a Dancer application, but I imagine that converting this to use/support Dancer2 shouldn't be too hard, since all you need to get is $app somewhere, and most likely, Dancer2::Test has just enough code to give you the appropriate $app somewhere.

#!perl -w use strict; use Twiggy::Server; use Dancer::Test; use File::Temp 'tempdir'; use WWW::Mechanize::Chrome; use Log::Log4perl qw(:easy); use Data::Dumper; use Test::More tests => 15; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ER +ROR #Log::Log4perl->easy_init($TRACE); # Set priority of root logger to E +RROR my $port = 5099; my $server = Twiggy::Server->new( host => '127.0.0.1', port => $port, ); $ENV{DANCER_APPHANDLER} = 'Dancer::Handler::PSGI'; my $handler = Dancer::Handler->get_handler(); Dancer::_load_app('App::mykeep'); my $app = $handler->psgi_app(); $server->register_service($app); # Fudge the config as appropriate for our test Dancer::config()->{mykeep}->{notes_dir} = tempdir( CLEANUP => 1, ); my @cleanup_directories; my $tempdir = tempdir( CLEANUP => 1 ); my $mech; $mech = WWW::Mechanize::Chrome->new( launch_exe => 'C:\\Users\\Corion\\Projekte\\WWW-Mechanize-Chrome\\ +chrome-versions\\chrome-65.0.3301.0\\chrome.exe', data_directory => $tempdir, #headless => 1, ); $mech->clear_js_errors(); my $console = $mech->add_listener('Runtime.consoleAPICalled', sub { diag join ", ", map { $_->{value} // $_->{description} } @{ $_[0]->{params}->{args} }; }); # run your tests here # ...

In reply to Re^5: Testing javascript on Dancer2 psgi sites by Corion
in thread Testing javascript on Dancer2 psgi sites by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.