7
use Test::Builder::Tester tests => 48;
8
Test::Builder::Tester::color(1);
12
use_ok 'Test::WWW::Selenium';
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';
25
$Mock_resp->mock('content' => sub { 'OK,Some Title' });
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');
33
Browser_gets_closed: {
34
$Mock_resp->mock('content' => sub { 'OK' });
36
req_ok('cmd=testComplete&sessionId=SESSION_ID');
41
# run these tests twice, the first time will create the function,
42
# the second time will use the auto-loaded function
44
$Mock_resp->mock('content' => sub { 'OK,SESSION_ID' });
45
my $sel = Test::WWW::Selenium->new(browser_url => 'http://foo.com');
48
$Mock_resp->mock('content' => sub { 'OK,foo' });
49
test_out('ok 1 - bar');
50
$sel->text_is('id', 'foo', 'bar');
54
$Mock_resp->mock('content' => sub { 'OK,baz' });
55
test_out('not ok 1 - bar');
57
$sel->text_is('id', 'foo', 'bar');
58
test_test(skip_err => 1, title => 'is fail');
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');
67
$Mock_resp->mock('content' => sub { 'OK,foo' });
68
test_out('not ok 1 - bar');
70
$sel->text_isnt('id', 'foo', 'bar');
71
test_test(skip_err => 1, title => 'isnt fail');
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');
80
$Mock_resp->mock('content' => sub { 'OK,baz' });
81
test_out('not ok 1 - bar');
83
$sel->text_like('id', qr/foo/, 'bar');
84
test_test(skip_err => 1, title => 'like fail');
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');
93
$Mock_resp->mock('content' => sub { 'OK,foo' });
94
test_out('not ok 1 - bar');
96
$sel->text_unlike('id', qr/foo/, 'bar');
97
test_test(skip_err => 1, title => 'unlike fail');
100
$Mock_resp->mock('content' => sub { 'OK' });
105
$Mock_resp->mock('content' => sub { 'OK,SESSION_ID' });
106
my $sel = Test::WWW::Selenium->new(browser_url => 'http://foo.com');
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');
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");
120
$sel->click_ok('id', 'bar');
121
test_test(skip_err => 1, title => 'click fail');
124
$Mock_resp->mock('content' => sub { 'OK' });
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');
133
my $method = "${getter}_is";
135
$Mock_resp->mock('content' => sub { 'OK,foo' });
136
test_out('ok 1 - bar');
137
$sel->$method('foo', 'bar');
138
test_test('is pass');
141
$Mock_resp->mock('content' => sub { 'OK,baz' });
142
test_out('not ok 1 - bar');
144
$sel->$method('foo', 'bar');
145
test_test(skip_err => 1, title => 'is fail');
148
$Mock_resp->mock('content' => sub { 'OK' });
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';
157
$Mock_resp->mock('content' => sub { 'OK' });
158
throws_ok { $sel->drink_coffee_ok } qr/Can't locate object method/;
160
$Mock_resp->mock('content' => sub { 'OK' });
164
$Mock_resp->mock('content' => sub { 'OK,SESSION_ID' });
165
my $sel = Test::WWW::Selenium->new(browser_url => 'http://foo.com');
168
my @locations = ('http://example.com/',
169
'http://example.com/bar',
170
'http://example.com:8080/baz',
172
for my $abs (@locations) {
173
$Mock_resp->mock('content' => sub { "OK,$abs" });
174
is $sel->get_location, $abs, "location $abs";
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');
184
$Mock_resp->mock('content' => sub { 'OK,http://foo.com:23/monkey/man' });
185
test_out('not ok 1 - bar');
187
$sel->location_is('foo', 'bar');
188
test_test(skip_err => 1, title => 'is fail');
191
$Mock_resp->mock('content' => sub { 'OK' });
194
Default_test_names: {
196
$Mock_resp->mock('content' => sub { 'OK,SESSION_ID' });
197
my $sel = Test::WWW::Selenium->new(browser_url => 'http://foo.com',
200
$Mock_resp->mock('content' => sub { 'OK' });
202
$sel->click_ok('id', 'bar');
203
test_test('default names off');
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',
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');
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');
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');
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;