CanStartBinary.t 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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::More;
  10. unless ( $ENV{RELEASE_TESTING} ) {
  11. plan skip_all => "Author tests not required for installation.";
  12. }
  13. PHANTOMJS: {
  14. SKIP: {
  15. my $has_phantomjs = which('phantomjs');
  16. skip 'Phantomjs binary not found in path', 3
  17. unless $has_phantomjs;
  18. skip 'PhantomJS binary not found in path', 3
  19. unless is_proper_phantomjs_available();
  20. my $phantom = Selenium::PhantomJS->new;
  21. is( $phantom->browser_name, 'phantomjs', 'binary phantomjs is okay');
  22. isnt( $phantom->port, 4444, 'phantomjs can start up its own binary');
  23. ok( Selenium::CanStartBinary::probe_port( $phantom->port ), 'the phantomjs binary is listening on its port');
  24. }
  25. }
  26. CHROME: {
  27. SKIP: {
  28. my $has_chromedriver = which('chromedriver');
  29. skip 'Chrome binary not found in path', 3
  30. unless $has_chromedriver;
  31. my $chrome = Selenium::Chrome->new;
  32. ok( $chrome->browser_name eq 'chrome', 'convenience chrome is okay' );
  33. isnt( $chrome->port, 4444, 'chrome can start up its own binary');
  34. ok( Selenium::CanStartBinary::probe_port( $chrome->port ), 'the chrome binary is listening on its port');
  35. }
  36. }
  37. FIREFOX: {
  38. my $command = Selenium::CanStartBinary::_construct_command('firefox', 1234);
  39. ok($command =~ /firefox -no-remote/, 'firefox command has proper args');
  40. SKIP: {
  41. skip 'Firefox will not start up on UNIX without a display', 3
  42. if ($^O ne 'MSWin32' && ! $ENV{DISPLAY});
  43. my $binary = Selenium::Firefox::Binary::firefox_path();
  44. skip 'Firefox binary not found in path', 3
  45. unless $binary;
  46. ok(-x $binary, 'we can find some sort of firefox');
  47. my $firefox = Selenium::Firefox->new;
  48. isnt( $firefox->port, 4444, 'firefox can start up its own binary');
  49. ok( Selenium::CanStartBinary::probe_port( $firefox->port ), 'the firefox binary is listening on its port');
  50. }
  51. }
  52. sub is_proper_phantomjs_available {
  53. my $ver = `phantomjs -v` // '';
  54. chomp $ver;
  55. $ver =~ s/^(\d\.\d).*/$1/;
  56. return $ver >= 1.9;
  57. }
  58. done_testing;