1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More qw/no_plan/;
use Test::Exception;
use Socialtext::WikiFixture::TestUtils qw/fixture_ok/;
BEGIN {
use lib 'lib';
use_ok 'Socialtext::WikiObject::TestPlan';
}
sel_fixture_ok (
name => 'Simple Selenese',
plan => <<EOT,
* Fixture: Selenese
| *Command* | *Option 1* | *Option 2* |
| open | / |
| verifyTitle | monkey |
| verifyTextPresent | water |
| verifyText | //body | pen? |
| verifyText | //body | qr/pen?/ |
| confirmation_like | pen? |
| confirmation_like | qr/pen?/ |
| clickAndWait | foo | |
EOT
tests => [
[ open_ok => '/' ],
[ title_like => qr/\Qmonkey\E/ ],
[ text_like => ['//body', qr/\Qwater\E/] ],
[ text_like => ['//body', qr/\Qpen?\E/] ],
[ text_like => ['//body', qr/pen?/s] ],
[ confirmation_like => qr/\Qpen?\E/ ],
[ confirmation_like => qr/pen?/s ],
[ click_ok => 'foo' ],
[ wait_for_page_to_load_ok => 10000 ],
],
);
sel_fixture_ok (
name => 'Specific timeout',
plan => <<EOT,
* Fixture: Selenese
| clickAndWait | foo | |
EOT
tests => [
[ click_ok => 'foo' ],
[ wait_for_page_to_load_ok => 9 ],
],
fixture_args => {
selenium_timeout => 9,
},
);
Pass_in_selenium: {
my $selenium = 'fake';
my $f = Socialtext::WikiFixture::Selenese->new(selenium => $selenium);
is $f->{selenium}, $selenium, "didn't create a new selenium";
$f->end_hook;
is $f->{selenium}, $selenium, "didn't undef selenium";
}
Variable_interpolation: {
my $f = Socialtext::WikiFixture::Selenese->new(selenium => 'fake');
my @opts = $f->_munge_options('%%foo%%');
is_deeply \@opts, ['undef'];
$f->{foo} = 'bar';
@opts = $f->_munge_options('%%foo%%');
is_deeply \@opts, ['bar'];
}
Missing_mandatory_args: {
throws_ok { Socialtext::WikiFixture::Selenese->new }
qr/Selenium host/;
throws_ok { Socialtext::WikiFixture::Selenese->new(host => 'foo') }
qr/Selenium browser_url/;
}
Optional_selenium_port: {
my $f = Socialtext::WikiFixture::Selenese->new(
host => 'foo',
browser_url => 'bar',
port => 1234,
);
is $f->{selenium}{args}{host}, 'foo';
is $f->{selenium}{args}{browser_url}, 'bar';
is $f->{selenium}{args}{port}, 1234;
}
Selenese_command_mapping: {
sel_fixture_ok (
name => 'text_like with 1 arg',
plan => <<EOT,
| verifyText | foo | |
EOT
tests => [
[ text_like => ['//body', qr/foo/] ],
],
);
}
Camel_cased_commands: {
my %commands = (
SuperDuper => 'super_duper',
Super => 'super',
);
my $f = Socialtext::WikiFixture::Selenese->new(selenium => 'fake');
for my $long (keys %commands) {
is $f->_munge_command($long), $commands{$long}, $long;
}
}
Quote_as_regex: {
my $f = Socialtext::WikiFixture::Selenese->new(selenium => 'fake');
is $f->quote_as_regex(), qr//;
is $f->quote_as_regex('foo'), qr/\Qfoo\E/;
is $f->quote_as_regex('qr/foo/'), qr/foo/s;
}
Special_functions: {
no warnings qw/redefine once/;
my $f = Socialtext::WikiFixture::Selenese->new(selenium => 'fake');
my $diag = '';
*Socialtext::WikiFixture::Selenese::diag = sub { $diag .= "$_[0]\n" };
Comment: {
$f->comment('foo');
is $diag, "\ncomment: foo\n";
}
Set: {
$diag = '';
$f->set('foo', 'bar');
is $diag, "Set 'foo' to 'bar'\n";
is $f->{foo}, 'bar';
}
Bad_set: {
$diag = '';
$f->set('bar');
like $diag, qr/Both name and value/;
is $f->{bar}, undef;;
$diag = '';
$f->set(undef, 'bar');
like $diag, qr/Both name and value/;
}
}
sub sel_fixture_ok {
my %args = @_;
fixture_ok(
default_fixture => 'Selenese',
%args,
);
}
|