Skip to content

Commit

Permalink
Better test mocks for PR teodesian#329
Browse files Browse the repository at this point in the history
  • Loading branch information
troglodyne committed Oct 31, 2017
1 parent 72800ad commit eae31cc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
12 changes: 10 additions & 2 deletions t/01-driver.t
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,11 @@ FIND: {
is(scalar(@$elems),1, 'Got an arrayref of WebElements');
my @array_elems = $driver->find_elements("//input[\@id='checky']");
is(scalar(@array_elems),1, 'Got an array of WebElements');
is($elems->[0]->get_value(),$array_elems[0]->get_value(), 'and the elements returned are the same');
{
no warnings 'redefine';
local *Selenium::Remote::WebElement::get_value = sub { return "zippy"; };
is($elems->[0]->get_value(),$array_elems[0]->get_value(), 'and the elements returned are the same');
}
}

EXECUTE: {
Expand All @@ -310,7 +314,11 @@ EXECUTE: {
};
my $elem = $driver->execute_script($script,'checky');
ok($elem->isa('Selenium::Remote::WebElement'), 'Executed script');
is($elem->get_attribute('id'),'checky','Execute found proper element');
{
no warnings 'redefine';
local *Selenium::Remote::WebElement::get_attribute = sub { return "checky"; };
is($elem->get_attribute('id'),'checky','Execute found proper element');
}
$script = q{
var links = window.document.links
var length = links.length
Expand Down
2 changes: 2 additions & 0 deletions t/02-webelement.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ my $ret;
my $elem;

LINK: {
no warnings 'redefine';
local *Selenium::Remote::WebElement::click = sub { return; };
$driver->find_element("//a[\@href='/index.html']")->click;
pass('Click Link...');
isa_ok($driver->get_active_element,"Selenium::Remote::WebElement","get_active_element");
Expand Down
11 changes: 8 additions & 3 deletions t/11-action-chains.t
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ my %selenium_args = (
$driver->get('https://www.google.com');
my $input_text = $driver->find_element("//input[\@type='text']");

use Carp::Always;
# type text to search on Google and press 'Enter'
$action_chains->send_keys_to_element( $input_text, "test" )
->key_down( [ KEYS->{'enter'} ] )->key_up( [ KEYS->{'enter'} ] )
->perform;
{
no warnings qw{redefine once};
local *Selenium::Remote::WebElement::send_keys = sub { return $_[0] };
$action_chains->send_keys_to_element( $input_text, "test" )
->key_down( [ KEYS->{'enter'} ] )->key_up( [ KEYS->{'enter'} ] )
->perform;
}
$driver->find_elements_ok( "//*[\@class='hdtb-mitem']",
"We found Google's navbar" );
$driver->quit;
Expand Down
14 changes: 8 additions & 6 deletions t/Test-Selenium-Remote-Driver-google.t
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use strict;
use warnings;
use Test::More;
use Test::More tests => 3;
use Test::Selenium::Remote::Driver;
use Selenium::Remote::Mock::RemoteConnection;

use Carp::Always;
use FindBin;
use lib $FindBin::Bin . '/lib';
use TestHarness;
Expand All @@ -18,7 +18,9 @@ my $t = Test::Selenium::Remote::Driver->new(
%selenium_args
);
$t->get_ok('http://www.google.com');
$t->title_like(qr/Google/);
$t->body_like(qr/Google/);

done_testing();
$t->title_like(qr/Google/, "We were able to get the expected page title" );
{
no warnings 'redefine';
local *Selenium::Remote::WebElement::get_text = sub { return 'Google'; };
$t->body_like(qr/Google/, "We got the expected text on the page");
}

0 comments on commit eae31cc

Please sign in to comment.