WWW-Mechanize-Chrome-0.79/0000755000175000017500000000000015211474440014617 5ustar corioncorionWWW-Mechanize-Chrome-0.79/README0000644000175000017500000000401415211474437015504 0ustar corioncorionWWW::Mechanize::Chrome - automate the Chrome browser DESCRIPTION Like L, this module automates web browsing with a Perl object. Fetching and rendering of web pages is delegated to the Chrome (or Chromium) browser by starting an instance of the browser and controlling it with L. INSTALLATION This is a Perl module distribution. It should be installed with whichever tool you use to manage your installation of Perl, e.g. any of cpanm . cpan . cpanp -i . Consult http://www.cpan.org/modules/INSTALL.html for further instruction. Should you wish to install this module manually, the procedure is perl Makefile.PL make make test make install REPOSITORY The public repository of this module is L. SUPPORT The public support forum of this module is L. TALKS I've given a German talk at GPW 2017, see L and L for the slides. At The Perl Conference 2017 in Amsterdam, I also presented a talk, see L. The slides for the English presentation at TPCiA 2017 are at L. At the London Perl Workshop 2017 in London, I also presented a talk, see L . The slides for that talk are L. KNOWN ISSUES Please see L. BUG TRACKER Please report bugs in this module via the Github bug queue at L CONTRIBUTING Please see L. SEE ALSO AUTHOR Max Maischein C LICENSE This module is released under the same terms as Perl itself. COPYRIGHT (c) Copyright 2010-2026 by Max Maischein C. WWW-Mechanize-Chrome-0.79/t/0000755000175000017500000000000015211474440015062 5ustar corioncorionWWW-Mechanize-Chrome-0.79/t/50-mech-content-nonhtml.t0000644000175000017500000000165215211474437021544 0ustar corioncorion#!perl -w use strict; use Test::More; use WWW::Mechanize::Chrome; use Log::Log4perl qw(:easy); use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); my $testcount = 2; if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => $testcount*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; t::helper::run_across_instances(\@instances, \&new_mech, $testcount, sub { my ($browser_instance, $mech) = @_; isa_ok $mech, 'WWW::Mechanize::Chrome'; $mech->get('https://corion.net/style.css'); my $body = $mech->decoded_content(); like $body, qr!^/\*!, "We retrieve the raw CSS"; }); WWW-Mechanize-Chrome-0.79/t/52-secondary-subframe.html0000644000175000017500000000053315211474437021774 0ustar corioncorion 52-secondary-subframe.html
52-secondary-subframe.html
WWW-Mechanize-Chrome-0.79/t/65-is_visible_hidden.html0000644000175000017500000000114615211474437021653 0ustar corioncorion 65-is_visible_hidden.html

Text before

Text after

