Ver código fonte

fixing the switch_to_window test

Gabor Szabo 11 anos atrás
pai
commit
f410cbb063
1 arquivos alterados com 23 adições e 21 exclusões
  1. 23 21
      t/10-switch-to-window.t

+ 23 - 21
t/10-switch-to-window.t

@@ -16,34 +16,36 @@ my $s = Test::Selenium::Remote::Driver->new(
     javascript     => 1,
 );
 
+my $perl_title = 'The Perl Programming Language - www.perl.org';
+my $cpan_title = 'The Comprehensive Perl Archive Network - www.cpan.org';
 
 $s->get_ok('http://perl.org/');
-$s->title_is('The Perl Programming Language - www.perl.org');
+$s->title_is($perl_title);
 my $old_handles = $s->get_window_handles;
 is scalar(@$old_handles), 1;
+my $perl_handle = $old_handles->[0];
+# setting the window.name manually
+$s->execute_script(q{return window.name = 'perlorg';});
 
-$s->execute_script(q{$(window.open('http://cpan.org/'))});
-$s->title_is('The Perl Programming Language - www.perl.org');
+# setting the window.name when opening the other window
+$s->execute_script(q{$(window.open('http://cpan.org/', 'cpanorg'))});
+$s->title_is($perl_title);
 
 my $handles = $s->get_window_handles;
 is scalar(@$handles), 2;
-
+# We don't assume any order in the @$handles array:
+my $cpan_handle = $perl_handle eq $handles->[0] ? $handles->[1] : $handles->[0];
 diag explain $handles;
-my @titles;
-foreach my $h (@$handles) {
-    $s->switch_to_window($h);
-    diag $s->get_title;
-    push @titles, $s->get_title;
-}
 
-my $current_title = $s->get_title;
-foreach my $t (@titles) {
-	TODO: {
-		local $TODO = 'switching window by title';
-    	eval {
-    	    $s->switch_to_window($t);
-    	};
-    	is $@, undef, 'exception switching';
-    	is $s->get_title, $t, 'title';
-	}
-}
+$s->switch_to_window($cpan_handle);
+$s->title_is($cpan_title);
+
+$s->switch_to_window($perl_handle);
+$s->title_is($perl_title);
+
+$s->switch_to_window('cpanorg');
+$s->title_is($cpan_title);
+
+$s->switch_to_window('perlorg');
+$s->title_is($perl_title);
+