Skip to content

Commit eae31cc

Browse files
committed
Better test mocks for PR #329
1 parent 72800ad commit eae31cc

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

t/01-driver.t

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,11 @@ FIND: {
299299
is(scalar(@$elems),1, 'Got an arrayref of WebElements');
300300
my @array_elems = $driver->find_elements("//input[\@id='checky']");
301301
is(scalar(@array_elems),1, 'Got an array of WebElements');
302-
is($elems->[0]->get_value(),$array_elems[0]->get_value(), 'and the elements returned are the same');
302+
{
303+
no warnings 'redefine';
304+
local *Selenium::Remote::WebElement::get_value = sub { return "zippy"; };
305+
is($elems->[0]->get_value(),$array_elems[0]->get_value(), 'and the elements returned are the same');
306+
}
303307
}
304308

305309
EXECUTE: {
@@ -310,7 +314,11 @@ EXECUTE: {
310314
};
311315
my $elem = $driver->execute_script($script,'checky');
312316
ok($elem->isa('Selenium::Remote::WebElement'), 'Executed script');
313-
is($elem->get_attribute('id'),'checky','Execute found proper element');
317+
{
318+
no warnings 'redefine';
319+
local *Selenium::Remote::WebElement::get_attribute = sub { return "checky"; };
320+
is($elem->get_attribute('id'),'checky','Execute found proper element');
321+
}
314322
$script = q{
315323
var links = window.document.links
316324
var length = links.length

t/02-webelement.t

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ my $ret;
2323
my $elem;
2424

2525
LINK: {
26+
no warnings 'redefine';
27+
local *Selenium::Remote::WebElement::click = sub { return; };
2628
$driver->find_element("//a[\@href='/index.html']")->click;
2729
pass('Click Link...');
2830
isa_ok($driver->get_active_element,"Selenium::Remote::WebElement","get_active_element");

t/11-action-chains.t

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ my %selenium_args = (
3131
$driver->get('https://www.google.com');
3232
my $input_text = $driver->find_element("//input[\@type='text']");
3333

34+
use Carp::Always;
3435
# type text to search on Google and press 'Enter'
35-
$action_chains->send_keys_to_element( $input_text, "test" )
36-
->key_down( [ KEYS->{'enter'} ] )->key_up( [ KEYS->{'enter'} ] )
37-
->perform;
36+
{
37+
no warnings qw{redefine once};
38+
local *Selenium::Remote::WebElement::send_keys = sub { return $_[0] };
39+
$action_chains->send_keys_to_element( $input_text, "test" )
40+
->key_down( [ KEYS->{'enter'} ] )->key_up( [ KEYS->{'enter'} ] )
41+
->perform;
42+
}
3843
$driver->find_elements_ok( "//*[\@class='hdtb-mitem']",
3944
"We found Google's navbar" );
4045
$driver->quit;

t/Test-Selenium-Remote-Driver-google.t

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use strict;
22
use warnings;
3-
use Test::More;
3+
use Test::More tests => 3;
44
use Test::Selenium::Remote::Driver;
55
use Selenium::Remote::Mock::RemoteConnection;
6-
6+
use Carp::Always;
77
use FindBin;
88
use lib $FindBin::Bin . '/lib';
99
use TestHarness;
@@ -18,7 +18,9 @@ my $t = Test::Selenium::Remote::Driver->new(
1818
%selenium_args
1919
);
2020
$t->get_ok('http://www.google.com');
21-
$t->title_like(qr/Google/);
22-
$t->body_like(qr/Google/);
23-
24-
done_testing();
21+
$t->title_like(qr/Google/, "We were able to get the expected page title" );
22+
{
23+
no warnings 'redefine';
24+
local *Selenium::Remote::WebElement::get_text = sub { return 'Google'; };
25+
$t->body_like(qr/Google/, "We got the expected text on the page");
26+
}

0 commit comments

Comments
 (0)