WWW-Mechanize-Chrome-0.79/t/65-is_visible.t0000644000175000017500000001565515211474437017651 0ustar corioncorion#!perl use strict; use warnings; use Test::More; use WWW::Mechanize::Chrome; use Cwd; use URI; use URI::file; use File::Basename; use File::Spec; use File::Temp 'tempdir'; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # A parallelization hack can prefill @files already with other files # see t/65-is_visible-2.t our @files; if( !@files) { @files = qw< 65-is_visible_class.html 65-is_visible_text.html 65-is_visible_hidden.html >; }; # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => (12*@files+5)*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, #headless => 0, ); }; t::helper::run_across_instances(\@instances, \&new_mech, 12*@files+5, sub { my ($browser_instance, $mech) = @_; isa_ok $mech, 'WWW::Mechanize::Chrome'; # Check that we can execute JS $mech->get_local($files[0]); $mech->allow('javascript' => 1); my ($triggered,$type,$ok); eval { ($triggered, $type) = $mech->eval_in_page('timer'); $ok = 1; }; if (! $triggered) { SKIP: { skip("Couldn't get at 'timer'. Do you have a Javascript blocker?", 12*@files +5); }; return; }; # Check that we can trigger the timeout for my $file ($files[0]) { $mech->get_local($file); is $mech->title, $file, "We loaded the right file ($file)"; $mech->allow('javascript' => 1); ok $mech->is_visible(selector => '#before'), "The element is visible"; my $finished = eval { $mech->wait_until_invisible(selector => '#before', timeout => 1); 1; }; is $finished, undef, "We got an exception"; like $@, qr/Timeout/, "We got a timeout error message"; }; for my $file (@files) { $mech->get_local($file); is $mech->title, $file, "We loaded the right file ($file)"; $mech->allow('javascript' => 1); my ($timer,$type) = $mech->eval_in_page('timer'); #(my ($window),$type) = $mech->eval_in_page('window'); #$window = $mech->tab->{linkedBrowser}->{contentWindow}; ok $mech->is_visible(selector => 'body'), "We can see the body"; if(! ok !$mech->is_visible(selector => '#standby'), "We can't see #standby") { my $standby = $mech->by_id('standby', single=>1); my $style = $standby->{style}; diag "style.visibility <" . $style->{visibility} . ">"; diag "style.display <" . $style->{display} . ">"; #$style = $window->getComputedStyle($standby, undef); diag "computed-style.visibility <" . $style->{visibility} . ">"; diag "computed-style.display <" . $style->{display} . ">"; }; ok !$mech->is_visible(selector => '.status', any => 1), "We can't see .status even though there exist multiple such elements"; $mech->click({ selector => '#start', synchronize => 0 }); my $timeout = time+2; while( time < $timeout and !$mech->is_visible(selector => '#standby')) { $mech->sleep(0.1); }; ok $mech->is_visible(selector => '#standby'), "We can see #standby"; my $ok = eval { $mech->wait_until_invisible(selector => '#standby', timeout => $timer+2); 1; }; is $ok, 1, "No timeout" or diag $@; if(! ok( !$mech->is_visible(selector => '#standby'), "The #standby is invisible")) { my $standby = $mech->by_id('standby', single=>1); my $style = $standby->{style}; diag "style.visibility <" . $style->{visibility} . ">"; diag "style.display <" . $style->{display} . ">"; #$style = $window->getComputedStyle($standby, undef); diag "computed-style.visibility <" . $style->{visibility} . ">"; diag "computed-style.display <" . $style->{display} . ">"; }; # Now test with plain text $mech->get_local($file); is $mech->title, $file, "We loaded the right file ($file)"; $mech->allow('javascript' => 1); ($timer,$type) = $mech->eval_in_page('timer'); if(! ok( !$mech->is_visible(xpath => '//*[contains(text(),"stand by")]'), "We can't see the standby message (via its text)")) { my $standby = $mech->by_id('standby', single=>1); my $style = $standby->{style}; diag "style.visibility <" . $style->{visibility} . ">"; diag "style.display <" . $style->{display} . ">"; #$style = $window->getComputedStyle($standby, undef); diag "computed-style.visibility <" . $style->{visibility} . ">"; diag "computed-style.display <" . $style->{display} . ">"; }; $mech->click({ selector => '#start', synchronize => 0 }); # Busy-wait $timeout = time+2; while( time < $timeout and !$mech->is_visible(xpath => '//*[contains(text(),"stand by")]')) { $mech->sleep(0.1); }; if(! ok $mech->is_visible(xpath => '//*[contains(text(),"stand by")]'), "We can see the standby message (via its text)") { my $standby = $mech->by_id('standby', single=>1); my $style = $standby->{style}; diag "style.visibility <" . $style->{visibility} . ">"; diag "style.display <" . $style->{display} . ">"; #$style = $window->getComputedStyle($standby, undef); diag "computed-style.visibility <" . $style->{visibility} . ">"; diag "computed-style.display <" . $style->{display} . ">"; }; $ok = eval { # This needs to re-query every time as the text changes!! $mech->wait_until_invisible(xpath => '//*[contains(text(),"stand by")]', timeout => $timer+2); 1; }; if(! is $ok, 1, "No timeout") { diag $@; for ($mech->xpath('//*[contains(text(),"stand by")]')) { diag $_->{tagName}, $_->{innerHTML}; }; my $standby = $mech->xpath('//*[contains(text(),"stand by")]', single=>1); my $style = $standby->{style}; diag "style.visibility <" . $style->{visibility} . ">"; diag "style.display <" . $style->{display} . ">"; #$style = $window->getComputedStyle($standby, undef); diag "computed-style.visibility <" . $style->{visibility} . ">"; diag "computed-style.display <" . $style->{display} . ">"; }; ok !$mech->is_visible(selector => '#standby'), "The #standby is invisible"; }; }); WWW-Mechanize-Chrome-0.79/t/50-click.html0000644000175000017500000000210415211474437017262 0ustar corioncorion 50-click.html
A link
Some div
Open a window (or tab) WWW-Mechanize-Chrome-0.79/t/50-form-with-fields.t0000644000175000017500000000411015211474437020653 0ustar corioncorion#!/usr/bin/perl -w # file 50-form3.t use strict; use Test::More; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => 8*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; t::helper::run_across_instances(\@instances, \&new_mech, 8, sub { my ($browser_instance, $mech) = @_; $mech->get_local('50-form3.html'); $mech->form_number(1); my $the_form_dom_node = $mech->current_form; my $button = $mech->selector('#btn_ok', single => 1); isa_ok $button, 'WWW::Mechanize::Chrome::Node', "The button image"; ok $mech->submit, 'Sent the page'; $mech->get_local('50-form3.html'); @{$mech->{event_log}} = (); $mech->form_id('snd'); if(! ok $mech->current_form, "We can find a form by its id") { for (@{$mech->{event_log}}) { diag $_ }; }; $mech->get_local('50-form3.html'); $mech->form_with_fields('r1[name]'); ok $mech->current_form, "We can find a form by its contained input fields (single,matched)"; $mech->get_local('50-form3.html'); $mech->form_with_fields('r1[name]','r2[name]'); ok $mech->current_form, "We can find a form by its contained input fields (double,matched)"; $mech->get_local('50-form3.html'); $mech->form_with_fields('r3name]'); ok $mech->current_form, "We can find a form by its contained input fields (single,closing)"; $mech->get_local('50-form3.html'); $mech->form_with_fields('r4[name'); ok $mech->current_form, "We can find a form by its contained input fields (single,opening)"; $mech->get_local('50-form3.html'); $mech->form_name('snd'); ok $mech->current_form, "We can find a form by its name"; }); WWW-Mechanize-Chrome-0.79/t/78-memleak.t0000644000175000017500000000732215211474437017130 0ustar corioncorion#!perl -w use strict; use Test::More; use Cwd; use URI::file; use File::Basename; use File::Spec; use Data::Dumper; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use lib '.'; use t::helper; use Capture::Tiny 'capture'; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); my $testcount = 14; if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => $testcount*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); my %args = @_; my $transport = WWW::Mechanize::Chrome->_preferred_transport( \%args ); if( $transport =~ /Pipe::AnyEvent$/ ) { die "AnyEvent Pipe transport is broken for this test"; # And I don't even know what tickles it, and not the other tests }; WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; my $have_test_memory_cycle = eval {; require Test::Memory::Cycle; 1; }; sub no_memory_cycles_ok { my( $mech, $name ) = @_; if( $have_test_memory_cycle ) { capture { Test::Memory::Cycle::memory_cycle_ok($mech, "No cycles $name"); }; } else { SKIP: { skip "Test::Memory::Cycle needed for deeper leak testing", 1; }; }; } sub load_file_ok { my ($mech, $htmlfile,@options) = @_; my $fn = File::Spec->rel2abs( File::Spec->catfile(dirname($0),$htmlfile), getcwd, ); #$mech->allow(@options); #diag "Loading $fn"; $mech->get_local($fn); ok $mech->success, "Loading $htmlfile is considered a success"; is $mech->title, $htmlfile, "We loaded the right file (@options)" or diag $mech->content; }; t::helper::run_across_instances(\@instances, \&new_mech, $testcount, sub { my ($browser_instance, $mech) = @_; $mech = new_mech( headless => 1 ); no_memory_cycles_ok( $mech, "at the start" ); my $old_destroy = $mech->can('DESTROY'); my $called = 0; no warnings 'redefine'; local *WWW::Mechanize::Chrome::DESTROY = sub { $called++; goto &$old_destroy; }; undef $mech; is $called, 1, "We destroyed our object immediately after loading"; note "Constructing fresh mechanize"; $mech = new_mech( headless => 1 ); load_file_ok($mech, 'xhtml.xhtml', javascript => 1); no_memory_cycles_ok( $mech, "after loading a page" ); $called = 0; undef $mech; is $called, 1, "We destroyed our object after loading"; note "Constructing fresh mechanize"; $mech = new_mech( headless => 1 ); $called = 0; my @alerts; $mech->on_dialog( sub { my ( $mech, $dialog ) = @_; push @alerts, $dialog; $mech->handle_dialog(1); # I always click "OK", why? }); load_file_ok($mech, '58-alert.html', javascript => 1); no_memory_cycles_ok( $mech, "after an alert()" ); undef $mech; is $called, 1, "We destroyed our object after ->on_dialog"; $called = 0; note "Constructing fresh mechanize"; $mech = new_mech( headless => 1 ); $mech->setScreenFrameCallback(sub {}); $mech->sleep(0.1); $mech->setScreenFrameCallback(); no_memory_cycles_ok( $mech, "after a screen cast frame" ); undef $mech; is $called, 1, "We destroyed our object after a frame was grabbed"; $called = 0; $mech = new_mech( headless => 1 ); $mech->get_local('49-mech-get-file.html'); my @results = $mech->xpath('//*'); no_memory_cycles_ok( $mech, "after an xpath search" ); undef $mech; is $called, 1, "We destroyed our object after a search was performed"; }); WWW-Mechanize-Chrome-0.79/t/58-alert.t0000644000175000017500000000306115211474437016616 0ustar corioncorion#!perl -w use strict; use Test::More; use Cwd; use URI::file; use File::Basename; use File::Spec; use Data::Dumper; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => 4*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; sub load_file_ok { my ($mech, $htmlfile,@options) = @_; my $fn = File::Spec->rel2abs( File::Spec->catfile(dirname($0),$htmlfile), getcwd, ); #$mech->allow(@options); #diag "Loading $fn"; $mech->get_local($fn); ok $mech->success, "Loading $htmlfile is considered a success"; is $mech->title, $htmlfile, "We loaded the right file (@options)" or diag $mech->content; }; t::helper::run_across_instances(\@instances, \&new_mech, 4, sub { my ($browser_instance, $mech) = @_; isa_ok $mech, 'WWW::Mechanize::Chrome'; my @alerts; $mech->on_dialog( sub { my ( $mech, $dialog ) = @_; push @alerts, $dialog; $mech->handle_dialog(1); # I always click "OK", why? }); load_file_ok($mech, '58-alert.html', javascript => 1); is 0+@alerts, 2, "got two alerts"; undef $mech; }); WWW-Mechanize-Chrome-0.79/t/49-port.t0000644000175000017500000000206515211474437016476 0ustar corioncorion#!perl use warnings; use strict; use Test::More; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use lib '.'; use Test::HTTP::LocalServer; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR #Log::Log4perl->easy_init($DEBUG); # Set priority of root logger to ERROR # What instances of Chrome will we try? my $instance_port = 9223; my @instances = t::helper::browser_instances(); if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => 1*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, port => $instance_port, @_, ); }; my $server = Test::HTTP::LocalServer->spawn( #debug => 1, ); t::helper::run_across_instances(\@instances, \&new_mech, 1, sub { my ($browser_instance, $mech) = splice @_; $mech->get($server->url); pass "We can connect to port $instance_port"; undef $mech; }); $server->stop; WWW-Mechanize-Chrome-0.79/t/51-mech-find-all-links.t0000644000175000017500000000222015211474437021212 0ustar corioncorion#!perl use warnings; use strict; use Test::More; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use lib '.'; use Test::HTTP::LocalServer; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); my $testcount = 10; if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => $testcount*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, #headless => 0, ); }; sub WWW::Mechanize::chrome_version { "62.0.0.0" } my $server = Test::HTTP::LocalServer->spawn( #debug => 1, ); t::helper::run_across_instances(\@instances, \&new_mech, $testcount, sub { my( $file, $mech ) = splice @_; # so we move references $mech->get($server->url); my $url = $server->url; my $links = $mech->find_all_links(); for my $link (@$links) { like $link->url_abs, qr!^\Q$url!, "Link is absolute"; }; }); $server->stop; WWW-Mechanize-Chrome-0.79/t/49-pipe.t0000644000175000017500000000237715211474437016455 0ustar corioncorion#!perl use warnings; use strict; use stable 'postderef'; use Test::More; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use Test::HTTP::LocalServer; use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR my @instances = t::helper::browser_instances(); my $testcount = 3; if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } elsif ( $^O =~ /mswin/i ) { plan skip_all => "Pipes are currently unsupported on $^O"; } else { plan tests => $testcount*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '72.0.0.0', @_ ); WWW::Mechanize::Chrome->new( @_, pipe => 1, ); }; my $server = Test::HTTP::LocalServer->spawn( ); t::helper::run_across_instances(\@instances, \&new_mech, $testcount, sub { my ($browser_instance, $mech) = splice @_; $mech->get($server->url); pass "We launch Chrome and control it via two filehandles"; my $pids = $mech->{pid}; like $mech->title, qr/^WWW::Mechanize::Firefox test page$/, "Retrieving the title works"; undef $mech; my $alive = kill( 0 => $pids->@*); is $alive, 0, "The chrome process $pids->@* was removed"; }); $server->stop; WWW-Mechanize-Chrome-0.79/t/76-infinite-scroll.html0000644000175000017500000000337215211474437021316 0ustar corioncorion
WWW-Mechanize-Chrome-0.79/t/49-launch.t0000644000175000017500000000173015211474437016762 0ustar corioncorion#!perl use warnings; use strict; use Test::More tests => 5; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR my ($program,$msg) = WWW::Mechanize::Chrome->find_executable('path/another-nonexistent'); is $program, undef, "Nonexisting program does not get found"; like $msg, qr/^No executable like '.*' found$/, "We signal the correct error"; { local $ENV{CHROME_BIN} = 'bar'; is_deeply [WWW::Mechanize::Chrome->default_executable_names('foo')], ['bar','foo'], "CHROME_BIN overrides hardcoded values"; }; { local $ENV{CHROME_BIN}; my $lives = eval { WWW::Mechanize::Chrome->new( launch_exe => 'program.that.doesnt.exist', ); 1; }; my $err = $@; is $lives, undef, "We die if we can't find the executable in \$ENV{PATH}"; like $@, qr/No executable like '.*?' found in/, "We signal the error condition"; };WWW-Mechanize-Chrome-0.79/t/51-mech-submit.html0000644000175000017500000000272615211474437020425 0ustar corioncorion Hello Chrome!
WWW-Mechanize-Chrome-0.79/t/50-mech-get.t0000644000175000017500000000367315211474437017201 0ustar corioncorion#!perl -w use strict; use Test::More; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use lib '.'; use Test::HTTP::LocalServer; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); my $testcount = 9; if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => $testcount*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; my $server = Test::HTTP::LocalServer->spawn( #debug => 1, ); t::helper::run_across_instances(\@instances, \&new_mech, $testcount, sub { my ($browser_instance, $mech) = @_; isa_ok $mech, 'WWW::Mechanize::Chrome'; my ($site,$estatus) = ($server->url,200); my $res = $mech->get($site); isa_ok $res, 'HTTP::Response', "Response"; is $mech->uri, $site, "Navigated to $site"; is $res->code, $estatus, "GETting $site returns HTTP code $estatus from response" or diag $mech->content; is $mech->status, $estatus, "GETting $site returns HTTP status $estatus from mech" or diag $mech->content; ok $mech->success, 'We consider this response successful'; # Check that we can GET a binary file and see its content for download note my $url = $server->local('blank.jpg'); $res = $mech->get($url); isa_ok $res, 'HTTP::Response', "We get a response for a direct image URL"; is $res->code, $estatus, "GETting image returns 200" or diag $mech->content; #like $mech->content, qr/^sleep(0.1); # we need to give the response body time to arrive :( like $res->decoded_content, qr/^\xff\xd8\xff.*?JFIF/ms, "We have an image in the response"; }); $server->stop; WWW-Mechanize-Chrome-0.79/t/50-mech-eval.t0000644000175000017500000000241115211474437017336 0ustar corioncorion#!perl -w use strict; use Test::More; use WWW::Mechanize::Chrome; use Log::Log4perl qw(:easy); use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); my $testcount = 4; if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => $testcount*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; t::helper::run_across_instances(\@instances, \&new_mech, $testcount, sub { my ($browser_instance, $mech) = @_; isa_ok $mech, 'WWW::Mechanize::Chrome'; my ($val, $type) = $mech->eval('new Object'); is $type, "object", "We can create simple objects and serialize them as JSON"; ($val, $type) = $mech->eval('window', returnByValue => JSON::false); is $type, "object", "We can also return (proxies for) unserializable objects"; ($val, $type) = $mech->callFunctionOn('function add(a,b){ return a+b }', arguments => [ {value => 2 }, { value => 2 }]); is $val, 4, "We can call functions without manually encoding parameters"; }); WWW-Mechanize-Chrome-0.79/t/61-mech-download.t0000644000175000017500000000470715211474437020232 0ustar corioncorion#!perl -w use strict; use Test::More; use Cwd; use URI::file; use File::Basename; use File::Spec; use File::Temp 'tempdir'; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use lib '.'; use Test::HTTP::LocalServer; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => 5*@instances; }; my $d = tempdir( CLEANUP => 1 ); -d $d or diag "Temp directory '$d' doesn't exist?!: $!"; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, download_directory => $d, @_, #headless => 0, ); }; my $server = Test::HTTP::LocalServer->spawn( #debug => 1 ); t::helper::run_across_instances(\@instances, \&new_mech, 5, sub { my ($browser_instance, $mech) = @_; isa_ok $mech, 'WWW::Mechanize::Chrome'; SKIP: { my $version = $mech->chrome_version; if( $version =~ /\b(\d+)\b/ and $1 < 62 ) { skip "Chrome before v62 doesn't know about downloads...", 4; } elsif( $version =~ /\b(\d+)\.\d+\.(\d+)\b/ and ($1 == 63 and $2 >= 3239)) { skip "Chrome before v63 build 3292 doesn't know about downloads anymore", 4; # No, but Chrome 63 doesn't send proper events for downloaded files # we could try with networkIdle ... } elsif( $version =~ /\b(\d+)\b/ and $1 >= 64 and $1 <= 65 ) { skip "Chrome between v64 and v65 doesn't tell us about downloads...", 4; # Actually, they are missing any kind of sensible events to tell us # anything about the quality of the response } else { my ($site,$estatus) = ($server->download('mytest.txt'),200); my $res = $mech->get($site); isa_ok $res, 'HTTP::Response', "Response"; ok $mech->success, "The download (always) succeeds"; like $res->header('Content-Disposition'), qr/attachment;/, "We got a download response"; my $timeout = time+1; while( time < $timeout && ! -f "$d/mytest.txt" ) { $mech->sleep(0.1); }; ok -f "$d/mytest.txt", "File 'mytest.txt' was downloaded OK"; }; } }); $server->stop; done_testing; WWW-Mechanize-Chrome-0.79/t/65-is_visible_class.html0000644000175000017500000000122515211474437021523 0ustar corioncorion 65-is_visible_class.html

