1
0

FindBinary.pm 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package Selenium::CanStartBinary::FindBinary;
  2. # ABSTRACT: Coercions for finding webdriver binaries on your system
  3. use File::Which qw/which/;
  4. use Cwd qw/abs_path/;
  5. use File::Which qw/which/;
  6. use IO::Socket::INET;
  7. use Selenium::Firefox::Binary qw/firefox_path/;
  8. require Exporter;
  9. our @ISA = qw/Exporter/;
  10. our @EXPORT_OK = qw/coerce_simple_binary coerce_firefox_binary/;
  11. use constant IS_WIN => $^O eq 'MSWin32';
  12. sub coerce_simple_binary {
  13. my ($executable) = @_;
  14. my $manual_binary = _validate_manual_binary($executable);
  15. if ($manual_binary) {
  16. return $manual_binary;
  17. }
  18. else {
  19. return _naive_find_binary($executable);
  20. }
  21. }
  22. sub coerce_firefox_binary {
  23. my ($executable) = @_;
  24. my $manual_binary = _validate_manual_binary($executable);
  25. if ($manual_binary) {
  26. return $manual_binary;
  27. }
  28. else {
  29. return firefox_path();
  30. }
  31. }
  32. sub _validate_manual_binary {
  33. my ($executable) = @_;
  34. my $abs_executable = eval {
  35. my $path = abs_path($executable);
  36. die unless -e $path;
  37. $path
  38. };
  39. if ( $abs_executable ) {
  40. if ( -x $abs_executable || IS_WIN ) {
  41. return $abs_executable;
  42. }
  43. else {
  44. die 'The binary at ' . $executable . ' is not executable. Choose the correct file or chmod +x it as needed.';
  45. }
  46. }
  47. }
  48. sub _naive_find_binary {
  49. my ($executable) = @_;
  50. my $naive_binary = which($executable);
  51. if (defined $naive_binary) {
  52. return $naive_binary;
  53. }
  54. else {
  55. warn qq(Unable to find the $naive_binary binary in your \$PATH. We'll try falling back to standard Remote Driver);
  56. return;
  57. }
  58. }