10-switch-to-window.t 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. use strict;
  2. use warnings;
  3. use 5.010;
  4. use Test::More;
  5. use Test::Selenium::Remote::Driver;
  6. if (not Test::Selenium::Remote::Driver->server_is_running()) {
  7. plan skip_all => 'The Selenium server must be running for this test';
  8. }
  9. plan tests => 9;
  10. my $s = Test::Selenium::Remote::Driver->new(
  11. default_finder => 'css',
  12. javascript => 1,
  13. );
  14. my $perl_title = 'The Perl Programming Language - www.perl.org';
  15. my $cpan_title = 'The Comprehensive Perl Archive Network - www.cpan.org';
  16. $s->get_ok('http://perl.org/');
  17. $s->title_is($perl_title);
  18. my $old_handles = $s->get_window_handles;
  19. is scalar(@$old_handles), 1;
  20. my $perl_handle = $old_handles->[0];
  21. # setting the window.name manually
  22. $s->execute_script(q{return window.name = 'perlorg';});
  23. # setting the window.name when opening the other window
  24. $s->execute_script(q{$(window.open('http://cpan.org/', 'cpanorg'))});
  25. $s->title_is($perl_title);
  26. my $handles = $s->get_window_handles;
  27. is scalar(@$handles), 2;
  28. # We don't assume any order in the @$handles array:
  29. my $cpan_handle = $perl_handle eq $handles->[0] ? $handles->[1] : $handles->[0];
  30. diag explain $handles;
  31. $s->switch_to_window($cpan_handle);
  32. $s->title_is($cpan_title);
  33. $s->switch_to_window($perl_handle);
  34. $s->title_is($perl_title);
  35. $s->switch_to_window('cpanorg');
  36. $s->title_is($cpan_title);
  37. $s->switch_to_window('perlorg');
  38. $s->title_is($perl_title);