Text before

Please stand by

Text after

WWW-Mechanize-Chrome-0.79/t/html5.html0000644000175000017500000000110015211474437016777 0ustar corioncorion Hello, World!
WWW-Mechanize-Chrome-0.79/t/51-mech-links-base.html0000644000175000017500000000064515211474437021150 0ustar corioncorion Hello Firefox!

Hello World!

Hello WWW::Mechanize::Firefox

Links

relative WWW-Mechanize-Chrome-0.79/t/50-follow-link.t0000644000175000017500000000522415211474437017737 0ustar corioncorion#!perl -w use strict; use Test::More; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => 9*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; t::helper::run_across_instances(\@instances, \&new_mech, 9, sub { my ($browser_instance, $mech) = @_; isa_ok $mech, 'WWW::Mechanize::Chrome'; $mech->autodie(1); $mech->get_local('50-click.html'); $mech->allow('javascript' => 1); my ($clicked,$type,$ok); eval { ($clicked, $type) = $mech->eval_in_page('clicked'); $ok = 1; }; diag $@ if $@; if (! $clicked) { SKIP: { skip "Couldn't get at 'clicked'. Do you have a Javascript blocker?", 8; }; return; }; ok $clicked, "We found 'clicked'"; # Xpath $mech->get_local('50-click.html'); $mech->allow('javascript' => 1); $mech->follow_link( xpath => '//*[@id="a_link"]', synchronize=>0, ); ($clicked,$type) = $mech->eval_in_page('clicked'); is $clicked, 'a_link', "->follow_link() with an xpath selector works"; # CSS $mech->get_local('50-click.html'); $mech->allow('javascript' => 1); $mech->follow_link( selector => '#a_link', synchronize=>0, ); ($clicked,$type) = $mech->eval_in_page('clicked'); is $clicked, 'a_link', "->follow_link() with a CSS selector works"; # Regex $mech->get_local('50-click.html'); $mech->allow('javascript' => 1); $mech->follow_link( text_regex => qr/A link/, synchronize => 0 ); ($clicked,$type) = $mech->eval_in_page('clicked'); is $clicked, 'a_link', "->follow_link() with a RE works"; # Non-existing link $mech->get_local('50-click.html'); my $lives = eval { $mech->follow_link('foobar'); 1 }; my $msg = $@; ok !$lives, "->follow_link() on non-existing parameter fails correctly"; like $msg, qr/No elements found for Button with name 'foobar'/, "... with the right error message"; # Non-existing link via CSS selector $mech->get_local('50-click.html'); $lives = eval { $mech->follow_link({ selector => 'foobar' }); 1 }; $msg = $@; ok !$lives, "->follow_link() on non-existing parameter fails correctly"; like $msg, qr/No elements found for CSS selector 'foobar'/, "... with the right error message"; }); WWW-Mechanize-Chrome-0.79/t/49-mech-nav.t0000644000175000017500000000314715211474437017212 0ustar corioncorion#!perl use warnings; use strict; use Test::More; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use lib '.'; use Test::HTTP::LocalServer; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); my $testcount = 5; if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => 5*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, #headless => 0, ); }; my $server = Test::HTTP::LocalServer->spawn( #debug => 1, ); t::helper::run_across_instances(\@instances, \&new_mech, $testcount, sub { my( $file, $mech ) = splice @_; # so we move references $mech->get($server->url); $mech->click_button(number => 1); like( $mech->uri, qr/formsubmit/, 'Clicking on button by number' ); my $last = $mech->uri; $mech->back; is $mech->uri, $server->url, 'We went back'; $mech->forward; is $mech->uri, $last, 'We went forward'; my $version = $mech->chrome_version; SKIP: { #if( $version =~ /\b(\d+)\b/ and $1 < 66 ) { $mech->reload; is $mech->uri, $last, 'We reloaded'; $mech->reload( ignoreCache => 1 ); is $mech->uri, $last, 'We reloaded, ignoring the cache'; #} else { # skip "Chrome v66+ doesn't know how to reload without hanging in a dialog box", 1; #} }; }); $server->stop; WWW-Mechanize-Chrome-0.79/t/50-form3.html0000644000175000017500000000555215211474437017235 0ustar corioncorion untitled
Legno Legno: (1800)
Argilla Argilla: (1800)
Ferro Ferro: (1800)
Grano Grano: (1800)
Mercanti 20/20
Villaggio:
oppure
X: Y:

WWW-Mechanize-Chrome-0.79/t/65-is_visible_none_to_visible.html0000644000175000017500000000113415211474437023573 0ustar corioncorion 65-is_visible_none_to_visible.html

Text before

Text after

