0cb2d87b968f921d5f46074700bffdf53644f85a
[catagits/Test-WWW-Selenium-Catalyst.git] / t / 01-live.t
1 #!/usr/bin/perl
2 # 01-live.t 
3 # Copyright (c) 2006 Jonathan Rockway <jrockway@cpan.org>
4
5 use Test::More tests => 80;
6 use FindBin;
7 use lib "$FindBin::Bin/lib";
8
9 use IPC::Cmd qw/can_run/;
10
11 my $have_apps = 
12   can_run('java') &&
13   ( can_run('firefox') || can_run('firefox-bin') );
14                 
15 SKIP: {
16   unless ($have_apps) {
17     # Missing Java or firefox, just do a use_ok test
18     use_ok('Test::WWW::Selenium::Catalyst', 'TestApp',
19       -no_selenium_server => 1);
20     skip "java and firefox requires for further testing", 79;
21   } else {
22     diag("You need to have firefox(-bin) in your path for this to work!");
23
24     my $port = int(20000+rand()*20000);
25     # Try to cope with case when selenium is already running or something is on port 4444
26     my $sel = eval { 
27
28       use_ok('Test::WWW::Selenium::Catalyst', 'TestApp',
29         -selenium_args => "-singleWindow -port $port");
30
31       Test::WWW::Selenium::Catalyst->start( {
32         browser => '*firefox', 
33         selenium_port => $port 
34       } ); 
35     };
36
37     skip $@, 80 if $@;
38
39     $sel->open_ok('/');
40     $sel->text_is("link=Click here", "Click here");
41     $sel->click_ok("link=Click here");
42     $sel->wait_for_page_to_load_ok("30000", 'wait');
43     for my $i (1..10){
44         $sel->open_ok("/words/$i");
45         $sel->is_text_present_ok(
46       qq{Here you'll find all things "words" printed $i time(s)!});
47         
48         for my $j (1..$i){
49       $sel->is_text_present_ok("$j: foo bar baz bat qux quux");
50         }
51     }
52   }
53 }