Version 0.07
[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;
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   $ENV{WE_HAVE_SELENIUM};
15                 
16 SKIP: {
17   unless ($have_apps) {
18     # Missing Java or firefox, just do a use_ok test
19     use_ok('Test::WWW::Selenium::Catalyst', 'TestApp',
20       -no_selenium_server => 1);
21     skip "java and firefox requires for further testing", 79;
22   } else {
23     diag("You need to have firefox(-bin) in your path for this to work!");
24
25     my $port = int(20000+rand()*20000);
26     # Try to cope with case when selenium is already running or something is on port 4444
27     my $sel = eval { 
28
29       use_ok('Test::WWW::Selenium::Catalyst', 'TestApp',
30         -selenium_args => "-singleWindow -port $port");
31
32       Test::WWW::Selenium::Catalyst->start( {
33         browser => '*firefox', 
34         selenium_port => $port 
35       } ); 
36     };
37
38     skip $@, 79 if $@;
39
40     $sel->open_ok('/');
41     $sel->text_is("link=Click here", "Click here");
42     $sel->click_ok("link=Click here");
43     $sel->wait_for_page_to_load_ok("30000", 'wait');
44     for my $i (1..10){
45         $sel->open_ok("/words/$i");
46         $sel->is_text_present_ok(
47       qq{Here you'll find all things "words" printed $i time(s)!});
48         
49         for my $j (1..$i){
50       $sel->is_text_present_ok("$j: foo bar baz bat qux quux");
51         }
52     }
53   }
54 }
55
56 done_testing;