WWW-Mechanize-Chrome-0.79/t/03-listener-leak-test.t0000644000175000017500000000612015211474437021210 0ustar corioncorion#!perl -w use strict; use Test::More; use WWW::Mechanize::Chrome; use Test::HTTP::LocalServer; use Data::Dumper; use Log::Log4perl qw(:easy); use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR #Log::Log4perl->easy_init($TRACE) # if $^O =~ /darwin/i; # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); my $testcount = 11; if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => $testcount*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; my $server = Test::HTTP::LocalServer->spawn( #debug => 1, ); t::helper::run_across_instances(\@instances, \&new_mech, $testcount, sub { my ($browser_instance, $mech) = @_; my ($site,$estatus) = ($server->url,200); my $res = $mech->get($site); for( 1..10 ) { my @input = $mech->xpath('//input[@name="q"]'); }; is scalar @{ $mech->driver->listener->{'DOM.setChildNodes'} || []}, 0, "We don't accumulate listeners"; my $destroyed = 0; my $old_destroy = \&Chrome::DevToolsProtocol::EventListener::DESTROY; no warnings 'redefine'; local *Chrome::DevToolsProtocol::EventListener::DESTROY = sub { $destroyed++; goto &$old_destroy; }; # Set up our listener $mech->on_dialog(sub { # ... }); is scalar @{ $mech->driver->listener->{'Page.javascriptDialogOpening'} }, 1, "We have exactly one listener"; # Remove our listener $mech->on_dialog(undef); is scalar @{ $mech->driver->listener->{'Page.javascriptDialogOpening'} }, 0, "We remove it"; is $destroyed, 1, "our destructor gets called"; is scalar @{ $mech->driver->listener->{'Runtime.consoleAPICalled'} }, 1, "We have one console listener already"; $destroyed = 0; my $called = 0; my $console = $mech->add_listener('Runtime.consoleAPICalled', sub { $called++; }); is scalar @{ $mech->driver->listener->{'Runtime.consoleAPICalled'} }, 2, "We have one listener more"; $mech->driver->on_response(undef, '{"method":"Runtime.consoleAPICalled"}'); is $called, 1, "Our handler was called"; $console->unregister; $called = 0; $destroyed = 0; $mech->driver->on_response(undef, '{"method":"Runtime.consoleAPICalled"}'); is $called, 0, "Our handler was not called after manual removal"; is scalar @{ $mech->driver->listener->{'Runtime.consoleAPICalled'} }, 1, "We remove it"; undef $console; is $destroyed, 1, "our destructor gets called"; $called = 0; $console = $mech->add_listener('Runtime.consoleAPICalled', sub { $called++; }); $mech->remove_listener( $console ); $mech->driver->on_response(undef, '{"method":"Runtime.consoleAPICalled"}'); is $called, 0, "Our handler was not called after manual removal via ->remove_listener"; note "Test with one browser instance finished"; }); note "Stopping local HTTP server"; $server->stop; note "Shutting down"; WWW-Mechanize-Chrome-0.79/t/49-mech-get-file.t0000644000175000017500000000451315211474437020120 0ustar corioncorion#!perl -w use strict; use Test::More; use Cwd; use URI::file; use File::Basename; use File::Spec; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => 14*@instances; }; use Data::Dumper; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; sub load_file_ok { my ($mech, $htmlfile,@options) = @_; my $fn = File::Spec->rel2abs( File::Spec->catfile(dirname($0),$htmlfile), getcwd, ); #$mech->allow(@options); note "Loading $fn"; $mech->get_local($fn); ok $mech->success, "Loading $htmlfile is considered a success"; is $mech->title, $htmlfile, "We loaded the right file (@options)" or diag $mech->content; }; t::helper::run_across_instances(\@instances, \&new_mech, 14, sub { my ($firefox_instance, $mech) = @_; isa_ok $mech, 'WWW::Mechanize::Chrome'; load_file_ok($mech, '49-mech-get-file.html', javascript => 0); is $mech->content_type, 'text/html', "HTML content type"; $mech->get('about:blank'); load_file_ok($mech, '49-mech-get-file.html', javascript => 1); $mech->get('about:blank'); $mech->get_local('49-mech-get-file.html'); ok $mech->success, '49-mech-get-file.html'; is $mech->title, '49-mech-get-file.html', "We loaded the right file"; ok $mech->is_html, "The local file gets identified as HTML" or diag $mech->content; $mech->get_local('49-mech-get-file-lc-ct.html'); ok $mech->success, '49-mech-get-file-lc-ct.html'; is $mech->title, '49-mech-get-file-lc-ct.html', "We loaded the right file"; ok $mech->is_html, "The local file gets identified as HTML even with a weird-cased http-equiv attribute" or diag $mech->content; is $mech->content_type, 'text/html', "HTML content type is read from http-equiv meta tag"; $mech->get_local('file-does-not-exist.html'); ok !$mech->success, 'We fail on non-existing file'; #or diag $mech->content; }); WWW-Mechanize-Chrome-0.79/t/select.t0000644000175000017500000000752315211474437016543 0ustar corioncorion#!perl -w #use warnings; use strict; use Test::More; BEGIN { delete @ENV{qw(PATH IFS CDPATH ENV BASH_ENV)}; # Placates taint-unsafe Cwd.pm in 5.6.1 } use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); my $testcount = 20; if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => $testcount*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; t::helper::run_across_instances(\@instances, \&new_mech, $testcount, sub { my ($browser_instance, $mech) = @_; #my $uri = URI::file->new_abs( 't/select.html' )->as_string; my $response = $mech->get_local( 'select.html' ); ok( $response->is_success, "Fetched select.html" ); my ($sendsingle, @sendmulti, %sendsingle, %sendmulti, $rv, $return, @return, @singlereturn, $form); # possible values are: aaa, bbb, ccc, ddd $sendsingle = 'aaa'; @sendmulti = qw(bbb ccc); @singlereturn = ($sendmulti[0]); %sendsingle = (n => 1); %sendmulti = (n => [2, 3]); ok($mech->form_number(1), 'set form to number 1'); $form = $mech->current_form(); # Multi-select # pass multiple values to a multi select $mech->select('multilist', \@sendmulti); @return = $mech->value('multilist'); is_deeply(\@return, \@sendmulti, 'multi->multi value is ' . join(' ', @sendmulti)); $response = $mech->get_local( 'select.html' ); ok( $response->is_success, "Fetched select.html" ); $mech->select('multilist', \%sendmulti); @return = $mech->value('multilist'); is_deeply(\@return, \@sendmulti, 'multi->multi value is ' . join(' ', @sendmulti)); # pass a single value to a multi select $response = $mech->get_local( 'select.html' ); ok( $response->is_success, "Fetched select.html" ); $mech->select('multilist', $sendsingle); #$return = $form->param('multilist'); $return = $mech->value('multilist'); is($return, $sendsingle, "single->multi value is '$sendsingle'"); $response = $mech->get_local( 'select.html' ); ok( $response->is_success, "Fetched select.html" ); $mech->select('multilist', \%sendsingle); $return = $mech->value('multilist'); is($return, $sendsingle, "single->multi value is '$sendsingle'"); # Single select # pass multiple values to a single select (only the _first_ should be set) $response = $mech->get_local( 'select.html' ); ok( $response->is_success, "Fetched select.html" ); $mech->select('singlelist', \@sendmulti); @return = $mech->value('singlelist'); is_deeply(\@return, \@singlereturn, 'multi->single value is ' . join(' ', @singlereturn)); $response = $mech->get_local( 'select.html' ); ok( $response->is_success, "Fetched select.html" ); $mech->select('singlelist', \%sendmulti); @return = $mech->value('singlelist'); is_deeply(\@return, \@singlereturn, 'multi->single value is ' . join(' ', @singlereturn)); # pass a single value to a single select $response = $mech->get_local( 'select.html' ); ok( $response->is_success, "Fetched select.html" ); $rv = $mech->select('singlelist', $sendsingle); $return = $mech->value('singlelist'); is($return, $sendsingle, "single->single value is '$sendsingle'"); $response = $mech->get_local( 'select.html' ); ok( $response->is_success, "Fetched select.html" ); $rv = $mech->select('singlelist', \%sendsingle); $return = $mech->value('singlelist'); is($return, $sendsingle, "single->single value is '$sendsingle'"); # test return value from $mech->select is($rv, 1, 'return 1 after successful select'); undef $rv; my $lived = eval { $rv = $mech->select('missing_list', 1); 1; }; is $lived, 1, 'We can ->select() on a missing field' or diag $@; is($rv, undef, 'return undef after failed select'); }); WWW-Mechanize-Chrome-0.79/t/50-form-with-fields-gh48.t0000644000175000017500000000544415211474437021436 0ustar corioncorionuse strict; use Test::More; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use WWW::Mechanize::Chrome::URLBlacklist; use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); my $testcount = 6; if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => $testcount*@instances; }; #my $bl = WWW::Mechanize::Chrome::URLBlacklist->new( # blacklist => [ # ], # whitelist => [ # qr!localhost!, # qr!^file://!, # ], # # # fail all unknown URLs # default => 'failRequest', # # allow all unknown URLs # # default => 'continueRequest', # # on_default => sub { # warn "*** Ignored URL $_[0] (action was '$_[1]')", # }, #); sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); my $mech = WWW::Mechanize::Chrome->new( autodie => 1, @_, ); #$bl->enable($mech); return $mech; }; t::helper::run_across_instances(\@instances, \&new_mech, $testcount, sub { my ($browser_instance, $mech) = @_; $mech->get_local('50-form-with-fields-gh48.html'); # A second attempt, to cycle the node ids quickly to avoid a node id 0 $mech->get_local('50-form-with-fields-gh48.html'); note "Loaded page"; #$mech->dump_forms; my $f; my $ok = eval { $f = $mech->current_form(); 1; }; my $err = $@; is $err, '', "No fatal error when retrieving ->current_form() again"; if( isnt $f, undef, "We have a form" ) { note "Retrieving HTML from ->current_form()"; my $html = $mech->current_form()->get_attribute('outerHTML'); like $html, qr/^
form_name('signIn'); 1; }; $err = $@; is $err, '', "We got no error on selecting the form by form name"; # Just checking.. yup its there: #my @text = $mech->selector('#ap_email'); #say $_->get_attribute('outerHTML') for @text; # #my @text = $mech->xpath('//input[@id="#ap_email"]'); #say $_->get_attribute('outerHTML') for @text; # Works $ok = eval { $mech->form_with_fields('email', 'password'); 1 }; $err = $@; is $err, '', "We got no error on selecting the form by field name"; #print $mech->current_form()->get_attribute('outerHTML'); # Fails! (well, no more) $ok = eval { $mech->submit_form(with_fields => {email => 'foo@bar.baz'}); }; $err = $@; is $err, '', "We got no error on submitting the form by field name"; }); WWW-Mechanize-Chrome-0.79/t/blank.jpg0000644000175000017500000000116715211474437016666 0ustar corioncorionJFIF``C    $.' ",#(7),01444'9=82<.342C  2!!22222222222222222222222222222222222222222222222222" }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbr $4%&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz ?(?WWW-Mechanize-Chrome-0.79/t/53-mech-capture-js-error.html0000644000175000017500000000040715211474437022322 0ustar corioncorion 53-mech-capture-js-error.html

