~testplan-team/testplan/source-collection

« back to all changes in this revision

Viewing changes to selenium-remote-control-1.0.1-dist/selenium-remote-control-1.0.1/selenium-perl-client-driver-1.0.1/t/test-selenium.t

  • Committer: edA-qa mort-ora-y
  • Date: 2009-07-02 09:23:56 UTC
  • Revision ID: eda-qa@disemia.com-20090702092356-w9rxifuvlva3bk31
upgradingĀ selenium

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
use strict;
 
3
use warnings;
 
4
use Test::More;
 
5
use Test::Exception;
 
6
use Test::Mock::LWP;
 
7
use Test::Builder::Tester tests => 48;
 
8
Test::Builder::Tester::color(1);
 
9
 
 
10
BEGIN {
 
11
    use lib 'lib';
 
12
    use_ok 'Test::WWW::Selenium';
 
13
}
 
14
 
 
15
Good_usage: {
 
16
    my $sel;
 
17
    Start_a_browser: {
 
18
        $Mock_resp->mock('content' => sub { 'OK,SESSION_ID' });
 
19
        $sel = Test::WWW::Selenium->new(browser_url => 'http://foo.com');
 
20
        isa_ok $sel, 'Test::WWW::Selenium';
 
21
        is $sel->{session_id}, 'SESSION_ID', 'correct session id';
 
22
    }
 
23
 
 
24
    Test_page_title: {
 
25
        $Mock_resp->mock('content' => sub { 'OK,Some Title' });
 
26
        $sel->open;
 
27
        test_out("ok 1 - get_title, 'Some Title'");
 
28
        $sel->title_is('Some Title');
 
29
        test_test('title_is passes');
 
30
        req_ok('cmd=getTitle&sessionId=SESSION_ID');
 
31
    }
 
32
 
 
33
    Browser_gets_closed: {
 
34
        $Mock_resp->mock('content' => sub { 'OK' });
 
35
        $sel = undef; 
 
36
        req_ok('cmd=testComplete&sessionId=SESSION_ID');
 
37
    }
 
38
}
 
39
 
 
40
Comparators: {
 
41
    # run these tests twice, the first time will create the function,
 
42
    # the second time will use the auto-loaded function
 
43
  for(1 .. 2) {
 
44
    $Mock_resp->mock('content' => sub { 'OK,SESSION_ID' });
 
45
    my $sel = Test::WWW::Selenium->new(browser_url => 'http://foo.com');
 
46
    $sel->open;
 
47
    is_pass: {
 
48
        $Mock_resp->mock('content' => sub { 'OK,foo' });
 
49
        test_out('ok 1 - bar');
 
50
        $sel->text_is('id', 'foo', 'bar');
 
51
        test_test('is pass');
 
52
    }
 
53
    is_fail: {
 
54
        $Mock_resp->mock('content' => sub { 'OK,baz' });
 
55
        test_out('not ok 1 - bar');
 
56
        test_fail(+1);
 
57
        $sel->text_is('id', 'foo', 'bar');
 
58
        test_test(skip_err => 1, title => 'is fail');
 
59
    }
 
60
    isnt_pass: {
 
61
        $Mock_resp->mock('content' => sub { 'OK,baz' });
 
62
        test_out('ok 1 - bar');
 
63
        $sel->text_isnt('id', 'foo', 'bar');
 
64
        test_test('isnt pass');
 
65
    }
 
66
    isnt_fail: {
 
67
        $Mock_resp->mock('content' => sub { 'OK,foo' });
 
68
        test_out('not ok 1 - bar');
 
69
        test_fail(+1);
 
70
        $sel->text_isnt('id', 'foo', 'bar');
 
71
        test_test(skip_err => 1, title => 'isnt fail');
 
72
    }
 
73
    like_pass: {
 
74
        $Mock_resp->mock('content' => sub { 'OK,foo' });
 
75
        test_out('ok 1 - bar');
 
76
        $sel->text_like('id', qr/foo/, 'bar');
 
77
        test_test('like pass');
 
78
    }
 
79
    like_fail: {
 
80
        $Mock_resp->mock('content' => sub { 'OK,baz' });
 
81
        test_out('not ok 1 - bar');
 
82
        test_fail(+1);
 
83
        $sel->text_like('id', qr/foo/, 'bar');
 
84
        test_test(skip_err => 1, title => 'like fail');
 
85
    }
 
86
    unlike_pass: {
 
87
        $Mock_resp->mock('content' => sub { 'OK,baz' });
 
88
        test_out('ok 1 - bar');
 
89
        $sel->text_unlike('id', qr/foo/, 'bar');
 
90
        test_test('unlike pass');
 
91
    }
 
92
    unlike_fail: {
 
93
        $Mock_resp->mock('content' => sub { 'OK,foo' });
 
94
        test_out('not ok 1 - bar');
 
95
        test_fail(+1);
 
96
        $sel->text_unlike('id', qr/foo/, 'bar');
 
97
        test_test(skip_err => 1, title => 'unlike fail');
 
98
    }
 
99
    # for $sel DESTROY
 
100
    $Mock_resp->mock('content' => sub { 'OK' });
 
101
  }
 
102
}
 
