Binary.pm 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package Selenium::Firefox::Binary;
  2. # ABSTRACT: Subroutines for locating and properly initializing the Firefox Binary
  3. use File::Which qw/which/;
  4. use Selenium::Firefox::Profile;
  5. require Exporter;
  6. our @ISA = qw/Exporter/;
  7. our @EXPORT_OK = qw/firefox_path setup_firefox_binary_env/;
  8. sub _firefox_windows_path {
  9. # TODO: make this slightly less dumb
  10. return which('firefox');
  11. }
  12. sub _firefox_darwin_path {
  13. my $default_firefox = '/Applications/Firefox.app/Contents/MacOS/firefox-bin';
  14. if (-e $default_firefox) {
  15. return $default_firefox
  16. }
  17. else {
  18. return which('firefox-bin');
  19. }
  20. }
  21. sub _firefox_unix_path {
  22. # TODO: maybe which('firefox3'), which('firefox2') ?
  23. return which('firefox') || '/usr/bin/firefox';
  24. }
  25. sub firefox_path {
  26. my $path;
  27. if ($^O eq 'MSWin32') {
  28. $path =_firefox_windows_path();
  29. }
  30. elsif ($^O eq 'darwin') {
  31. $path = _firefox_darwin_path();
  32. }
  33. else {
  34. $path = _firefox_unix_path;
  35. }
  36. if (not -x $path) {
  37. die $path . ' is not an executable file.';
  38. }
  39. return $path;
  40. }
  41. sub setup_firefox_binary_env {
  42. my ($port) = @_;
  43. # TODO: respect the user's profile instead of overwriting it
  44. my $profile = Selenium::Firefox::Profile->new;
  45. $profile->add_webdriver($port);
  46. $ENV{'XRE_PROFILE_PATH'} = $profile->_layout_on_disk;
  47. $ENV{'MOZ_NO_REMOTE'} = '1'; # able to launch multiple instances
  48. $ENV{'MOZ_CRASHREPORTER_DISABLE'} = '1'; # disable breakpad
  49. $ENV{'NO_EM_RESTART'} = '1'; # prevent the binary from detaching from the console.log
  50. }
  51. 1;