A Javascript page with a JS parse error in it

WWW-Mechanize-Chrome-0.79/t/47-mech-simplest.t0000644000175000017500000000105515211474437020260 0ustar corioncorion#!perl -w use strict; use Test::More; use WWW::Mechanize::Chrome; use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR use lib '.'; use t::helper; my $mech = eval { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 0, startup_timeout => 4, headless => 1, )}; if (! $mech) { my $err = $@; plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => 1; }; isa_ok $mech, 'WWW::Mechanize::Chrome'; WWW-Mechanize-Chrome-0.79/t/62-networkstatus.t0000644000175000017500000000526415211474437020446 0ustar corioncorion#!perl -w use strict; use Test::More; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use JSON; use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => 4*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); my $m = WWW::Mechanize::Chrome->new( autodie => 1, @_, #headless => 0, ); }; t::helper::run_across_instances(\@instances, \&new_mech, 4, sub { my ($browser_instance, $mech) = @_; SKIP: { my $version = $mech->chrome_version; if( $version =~ /\b(\d+)\b/ and $1 < 63 ) { skip "Chrome before v63 doesn't know about online/offline mode or can do throttling", 4; } elsif( $version =~ /\b(\d+)\.\d+\.(\d+)\b/ and $1 == 63 and $2 < 3239) { # https://bugs.chromium.org/p/chromium/issues/detail?id=728451 skip "Chrome before v63.0.3239 doesn't know about online/offline mode or can do throttling", 4; } else { $mech->get_local('50-click.html'); my ($value,$type); ($value, $type) = $mech->eval_in_page('window.navigator.connection.effectiveType'); #is( $value, '4g', "We are online"); ($value, $type) = $mech->eval_in_page('window.navigator.onLine'); is( $value, JSON::true, "We are online (.onLine)"); $mech->emulateNetworkConditions( offline => JSON::true, latency => 0, downloadThroughput => 0, uploadThroughput => 0, #connectionType => 'none', ); ($value, $type) = $mech->eval('navigator.connection.effectiveType'); #is( $value, 'offline', "We are offline"); ($value, $type) = $mech->eval_in_page('window.navigator.onLine'); is( $value, JSON::false, "We are offline (.onLine)"); my $res = $mech->get('https://google.de'); ok !$res->is_success, "We can't fetch pages while offline"; #$mech->eval_in_page(sprintf 'window.location="%s"', '49-mech-get-file.html'); $mech->emulateNetworkConditions( offline => JSON::false, ); ($value, $type) = $mech->eval('navigator.connection.effectiveType'); #is( $value, '4g', "We are online again"); ($value, $type) = $mech->eval_in_page('window.navigator.onLine'); is( $value, JSON::true, "We are online (.onLine)"); } } undef $mech; }); WWW-Mechanize-Chrome-0.79/t/50-form2.t0000644000175000017500000001206515211474437016530 0ustar corioncorion#!perl -w use strict; use Test::More; use Test::Deep; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); my $testcount = 33; if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => $testcount*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; t::helper::run_across_instances(\@instances, \&new_mech, $testcount, sub { my ($browser_instance, $mech) = @_; $mech->get_local('50-form2.html'); ok $mech->current_form, "At start, we have a current form"; $mech->form_number(2); my $button = $mech->selector('#btn_ok', single => 1); isa_ok $button, 'WWW::Mechanize::Chrome::Node', "The button image"; ok $mech->submit, 'Sent the page'; ok $mech->current_form, "After a submit, we have a current form"; $mech->get_local('50-form2.html'); $mech->form_id('snd2'); ok $mech->current_form, "After setting form_id, We have a current form"; $mech->sleep(0.1); # why is this here?! is $mech->current_form->get_attribute('id'), 'snd2', "We can ask the form with get_attribute(id)"; my $content = $mech->current_form->get_attribute('innerHTML'); ok !!$content, "We got content from asking the current form with get_attribute"; my $backendNodeId = $mech->current_form->backendNodeId; ok !!$backendNodeId, "The form has a backendNodeId '$backendNodeId'"; $mech->field('id', 99); pass "We survived setting the field 'id' to 99"; my $current_form = $mech->current_form; ok !!$current_form, "We got a current form"; my $objectId = $current_form->objectId; ok !!$objectId, "The form has an objectId ('$objectId')"; #like $objectId, qr{injectedScriptId}, "The objectId matches /injectedScriptId/"; $objectId = $current_form->objectId; is $@, '', "No error when retrieving objectId twice"; ok !!$objectId, "The form still has an objectId ('$objectId')"; #like $objectId, qr{injectedScriptId}, "The objectId still matches /injectedScriptId/"; my $content2; #eval { $content2 = $current_form->get_attribute('innerHTML'); #}; is $@, '', "No error when retrieving form HTML"; ok !!$content2, "We got content from (again) asking the current form with get_attribute"; isnt $content2, $content, "we managed to change the form by setting the 'id' field"; is $mech->xpath('.//*[@name="id"]', node => $mech->current_form, single => 1)->get_attribute('value', live => 1), 99, "We have set field 'id' to '99' in the correct form"; $mech->get_local('50-form2.html'); $mech->form_with_fields('r1','r2'); ok $mech->current_form, "We can find a form by its contained input fields"; $mech->get_local('50-form2.html'); $mech->form_name('snd'); ok $mech->current_form, "We can find a form by its name"; is $mech->current_form->get_attribute('name'), 'snd', "We can find a form by its name"; $mech->get_local('50-form2.html'); ok $mech->current_form, "On a new ->get, we have a current form"; $mech->get_local('50-form2.html'); $mech->form_with_fields('comment'); ok $mech->current_form, "We can find a form by its contained textarea fields"; $mech->field('comment', "Just another Phrome Hacker,"); pass "We survived setting the field 'comment' to some JAPH"; like $mech->xpath('.//textarea', node => $mech->current_form, single => 1)->get_attribute('value'), qr/Just another/, "We set textarea and verified it"; $mech->get_local('50-form2.html'); $mech->form_with_fields('quickcomment'); ok $mech->current_form, "We can find a form by its contained select fields"; $mech->field('quickcomment', 2); pass "We survived setting the field 'quickcomment' to 2"; my @result = $mech->value('quickcomment'); cmp_bag \@result, [2], "->field returned bag 2"; # diag explain \@result; $mech->get_local('50-form2.html'); $mech->form_with_fields('multic'); ok $mech->current_form, "We can find a form by its contained multi-select fields"; @result = $mech->value('multic'); cmp_bag \@result, [2,2,3], "->field returned bag 2,2,3"; # diag explain \@result; $mech->field('multic', [1,2]); pass "We survived setting the field 'multic' to 1,2"; @result = $mech->value('multic'); cmp_bag \@result, [1,1,2,2], "->field returned bag 1,1,2,2"; # diag explain \@result; # Check that we can address multiple fields with the same form parameter name $mech->get_local('50-form2.html'); $mech->form_with_fields('date'); @result = (); my $ok = eval { $mech->set_fields( date => ['2020-04-04',2] ); 1; }; is $ok, 1, "We survived setting the second date field" or diag $@; @result = $mech->value('date',2); is_deeply \@result, ['2020-04-04'], "We set the second date field"; }); WWW-Mechanize-Chrome-0.79/t/50-mech-start-url.t0000644000175000017500000000172015211474437020346 0ustar corioncorion#!perl -w use strict; use Test::More; use WWW::Mechanize::Chrome; use Log::Log4perl qw(:easy); use Test::HTTP::LocalServer; use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => 2*@instances; }; my $server = Test::HTTP::LocalServer->spawn( #debug => 1 ); my $url = $server->url; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, start_url => $url, @_, ); }; t::helper::run_across_instances(\@instances, \&new_mech, 2, sub { my ($browser_instance, $mech) = @_; $mech->sleep(1); isa_ok $mech, 'WWW::Mechanize::Chrome'; is $mech->uri, $url, "We moved to the start URL instead of about:blank"; }); $server->stop; WWW-Mechanize-Chrome-0.79/t/77-reload-fragment.t0000644000175000017500000000261715211474437020565 0ustar corioncorion#!perl -w use strict; use Test::More; use WWW::Mechanize::Chrome; use strict; use Test::More; use Cwd; use URI; use URI::file; use File::Basename; use File::Spec; use File::Temp 'tempdir'; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use lib '.'; use Test::HTTP::LocalServer; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => 2*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, #headless => 0, ); }; my $server = Test::HTTP::LocalServer->spawn( #debug => 1 ); my $url = $server->url; my @urls = ( "$url#1", "$url#2", ); t::helper::run_across_instances(\@instances, \&new_mech, 2, sub { my ($browser_instance, $mech) = @_; SKIP: { my $version = $mech->chrome_version; if( $version =~ /\b(\d+)\b/ and ($1 == 64 or $1 == 59)) { skip "Chrome 64 doesn't handle self-navigating well", 2; } else { for my $url (@urls) { $mech->get( $url ); pass "We retrieved $url"; }; }; }; }); $server->stop; WWW-Mechanize-Chrome-0.79/t/49-mech-get-file.html0000644000175000017500000000035615211474437020622 0ustar corioncorion 49-mech-get-file.html