103
 
 
104
Commands: {
 
105
    $Mock_resp->mock('content' => sub { 'OK,SESSION_ID' });
 
106
    my $sel = Test::WWW::Selenium->new(browser_url => 'http://foo.com');
 
107
    $sel->open;
 
108
    click_pass: {
 
109
        $Mock_resp->mock('content' => sub { 'OK' });
 
110
        test_out('ok 1 - click, id, bar');
 
111
        $sel->click_ok('id', 'bar');
 
112
        test_test('click pass');
 
113
    }
 
114
    click_fail: {
 
115
        $Mock_resp->mock('content' => sub { 'Failed to click' });
 
116
        test_out('not ok 1 - click, id, bar');
 
117
        test_err("# Error requesting http://localhost:4444/selenium-server/driver/?cmd=click&1=id&2=bar&sessionId=SESSION_ID:");
 
118
        test_err("# Failed to click");
 
119
        test_fail(+1);
 
120
        $sel->click_ok('id', 'bar');
 
121
        test_test(skip_err => 1, title => 'click fail');
 
122
    }
 
123
    # for $sel DESTROY
 
124
    $Mock_resp->mock('content' => sub { 'OK' });
 
125
}
 
126
 
 
127
no_locatior: { 
 
128
    $Mock_resp->mock('content' => sub { 'OK,SESSION_ID' });
 
129
    for my $getter (qw(alert prompt absolute_location title)) {
 
130
        $Mock_resp->mock('content' => sub { 'OK,SESSION_ID' });
 
131
        my $sel = Test::WWW::Selenium->new(browser_url => 'http://foo.com');
 
132
        $sel->open;
 
133
        my $method = "${getter}_is";
 
134
        is_pass: {
 
135
            $Mock_resp->mock('content' => sub { 'OK,foo' });
 
136
            test_out('ok 1 - bar');
 
137
            $sel->$method('foo', 'bar');
 
138
            test_test('is pass');
 
139
        }
 
140
        is_fail: {
 
141
            $Mock_resp->mock('content' => sub { 'OK,baz' });
 
142
            test_out('not ok 1 - bar');
 
143
            test_fail(+1);
 
144
            $sel->$method('foo', 'bar');
 
145
            test_test(skip_err => 1, title => 'is fail');
 
146
        }
 
147
        # for $sel DESTROY
 
148
        $Mock_resp->mock('content' => sub { 'OK' });
 
149
    }
 
150
}
 
