1
0

CanStartBinary.t 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #! /usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use File::Which qw/which/;
  5. use Selenium::Chrome;
  6. use Selenium::Firefox;
  7. use Selenium::Firefox::Binary;
  8. use Selenium::PhantomJS;
  9. use Test::Fatal;
  10. use Test::More;
  11. unless ( $ENV{RELEASE_TESTING} ) {
  12. plan skip_all => "Author tests not required for installation.";
  13. }
  14. PHANTOMJS: {
  15. SKIP: {
  16. my $has_phantomjs = which('phantomjs');
  17. skip 'Phantomjs binary not found in path', 3
  18. unless $has_phantomjs;
  19. skip 'PhantomJS binary not found in path', 3
  20. unless is_proper_phantomjs_available();
  21. my $phantom = Selenium::PhantomJS->new;
  22. is( $phantom->browser_name, 'phantomjs', 'binary phantomjs is okay');
  23. isnt( $phantom->port, 4444, 'phantomjs can start up its own binary');
  24. ok( Selenium::CanStartBinary::probe_port( $phantom->port ), 'the phantomjs binary is listening on its port');
  25. }
  26. }
  27. MANUAL: {
  28. ok( exception { PhantomJS->new( binary => '/bad/executable') },
  29. 'we throw if the user specified binary is not executable');
  30. SKIP: {
  31. my $phantom_binary = which('phantomjs');
  32. skip 'PhantomJS needed for manual binary path tests', 2
  33. unless $phantom_binary;
  34. my $manual_phantom = Selenium::PhantomJS->new(
  35. binary => $phantom_binary
  36. );
  37. isnt( $manual_phantom->port, 4444, 'manual phantom can start up user specified binary');
  38. ok( Selenium::CanStartBinary::probe_port( $manual_phantom->port ), 'the manual chrome binary is listening on its port');
  39. }
  40. }
  41. CHROME: {
  42. SKIP: {
  43. my $has_chromedriver = which('chromedriver');
  44. skip 'Chrome binary not found in path', 3
  45. unless $has_chromedriver;
  46. my $chrome = Selenium::Chrome->new;
  47. ok( $chrome->browser_name eq 'chrome', 'convenience chrome is okay' );
  48. isnt( $chrome->port, 4444, 'chrome can start up its own binary');
  49. ok( Selenium::CanStartBinary::probe_port( $chrome->port ), 'the chrome binary is listening on its port');
  50. }
  51. }
  52. FIREFOX: {
  53. SKIP: {
  54. skip 'Firefox will not start up on UNIX without a display', 3
  55. if ($^O ne 'MSWin32' && ! $ENV{DISPLAY});
  56. my $binary = Selenium::Firefox::Binary::firefox_path();
  57. skip 'Firefox binary not found in path', 3
  58. unless $binary;
  59. ok(-x $binary, 'we can find some sort of firefox');
  60. my $firefox = Selenium::Firefox->new;
  61. isnt( $firefox->port, 4444, 'firefox can start up its own binary');
  62. ok( Selenium::CanStartBinary::probe_port( $firefox->port ), 'the firefox binary is listening on its port');
  63. }
  64. }
  65. sub is_proper_phantomjs_available {
  66. my $ver = `phantomjs --version` // '';
  67. chomp $ver;
  68. $ver =~ s/^(\d\.\d).*/$1/;
  69. return $ver >= 1.9;
  70. }
  71. done_testing;