A Javascript page that has no (JS) errors

WWW-Mechanize-Chrome-0.79/t/50-mech-encoding.t0000644000175000017500000000243015211474437020176 0ustar corioncorion#!perl -w use strict; use Test::More; use WWW::Mechanize::Chrome; use Log::Log4perl qw(:easy); use lib '.'; use t::helper; my @tests = ( [ 'mixi_jp_index.html', 'EUC-JP', qr/\x{30DF}\x{30AF}\x{30B7}\x{30A3}/ ], [ 'sophos_co_jp_index.html', 'SHIFT_JIS', qr/\x{30B0}\x{30ED}\x{30FC}\x{30D0}\x{30EB}/ ], ); my $testcount = 2*@tests; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => $testcount*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; t::helper::run_across_instances(\@instances, \&new_mech, $testcount, sub { my ($browser_instance, $mech) = @_; for (@tests) { my ($file,$encoding,$content_re) = @$_; $mech->get_local($file); is uc $mech->content_encoding, $encoding, "$file has encoding $encoding"; note "Length of content", length $mech->content; like $mech->content, $content_re, "Partial expression gets found in UTF-8 content"; }; }); WWW-Mechanize-Chrome-0.79/t/50-mech-content.t0000644000175000017500000000447415211474437020074 0ustar corioncorion#!perl -w use strict; use Test::More; use WWW::Mechanize::Chrome; use Log::Log4perl qw(:easy); use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); my $testcount = 9; if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => $testcount*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; t::helper::run_across_instances(\@instances, \&new_mech, $testcount, sub { my ($browser_instance, $mech) = @_; isa_ok $mech, 'WWW::Mechanize::Chrome'; my $html = $mech->content; like $html, qr!!, "We can get the plain HTML"; my $html2 = $mech->content( format => 'html' ); is $html2, $html, "When asking for HTML explicitly, we get the same text"; my $text = $mech->content( format => 'text' ); is $text, '', "We can get the plain text"; my $version = $mech->chrome_version; if( $version =~ /\b(\d+)\b/ and $1 < 80 ) { SKIP: { skip "Chrome version is $version, need Chrome version 80 for MHTML", 2; }; } else { my $mhtml = $mech->content( format => 'mhtml' ); like $mhtml, qr/^Snapshot-Content-Location:/m, "We can get the MHTML of the whole page"; $mech->get_local('52-frameset.html'); $mhtml = $mech->content( format => 'mhtml' ); like $mhtml, qr!52-subframe.html!, "We can get the MHTML of the whole page, including frames"; }; my $text2; my $lives = eval { $mech->content( format => 'bogus' ); 1 }; ok !$lives, "A bogus content format raises an error"; { local $TODO = "Chrome devtools doesn't return the XML declaration of a document"; $mech->get_local('xhtml.xhtml'); $html = $mech->content; like $html, qr/^content preserves the XHTML directive"; } # pm11123357 $mech->get_local('scripttag.html'); $text = $mech->content( format => 'text' ); like $text, qr/^\s*This should appear.\s+This should also appear.\s*$/, "

Text before

Text after

WWW-Mechanize-Chrome-0.79/t/50-mech-ct.t0000644000175000017500000000167615211474437017031 0ustar corioncorion#!perl -w use strict; use Test::More; use WWW::Mechanize::Chrome; use Log::Log4perl qw(:easy); use Test::HTTP::LocalServer; use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => 2*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; my $server = Test::HTTP::LocalServer->spawn( #debug => 1 ); t::helper::run_across_instances(\@instances, \&new_mech, 2, sub { my ($browser_instance, $mech) = @_; $mech->get($server->url); isa_ok $mech, 'WWW::Mechanize::Chrome'; is $mech->ct, 'text/html', "Content-type of text/html"; }); $server->stop; WWW-Mechanize-Chrome-0.79/t/helper.pm0000644000175000017500000001434715211474437016716 0ustar corioncorionpackage # hide from CPAN indexer t::helper; use 5.020; use feature 'postderef'; use Test::More; use File::Glob qw(bsd_glob); use Config '%Config'; use File::Spec; use Carp qw(croak); use File::Temp 'tempdir'; use WWW::Mechanize::Chrome; use Config; use Time::HiRes qw(sleep time); use POSIX qw(:sys_wait_h); use Log::Log4perl ':easy'; delete $ENV{HTTP_PROXY}; delete $ENV{HTTPS_PROXY}; $ENV{PERL_FUTURE_DEBUG} = 1 if not exists $ENV{PERL_FUTURE_DEBUG}; # Global PID tracking for fail-safe cleanup our %all_spawned_pids; { my $org_new = \&WWW::Mechanize::Chrome::new; no warnings 'redefine'; *WWW::Mechanize::Chrome::new = sub { my $self = $org_new->(@_); if (ref $self && $self->{pid}) { for my $pid ($self->{pid}->@*) { $all_spawned_pids{$pid} = 1 if $pid; } } return $self; }; # Override kill_child to be more aggressive and non-blocking in tests. # This prevents hangs during the cleanup phase of tests, especially with # modern Chromium versions that may not exit promptly on SIGTERM. *WWW::Mechanize::Chrome::kill_child = sub { my ($self, $signal, $pids, $wait_file) = @_; return unless $pids; my @p = ref $pids eq 'ARRAY' ? @$pids : ($pids); for my $pid (@p) { next unless $pid && kill(0, $pid); # Use SIGKILL in tests to ensure swift termination and avoid hangs kill('KILL', $pid); # Non-blocking wait with a short timeout my $timeout = Time::HiRes::time() + 2; while (Time::HiRes::time() < $timeout) { my $res = waitpid($pid, WNOHANG); last if $res == -1 || $res == $pid; Time::HiRes::sleep(0.1); } delete $all_spawned_pids{$pid}; } return; }; } END { # Final fail-safe cleanup of all PIDs spawned during this test process for my $pid (keys %all_spawned_pids) { if ($pid && kill(0, $pid)) { kill('KILL', $pid); waitpid($pid, WNOHANG); } } } sub need_minimum_chrome_version { my( $version, @args ) = @_; $version =~ m!^(\d+)\.(\d+)\.(\d+)\.(\d+)$! or croak "Invalid version parameter '$version'"; my( $need_maj, $need_min, $need_sub, $need_patch ) = ($1,$2,$3,$4); my $v = WWW::Mechanize::Chrome->chrome_version( @args ); $v =~ m!/(\d+)\.(\d+)\.(\d+)\.(\d+)$! or die "Couldn't find version info from '$v'"; my( $maj, $min, $sub, $patch ) = ($1,$2,$3,$4); if( $maj < $need_maj or $maj == $need_maj and $min < $need_min or $maj == $need_maj and $min == $need_min and $sub < $need_sub or $maj == $need_maj and $min == $need_min and $sub == $need_sub and $patch < $need_patch ) { croak "Chrome $v is unsupported. Minimum required version is $version."; }; return; }; sub browser_instances { my ($filter) = @_; $filter ||= qr/^/; # (re)set the log level if (my $lv = $ENV{TEST_LOG_LEVEL}) { if( $lv eq 'trace' ) { Log::Log4perl->easy_init($TRACE) } elsif( $lv eq 'debug' ) { Log::Log4perl->easy_init($DEBUG) } } my @instances; if( $ENV{TEST_WWW_MECHANIZE_CHROME_INSTANCE}) { push @instances, $ENV{TEST_WWW_MECHANIZE_CHROME_VERSIONS}; } elsif( $ENV{TEST_WWW_MECHANIZE_CHROME_VERSIONS} ) { # add author tests with local versions my $spec = $ENV{TEST_WWW_MECHANIZE_CHROME_VERSIONS}; push @instances, grep { -x } bsd_glob $spec; } elsif( $ENV{CHROME_BIN}) { push @instances, $ENV{ CHROME_BIN } if $ENV{ CHROME_BIN } and -x $ENV{ CHROME_BIN }; } else { my ($default) = WWW::Mechanize::Chrome->find_executable(); push @instances, $default if $default; my $spec = 'chrome-versions/*/{*/,}chrome' . $Config{_exe}; # sorry, likely a bad default push @instances, grep { -x } bsd_glob $spec; }; # Consider filtering for unsupported Chrome versions here @instances = map { s!\\!/!g; $_ } # for Windows grep { ($_ ||'') =~ /$filter/ } @instances; # Only use unique Chrome executables my %seen; @seen{ @instances } = 1 x @instances; # Well, we should do a nicer natural sort here @instances = sort {$a cmp $b} keys %seen; return @instances; }; sub default_unavailable { return !scalar browser_instances; }; sub runtests { my ($browser_instance, $new_mech, $code, $test_count) = @_; #if ($browser_instance) { # note sprintf 'Testing with %s', # $browser_instance; #}; my $tempdir = tempdir( CLEANUP => 1 ); my @launch; if( $ENV{TEST_WWW_MECHANIZE_CHROME_INSTANCE} ) { my( $host, $port ) = split /:/, $ENV{TEST_WWW_MECHANIZE_CHROME_INSTANCE}; @launch = ( host => $host, port => $port, reuse => 1, new_tab => 1, ); } else { @launch = ( launch_exe => $browser_instance, #port => $port, data_directory => $tempdir, headless => 1, ); }; { my $mech = eval { $new_mech->(@launch) }; if( ! $mech ) { my $err = $@; SKIP: { skip "Couldn't create new object: $err", $test_count; }; my $version = eval { WWW::Mechanize::Chrome->chrome_version( launch_exe => $browser_instance ); }; diag sprintf "Failed on Chrome version '%s': %s", ($version || '(unknown)'), $err; return; }; note sprintf "Using Chrome version '%s'", $mech->chrome_version; # Run the user-supplied tests, making sure we don't keep a # reference to $mech around @_ = ($browser_instance, $mech); }; # Ensure stack frame is cleared to allow proper destruction goto &$code; } sub run_across_instances { #my ($instances, $new_mech, $test_count, $code) = @_; croak 'No test count given' unless $_[2]; #$test_count; for my $browser_instance (@{$_[0]}) { runtests( $browser_instance, @_[1,3,2] ); }; return; }; 1; WWW-Mechanize-Chrome-0.79/t/50-form-with-fields-gh48.html0000644000175000017500000017323615211474437022144 0ustar corioncorion Amazon Sign In

