CanStartBinary.t 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. package ManualChrome {
  29. use Moo;
  30. with 'Selenium::CanStartBinary';
  31. has 'binary_name' => ( is => 'ro', default => 'fake' );
  32. has 'binary_port' => ( is => 'ro', default => 12345 );
  33. 1
  34. };
  35. ok( exception { ManualChrome->new( binary_path => '/not/executable') },
  36. 'we throw if the user specified binary is not executable');
  37. SKIP: {
  38. my $phantom_binary = which('phantomjs');
  39. skip 'PhantomJS needed for manual binary path tests', 3
  40. unless $phantom_binary;
  41. my $manual_phantom = Selenium::PhantomJS->new(
  42. binary_path => $phantom_binary
  43. );
  44. ok( $manual_phantom->browser_name eq 'phantomjs', 'convenience phantom is okay' );
  45. isnt( $manual_phantom->port, 4444, 'phantom can start up its own binary');
  46. ok( Selenium::CanStartBinary::probe_port( $manual_phantom->port ), 'the chrome binary is listening on its port');
  47. }
  48. }
  49. CHROME: {
  50. SKIP: {
  51. my $has_chromedriver = which('chromedriver');
  52. skip 'Chrome binary not found in path', 3
  53. unless $has_chromedriver;
  54. my $chrome = Selenium::Chrome->new;
  55. ok( $chrome->browser_name eq 'chrome', 'convenience chrome is okay' );
  56. isnt( $chrome->port, 4444, 'chrome can start up its own binary');
  57. ok( Selenium::CanStartBinary::probe_port( $chrome->port ), 'the chrome binary is listening on its port');
  58. }
  59. }
  60. FIREFOX: {
  61. my $command = Selenium::CanStartBinary::_construct_command('firefox', 1234);
  62. ok($command =~ /firefox -no-remote/, 'firefox command has proper args');
  63. SKIP: {
  64. skip 'Firefox will not start up on UNIX without a display', 3
  65. if ($^O ne 'MSWin32' && ! $ENV{DISPLAY});
  66. my $binary = Selenium::Firefox::Binary::firefox_path();
  67. skip 'Firefox binary not found in path', 3
  68. unless $binary;
  69. ok(-x $binary, 'we can find some sort of firefox');
  70. my $firefox = Selenium::Firefox->new;
  71. isnt( $firefox->port, 4444, 'firefox can start up its own binary');
  72. ok( Selenium::CanStartBinary::probe_port( $firefox->port ), 'the firefox binary is listening on its port');
  73. }
  74. }
  75. sub is_proper_phantomjs_available {
  76. my $ver = `phantomjs -v` // '';
  77. chomp $ver;
  78. $ver =~ s/^(\d\.\d).*/$1/;
  79. return $ver >= 1.9;
  80. }
  81. done_testing;