1
0

FindBinary.pm 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. sub coerce_simple_binary {
  12. my ($executable) = @_;
  13. my $manual_binary = _validate_manual_binary($executable);
  14. if ($manual_binary) {
  15. return $manual_binary;
  16. }
  17. else {
  18. return _naive_find_binary($executable);
  19. }
  20. }
  21. sub coerce_firefox_binary {
  22. my ($executable) = @_;
  23. my $manual_binary = _validate_manual_binary($executable);
  24. if ($manual_binary) {
  25. return $manual_binary;
  26. }
  27. else {
  28. return firefox_path();
  29. }
  30. }
  31. sub _validate_manual_binary {
  32. my ($executable) = @_;
  33. my $abs_executable = eval {
  34. my $path = abs_path($executable);
  35. die unless -e $path;
  36. $path
  37. };
  38. if ( $abs_executable ) {
  39. if ( -x $abs_executable ) {
  40. return $abs_executable;
  41. }
  42. else {
  43. die 'The binary at ' . $executable . ' is not executable. Choose the correct file or chmod +x it as needed.';
  44. }
  45. }
  46. }
  47. sub _naive_find_binary {
  48. my ($executable) = @_;
  49. my $naive_binary = which($executable);
  50. if (defined $naive_binary) {
  51. return $naive_binary;
  52. }
  53. else {
  54. warn qq(Unable to find the $naive_binary binary in your \$PATH. We'll try falling back to standard Remote Driver);
  55. return;
  56. }
  57. }