Sign-In

By signing-in you agree to Amazon's Conditions of Use & Sale. Please see our Privacy Notice, our Cookies Notice and our Interest-Based Ads Notice.
New to Amazon?
Create your Amazon account
WWW-Mechanize-Chrome-0.79/t/50-mech-status.t0000644000175000017500000000265215211474437017741 0ustar corioncorion#!perl -w use strict; use Test::More; use WWW::Mechanize::Chrome; use Log::Log4perl qw(:easy); use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => 5*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; t::helper::run_across_instances(\@instances, \&new_mech, 5, sub { my($browser_instance, $mech)= @_; isa_ok $mech, 'WWW::Mechanize::Chrome'; my ($site,$estatus) = ('https://'.rand(1000).'.www.doesnotexist.example/',500); my $res = $mech->get($site); #is $mech->uri, $site, "Navigating to (nonexisting) $site"; if( ! isa_ok $res, 'HTTP::Response', 'The response') { SKIP: { skip "No response returned", 2 }; } else { my $c = $res->code; like $res->code, qr/^(404|5\d\d)$/, "GETting $site gives a 5xx (no proxy) or 404 (proxy)" or diag $mech->content; like $mech->status, qr/^(404|5\d\d)$/, "GETting $site returns a 5xx (no proxy) or 404 (proxy) HTTP status" or diag $mech->content; }; ok !$mech->success, 'We consider this response not successful'; }); WWW-Mechanize-Chrome-0.79/t/60-mech-cookies.t0000644000175000017500000000750315211474437020053 0ustar corioncorion#!perl -w use strict; use Test::More; use WWW::Mechanize::Chrome; use Log::Log4perl ':easy'; use HTTP::Cookies; use File::Basename 'dirname'; use Test::HTTP::LocalServer; use Data::Dumper; use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); my $testcount = 15; if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => $testcount*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; my $server = Test::HTTP::LocalServer->spawn; t::helper::run_across_instances(\@instances, \&new_mech, $testcount, sub { my ($browser_instance, $mech) = @_; my $version = $mech->chrome_version; note "Fetching cookie jar"; my $cookies = $mech->cookie_jar; isa_ok $cookies, 'HTTP::Cookies'; if( $version =~ /\b(\d+)\b/ and ($1 >= 59 and $1 <= 62)) { SKIP: { skip "Chrome v$1 doesn't properly handle setting cookies...", $testcount-1; }; } else { for my $cookie_val (1, JSON::true, JSON::false, 0, '', undef) { my $lived = eval { $cookies->set_cookie(undef, 'foo','bar','/','localhost', undef, undef, $cookie_val, time+10, undef); 1; }; is $lived, 1, sprintf "We can use %s as a value for 'secure'", defined $cookie_val ? "'$cookie_val'" : "undef" or diag $@; }; # Count how many cookies we get as a test. my $count = 0; $cookies->scan(sub{$count++; }); ok $count > 0, 'We found at least one cookie'; my $other_jar = HTTP::Cookies->new(); $other_jar->set_cookie( 1, 'mycookie' => 'tasty1', '/', 'example.com', 0, '', 1, 600, 0 ); my $lived = eval { $cookies->load_jar( $other_jar, replace => 1 ); 1; }; ok $lived, "We can load another cookie jar" or diag $@; $count = 0; my @c; $cookies->scan(sub{$count++; push @c, [@_];}); is $count, 1, 'We replaced all the cookies with our single cookie from the jar' or diag Dumper \@c; $lived = eval { $cookies->load(dirname($0).'/CookiesOld'); 1; }; ok $lived, "We can load cookies from file" or diag $@; $other_jar = HTTP::Cookies->new(); #$self->SUPER::set_cookie( $version, $key, $val, $path, $domain, $port, $path_spec, $secure, $maxage, $discard ); $other_jar->set_cookie( 1, 'mycookie' => 'tasty2', '/', $server->url->host_port, $server->url->port, #undef, '', 0, # our test server only implements http 600, 0 ); $lived = eval { $cookies->load_jar( $other_jar, replace => 1 ); 1; }; ok $lived, "We can load another cookie jar" or diag $@; $count = 0; @c = (); $cookies->scan(sub{$count++; push @c,[@_]}); is $count, 1, 'We replaced all the cookies with our single cookie from the (manual) jar' or diag Dumper \@c; $mech->cookie_jar->load; $mech->get($server->url); like $mech->content, qr/\btasty2\b/, "Our cookie gets sent"; $mech->cookie_jar->load; $count = 0; @c = (); $cookies->scan(sub{$count++; push @c,[@_]}); cmp_ok $count, '>=', 3, "We keep the cookies our test server sends"; } undef $mech; }); undef $server; WWW-Mechanize-Chrome-0.79/t/70-mech-png.t0000644000175000017500000000662315211474437017206 0ustar corioncorion#!perl -w use strict; use Test::More; use WWW::Mechanize::Chrome; use Data::Dumper; use Log::Log4perl qw(:easy); use lib '.'; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); my $testcount = 11; if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => @instances*$testcount; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; sub save { my ($data,$filename) = @_; open my $fh, '>', $filename or die "Couldn't create '$filename': $!"; binmode $fh; print {$fh} $data; }; # This is a bit inefficient, but for a test I value simplicity sub image_dimensions_are { if( eval { require Image::Info; 1 }) { my $got = Image::Info::image_info( \$_[0] ); delete $got->{$_} for grep { $_ !~ /^(width|height)$/ } keys %$got; is_deeply $got, $_[1], $_[2] or diag Dumper $got; } else { SKIP: { skip "Image::Info not available", 1; } }; }; t::helper::run_across_instances(\@instances, \&new_mech, $testcount, sub { my ($browser_instance, $mech) = @_; isa_ok $mech, 'WWW::Mechanize::Chrome'; $mech->update_html(<<'HTML'); Hello PNG! Hello PNG! HTML #ok $mech->success, 'We got the page'; my $pngData = $mech->content_as_png(); like $pngData, '/^.PNG/', "The result looks like a PNG format file"; #save $pngData, 'tmp.png'; my $pngName = $mech->selector("#my_name", single => 1); $pngData = $mech->element_as_png($pngName); like $pngData, '/^.PNG/', "The result looks like a PNG format file"; #save $pngData, 'tmp.png'; #if( 0 ) { my $rect = { left => 0, top => 0, width => 200, height => 200, }; my $topleft = $mech->content_as_png($rect); like $topleft, '/^.PNG/', "The result looks like a PNG format file"; image_dimensions_are( $topleft, { width => 200, height => 200 }, "Partial image" ); $rect = { left => 0, top => 0, width => 200, height => 200, }; my $target = { scalex => 2, }; $topleft = $mech->content_as_png($rect, $target); like $topleft, '/^.PNG/', "The result looks like a PNG format file"; image_dimensions_are( $topleft, { width => 400, height => 400 }, "Blown up (scalex)" ); $rect = { left => 0, top => 0, width => 200, height => 300, }; $target = { width => 150, }; $topleft = $mech->content_as_png($rect, $target); like $topleft, '/^.PNG/', "The result looks like a PNG format file"; image_dimensions_are( $topleft, { width => 150, height => 225 }, "Scaled down via fixed with" ); $rect = { left => 0, top => 0, width => 300, height => 200, }; $target = { height => 150, }; $topleft = $mech->content_as_png($rect, $target); like $topleft, '/^.PNG/', "The result looks like a PNG format file"; image_dimensions_are( $topleft, { width => 225, height => 150 }, "Scaled down via fixed height" ); #save($pngData,"Topleft-".$i++.".png"); #}; }) WWW-Mechanize-Chrome-0.79/t/rt127588.t0000644000175000017500000000137315211474437016405 0ustar corioncorion#! /usr/bin/perl -w use strict; use Log::Log4perl qw( :easy ); use WWW::Mechanize::Chrome; use Test::More; use lib '.'; use t::helper; Log::Log4perl -> easy_init ( $ERROR ); # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => 1*@instances; }; sub new_mech { WWW::Mechanize::Chrome->new( autodie => 1, launch_arg => [ "--no-sandbox", "--disable-suid-sandbox", '--headless', ], ); }; t::helper::run_across_instances(\@instances, \&new_mech, 1, sub { pass "We didn't crash when disabling the suid sandbox"; }); WWW-Mechanize-Chrome-0.79/t/49-mech-get-file-lc-ct.html0000644000175000017500000000036415211474437021621 0ustar corioncorion 49-mech-get-file-lc-ct.html

