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::Firefox::Binary;
  6. use Selenium::Chrome;
  7. use Selenium::PhantomJS;
  8. use Selenium::Firefox;
  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 = Selenium::CanStartBinary::_find_executable('phantomjs');
  16. skip 'Phantomjs binary not found in path', 3
  17. unless $has_phantomjs;
  18. my $version = `phantomjs -v` // '';
  19. chomp $version;
  20. skip 'PhantomJS binary not found in path', 3
  21. unless is_proper_phantomjs_available($version);
  22. my $phantom = Selenium::PhantomJS->new;
  23. is( $phantom->browser_name, 'phantomjs', 'binary phantomjs is okay');
  24. isnt( $phantom->port, 4444, 'phantomjs can start up its own binary');
  25. ok( Selenium::CanStartBinary::probe_port( $phantom->port ), 'the phantomjs binary is listening on its port');
  26. }
  27. }
  28. CHROME: {
  29. SKIP: {
  30. my $has_chromedriver = Selenium::CanStartBinary::_find_executable('chromedriver');
  31. skip 'Chrome binary not found in path', 3
  32. unless $has_chromedriver;
  33. my $chrome = Selenium::Chrome->new;
  34. ok( $chrome->browser_name eq 'chrome', 'convenience chrome is okay' );
  35. isnt( $chrome->port, 4444, 'chrome can start up its own binary');
  36. ok( Selenium::CanStartBinary::probe_port( $chrome->port ), 'the chrome binary is listening on its port');
  37. }
  38. }
  39. FIREFOX: {
  40. my $command = Selenium::CanStartBinary::_construct_command('firefox', 1234);
  41. ok($command =~ /firefox -no-remote/, 'firefox command has proper args');
  42. SKIP: {
  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) = @_;
  54. $ver =~ s/\.\d$//;
  55. return $ver >= 1.9;
  56. }
  57. done_testing;