151
 
 
152
Non_existant_command: {
 
153
    $Mock_resp->mock('content' => sub { 'OK,SESSION_ID' });
 
154
    my $sel = Test::WWW::Selenium->new(browser_url => 'http://foo.com');
 
155
    isa_ok $sel, 'Test::WWW::Selenium';
 
156
    $sel->open;
 
157
    $Mock_resp->mock('content' => sub { 'OK' });
 
158
    throws_ok { $sel->drink_coffee_ok } qr/Can't locate object method/;
 
159
    # for $sel DESTROY
 
160
    $Mock_resp->mock('content' => sub { 'OK' });
 
161
}
 
162
 
 
163
Relative_location: {
 
164
    $Mock_resp->mock('content' => sub { 'OK,SESSION_ID' });
 
165
    my $sel = Test::WWW::Selenium->new(browser_url => 'http://foo.com');
 
166
    $sel->open;
 
167
    get_location: {
 
168
        my @locations = ('http://example.com/',
 
169
                         'http://example.com/bar',
 
170
                         'http://example.com:8080/baz',
 
171
                        );
 
172
        for my $abs (@locations) {
 
173
            $Mock_resp->mock('content' => sub { "OK,$abs" });
 
174
            is $sel->get_location, $abs, "location $abs";
 
175
        }
 
176
    }
 
177
    location_is_pass: {
 
178
        $Mock_resp->mock('content' => sub { 'OK,http://foo.com:23/monkey/man' });
 
179
        test_out('ok 1 - bar');
 
180
        $sel->location_is('http://foo.com:23/monkey/man', 'bar');
 
181
        test_test('is pass');
 
182
    }
 
183
    location_is_fail: {
 
184
        $Mock_resp->mock('content' => sub { 'OK,http://foo.com:23/monkey/man' });
 
185
        test_out('not ok 1 - bar');
 
186
        test_fail(+1);
 
187
        $sel->location_is('foo', 'bar');
 
188
        test_test(skip_err => 1, title => 'is fail');
 
189
    }
 
190
    # for $sel DESTROY
 
191
    $Mock_resp->mock('content' => sub { 'OK' });
 
192
}
 
193
 
 
194
Default_test_names: {
 
195
    Default_names_off: {
 
196
        $Mock_resp->mock('content' => sub { 'OK,SESSION_ID' });
 
197
        my $sel = Test::WWW::Selenium->new(browser_url => 'http://foo.com', 
 
198
                                           default_names => 0);
 
199
        $sel->open;
 
200
        $Mock_resp->mock('content' => sub { 'OK' });
 
201
        test_out('ok 1');
 
202
        $sel->click_ok('id', 'bar');
 
203
        test_test('default names off');
 
204
    }
 
205
    Test_name_provided: {
 
206
        $Mock_resp->mock('content' => sub { 'OK,SESSION_ID' });
 
207
        my $sel = Test::WWW::Selenium->new(browser_url => 'http://foo.com', 
 
208
                                           default_names => 1);
 
209
        $sel->open;
 
210
        $Mock_resp->mock('content' => sub { 'OK' });
 
211
        test_out('ok 1 - test name');
 
212
        $sel->click_ok('id', 'bar', 'test name');
 
213
        test_test('default names on with test name');
 
214
    }
 
215
    No_test_name_provided: {
 
216
        $Mock_resp->mock('content' => sub { 'OK,SESSION_ID' });
 
217
        my $sel = Test::WWW::Selenium->new(browser_url => 'http://foo.com');
 
218
        $sel->open;
 
219
        $Mock_resp->mock('content' => sub { 'OK' });
 
220
        test_out('ok 1 - click, id, bar');
 
221
        $sel->click_ok('id', 'bar');
 
222
        test_test('default names on with test name');
 
223
    }
 
224
}
 
225
 
 
226
exit;
 
227
 
 
228
 
 
229
sub req_ok {
 
230
    my $content = shift;
 
231
    my $args = $Mock_req->new_args;
 
232
    is $args->[0], 'HTTP::Request';
 
233
    is $args->[1], 'POST';
 
234
    is $args->[2], 'http://localhost:4444/selenium-server/driver/';
 
235
    is $args->[4], $content;
 
236
}
 
237