A Javascript page that has no (JS) errors

WWW-Mechanize-Chrome-0.79/t/52-nested-frameset.html0000644000175000017500000000106315211474437021270 0ustar corioncorion 52-nested-frameset.html <body> <a id="change_frame" onclick="javascript:document.all.myframe1.src='select.html';" href="#">Change frame</a> <div id="content">52-frameset.html</div> <p>Duh - no frame support?</p> </body> WWW-Mechanize-Chrome-0.79/t/50-mech-redirect.t0000644000175000017500000000254515211474437020220 0ustar corioncorion#!perl -w use strict; use Test::More; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use lib '.'; use Test::HTTP::LocalServer; #use Mojolicious; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => 6*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; my $server = Test::HTTP::LocalServer->spawn( #debug => 1, ); t::helper::run_across_instances(\@instances, \&new_mech, 6, sub { my ($browser_instance, $mech) = @_; isa_ok $mech, 'WWW::Mechanize::Chrome'; my ($site,$estatus) = ($server->url,200); my $res = $mech->get($server->redirect('')); isa_ok $res, 'HTTP::Response', "Response"; is $mech->uri, $site, "Navigated to $site"; is $res->code, $estatus, "GETting $site returns HTTP code $estatus from response" or diag $mech->content; is $mech->status, $estatus, "GETting $site returns HTTP status $estatus from mech" or diag $mech->content; ok $mech->success, 'We consider this response successful'; }); $server->stop; WWW-Mechanize-Chrome-0.79/t/CookiesOld0000644000175000017500000000016415211474437017047 0ustar corioncorion#LWP-Cookies-1.0 Set-Cookie3: key=OLD; path="/"; domain=OLD.old; port=80; expires="2020-03-28 20:41:55Z"; version=0WWW-Mechanize-Chrome-0.79/t/49-existing-port.t0000644000175000017500000000574615211474437020337 0ustar corioncorion#!perl use warnings; use strict; use Test::More; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use lib '.'; use Test::HTTP::LocalServer; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR my @instances = t::helper::browser_instances(); my $test_count = 4; my $transport = WWW::Mechanize::Chrome->_preferred_transport({}); if (my $err = t::helper::default_unavailable) { plan skip_all => q{Couldn't connect to Chrome: } . $@; exit } elsif( $transport =~ /::Pipe::/ ) { plan skip_all => 'Pipe transport makes no sense for this test'; exit } else { plan tests => $test_count*@instances; }; # Launch our Chrome instance separately: my ($existing_mech, $instance_host, $instance_port); my $expected_location = 'data:text/html,Test-' . $$; my $browser_launched = 0; my $org = \&WWW::Mechanize::Chrome::_spawn_new_chrome_instance; { no warnings 'redefine'; *WWW::Mechanize::Chrome::_spawn_new_chrome_instance = sub { $browser_launched++; goto &$org; }; } sub new_mech { my(%args) = @_; t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); $existing_mech = WWW::Mechanize::Chrome->new( @_, autodie => 1, headless => 1, connection_style => 'websocket', autoclose => 0, # Manual cleanup autoclose_tab => 0, ); $existing_mech->get($expected_location); #my $existing_mech; #my $instance_port = 9222; $instance_port = $existing_mech->{ port }; $instance_host = $existing_mech->{ host }; note "Instance communicates on port $instance_host:$instance_port"; WWW::Mechanize::Chrome->new( autodie => 1, port => $instance_port, host => $instance_host, autoclose => 0, # Manual cleanup autoclose_tab => 0, # tab => 'current', @_, ); }; my $server = Test::HTTP::LocalServer->spawn( #debug => 1, ); t::helper::run_across_instances(\@instances, \&new_mech, $test_count, sub { my ($browser_instance, $mech) = splice @_; pass "We can connect to port $instance_port"; is $browser_launched, 1, q{We didn't spawn a second process}; is $mech->{pid}, undef, 'We have no process to kill'; note $mech->chrome_version; note $existing_mech->chrome_version; my $location = $mech->uri; is $location, $expected_location, 'We connect to the same tab'; note $mech->title; my $pids = $existing_mech->{pid}; # Explicit cleanup with error handling eval { $mech->close() if $mech; undef $mech; }; eval { $existing_mech->close() if $existing_mech; undef $existing_mech; }; # Hard kill if still alive to release files if ($pids && ref $pids eq 'ARRAY') { for my $pid (@$pids) { if ($pid && kill(0, $pid)) { kill('KILL', $pid); waitpid($pid, 0); } } } $browser_launched = 0; }); undef $existing_mech; $server->stop; WWW-Mechanize-Chrome-0.79/t/50-mech-get-nonexistent.t0000644000175000017500000000222615211474437021546 0ustar corioncorion#!perl -w use strict; use Test::More; use Log::Log4perl qw(:easy); use WWW::Mechanize::Chrome; use lib '.'; use Test::HTTP::LocalServer; #use Mojolicious; use t::helper; Log::Log4perl->easy_init($ERROR); # Set priority of root logger to ERROR # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => 4*@instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; my $server = Test::HTTP::LocalServer->spawn( #debug => 1, ); t::helper::run_across_instances(\@instances, \&new_mech, 4, sub { my ($browser_instance, $mech) = @_; isa_ok $mech, 'WWW::Mechanize::Chrome'; my ($site,$estatus) = ('https://nonexistent.example/',200); my $res = $mech->get($site); isa_ok $res, 'HTTP::Response', "Response"; cmp_ok $res->code, '>=', 500, "An error gets reported as error"; ok !$mech->success, "We don't consider this response successful"; }); $server->stop; WWW-Mechanize-Chrome-0.79/t/select.html0000644000175000017500000000077315211474437017244 0ustar corioncorion Like a hole
WWW-Mechanize-Chrome-0.79/t/xhtml.xhtml0000644000175000017500000000235115211474437017303 0ustar corioncorion ]> xhtml.xhtml WWW-Mechanize-Chrome-0.79/t/56-render-content.t0000644000175000017500000000644515211474437020445 0ustar corioncorion#!perl -w use strict; use Test::More; use WWW::Mechanize::Chrome; use lib '.'; use File::Temp qw(tempfile); use t::helper; use Log::Log4perl qw(:easy); # What instances of Chrome will we try? my @instances = t::helper::browser_instances(); my @tests= ( # PDF only works with headless Chrome { format => 'pdf', like => qr/^%PDF-/ }, { format => 'png', like => qr/^.PNG/, }, #{ format => 'jpg', like => qr/^......JFIF/, }, ); my $testcount = (1+@tests*2+2); if (my $err = t::helper::default_unavailable) { plan skip_all => "Couldn't connect to Chrome: $@"; exit } else { plan tests => $testcount * @instances; }; sub new_mech { t::helper::need_minimum_chrome_version( '62.0.0.0', @_ ); WWW::Mechanize::Chrome->new( autodie => 1, @_, ); }; my @delete; END { for( @delete ) { unlink $_ or diag "Couldn't remove tempfile '$_': $!"; } }; t::helper::run_across_instances(\@instances, \&new_mech, $testcount, sub { my ($browser_instance, $mech) = @_; isa_ok $mech, 'WWW::Mechanize::Chrome'; $mech->get_local('50-click.html'); for my $test ( @tests ) { my $format= $test->{format}; my $content= eval { $mech->render_content( format => $format ); }; SKIP: { if( $@ ) { skip "$@", 2; }; my $shortcontent = substr( $content, 0, 30 ); like $shortcontent, $test->{like}, "->render_content( format => '$format' )" or diag $shortcontent; my @delete; my( $tempfh,$outfile )= tempfile; close $tempfh; push @delete, $outfile; $mech->render_content( format => $format, filename => $outfile ); my($res, $reason)= (undef, "Outfile '$outfile' was not created"); if(-f $outfile) { if( open my $fh, '<:raw', $outfile ) { local $/; my $content= <$fh>; $res= $content =~ $test->{like} or $reason= "Content did not match /$test->{like}/: " . substr($content,0,10); } else { $reason= "Couldn't open '$outfile': $!"; }; }; ok $res, "->render_content to file" or diag $reason; }; }; my $content= eval { $mech->content_as_pdf( format => 'A4' ); }; SKIP: { if( $@ ) { skip "$@", 1; }; my $shortcontent = substr( $content, 0, 30 ); like $shortcontent, qr/^%PDF-/, "looks like PDF" or diag $shortcontent; my @delete; my( $tempfh,$outfile )= tempfile; close $tempfh; push @delete, $outfile; $mech->content_as_pdf( format => 'A4', filename => $outfile ); my($res, $reason)= (undef, "Outfile '$outfile' was not created"); if(-f $outfile) { if( open my $fh, '<:raw', $outfile ) { local $/; my $content= <$fh>; $res= $content =~ qr/^%PDF-/, or $reason= "Content did not match /^%PDF-/: " . substr($content,0,10); } else { $reason= "Couldn't open '$outfile': $!"; }; }; ok $res, "->content_as_pdf to file" or diag $reason; }; }); WWW-Mechanize-Chrome-0.79/t/52-iframeset.html0000644000175000017500000000100315211474437020153 0ustar corioncorion 52-frameset.html
52-iframeset.html
Change frame Change frame to 404