10-switch-to-window.t 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. use 5.010;
  2. use strict;
  3. use warnings;
  4. use Test::More;
  5. use Test::Selenium::Remote::Driver;
  6. use Selenium::Remote::Mock::RemoteConnection;
  7. use FindBin;
  8. use lib $FindBin::Bin . '/lib';
  9. use TestHarness;
  10. my $harness = TestHarness->new(
  11. this_file => $FindBin::Script
  12. );
  13. my %selenium_args = (
  14. default_finder => 'css',
  15. javascript => 1,
  16. %{ $harness->base_caps }
  17. );
  18. plan tests => 9;
  19. my $s = Test::Selenium::Remote::Driver->new(
  20. %selenium_args
  21. );
  22. my $perl_title = 'The Perl Programming Language - www.perl.org';
  23. my $cpan_title = 'The Comprehensive Perl Archive Network - www.cpan.org';
  24. $s->get_ok('http://perl.org/');
  25. $s->title_is($perl_title);
  26. my $old_handles = $s->get_window_handles;
  27. is scalar(@$old_handles), 1;
  28. my $perl_handle = $old_handles->[0];
  29. # setting the window.name manually
  30. $s->execute_script(q{return window.name = 'perlorg';});
  31. # setting the window.name when opening the other window
  32. $s->execute_script(q{$(window.open('http://cpan.org/', 'cpanorg'))});
  33. $s->title_is($perl_title);
  34. my $handles = $s->get_window_handles;
  35. is scalar(@$handles), 2;
  36. # We don't assume any order in the @$handles array:
  37. my $cpan_handle = $perl_handle eq $handles->[0] ? $handles->[1] : $handles->[0];
  38. $s->switch_to_window($cpan_handle);
  39. $s->title_is($cpan_title);
  40. $s->switch_to_window($perl_handle);
  41. $s->title_is($perl_title);
  42. $s->switch_to_window('cpanorg');
  43. $s->title_is($cpan_title);
  44. $s->switch_to_window('perlorg');
  45. $s->title_is($perl_title);