File: selenium-compat.t

package info (click to toggle)
libtest-www-selenium-perl 1.36-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 460 kB
  • sloc: perl: 2,382; xml: 1,459; makefile: 8
file content (124 lines) | stat: -rw-r--r-- 3,303 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 27;
use Test::Exception;

# The purpose of these tests are to ensure that WWW::Selenium does not 
# break backwards compatibility with previously released versions.

BEGIN {
    use lib 'lib';
    use_ok 't::WWW::Selenium';  # subclass for testing
}

my $sel = t::WWW::Selenium->new;
isa_ok $sel, 't::WWW::Selenium';
$sel->open;

Simple_check: {
    $sel->_method_exists("is_location");
    $sel->_method_exists("get_checked");
    $sel->_method_exists("is_selected");
    $sel->_method_exists("get_selected_options");
    $sel->_method_exists("get_absolute_location");
}

Is_location: {
    # is_location now uses get_location under the hood
    True: {
        $sel->_set_mock_response_content('http://example.com');
        ok $sel->is_location('example.com');
    }

    False: {
        $sel->_set_mock_response_content('http://examplebad.com');
        ok !$sel->is_location('monkey.com');
    }
}

Get_checked: {
    True: {
        $sel->_set_mock_response_content('1');
        is $sel->get_checked('id=foo'), 'true';
    }

    False: {
        $sel->_set_mock_response_content('0');
        is $sel->get_checked('id=foo'), 'false';
    }

    Element_does_not_exist: {
        my $error_msg = "Element id=foo not found";
        $sel->_set_mock_response_content("ERROR: $error_msg");
        throws_ok { $sel->get_checked('id=foo') }
                  qr/\Q$error_msg\E/;
    }
}

Is_selected: {
    True: {
        $sel->_set_mock_response_content('ape,monkey');
        ok $sel->is_selected('id=foo', 'monkey');
    }

    False: {
        $sel->_set_mock_response_content('ape,human');
        ok !$sel->is_selected('id=foo', 'monkey');
    }

    Label: {
        $sel->_set_mock_response_content('ape,monkey');
        ok $sel->is_selected('id=foo', 'label=monkey');
    }

    Value: {
        $sel->_set_mock_response_content('ape,monkey');
        ok $sel->is_selected('id=foo', 'value=monkey');
    }

    Id: {
        $sel->_set_mock_response_content('ape,monkey');
        ok $sel->is_selected('id=foo', 'id=monkey');
    }

    Index_true: {
        $sel->_set_mock_response_content('1,2,3');
        ok $sel->is_selected('id=foo', 'index=2');
    }

    Index_false: {
        $sel->_set_mock_response_content('1,3,4');
        ok !$sel->is_selected('id=foo', 'index=2');
    }

    Element_does_not_exist: {
        my $error_msg = "Element id=foo not found";
        $sel->_set_mock_response_content("ERROR: $error_msg");
        throws_ok { $sel->is_selected('id=foo', 'value=monkey') }
                  qr/\Q$error_msg\E/;
    }
}

Get_selected_options: {
    None_selected: {
        $sel->_set_mock_response_content('');
        is_deeply [$sel->get_selected_options('id=foo')], [''];
    }

    One_selected: {
        $sel->_set_mock_response_content('first response');
        is_deeply [$sel->get_selected_options('id=foo')], ['first response'];
    }

    Two_selected: {
        $sel->_set_mock_response_content('first response,second');
        is_deeply [$sel->get_selected_options('id=foo')], 
                  ['first response', 'second'];
    }
}

Get_absolute_location: {
    $sel->_set_mock_response_content('http://example.com');
    is $sel->get_absolute_location, 'http://example.com';
}