splinter icon indicating copy to clipboard operation
splinter copied to clipboard

Can't open Firefox that is installed at a custom path

Open dwt opened this issue 11 years ago • 5 comments

Hi there,

I've got my development browsers installed in /Users/$user/Applications/Network/Browser/ - instead of in /Applications.

This however brings the problem that splinter doesn't find my firefox - and as far as I can see from the source code there is also no ability to set a custom path to find Firefox by.

Well, what to do?

For some ruby app I'm working on, I wrote this code to find the firefox binary:

# -*- encoding : utf-8 -*-
# Only needs doing on OS X
if RbConfig::CONFIG["host_os"].include? 'darwin'

  # Find it with  Spotlight
  firefox_paths = %x[mdfind "kMDItemFSName = Firefox.app"]
  firefox_path = firefox_paths.split('\n').first.chomp
  firefox_executable_path = File.join(firefox_path, '/Contents/MacOS/firefox')

  # Another way would be to dump launch services database and grep it out there
  # /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump | grep -n7 org.mozilla.firefox | grep path: | awk '{ print($3) }'

  require 'selenium-webdriver'
  Selenium::WebDriver::Firefox::Binary.path=firefox_executable_path

end

Please either adopt something based on this code (this will always find firefox regardless where it is installed) or allow the path to be set as an argument to the firefox web driver wrapper. (Similar settings might be necessary for the other browsers).

dwt avatar Mar 14 '15 15:03 dwt

This workaround seems to work for me, maybe you an adapt it to your needs:

class Monkey(object):
    def patch(self):
        import sys
        if not sys.platform.startswith('darwin'):
            return
        def find_firefox_path(self):
            from subprocess import check_output
            import os
            firefox_path = check_output(["mdfind", "kMDItemFSName = Firefox.app"]).decode('utf-8').strip()
            return os.path.join(firefox_path, "Contents/MacOS/firefox-bin")
        from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
        FirefoxBinary._get_firefox_start_cmd = find_firefox_path
Monkey().patch()

Please note, I have only tested the above code in python3.

dwt avatar Mar 14 '15 15:03 dwt

Hello Maintainers - what do you think, could you include this feature into splinter proper? That way splinter would find firefox binaries on mac regardless of where they are installed.

Some customization would still be needed for people with multiple versions of firefox, but it's need should be greatly diminished.

dwt avatar Oct 03 '15 09:10 dwt

If you create docs and tests we gladly accept your PR, friend.

douglascamata avatar Oct 03 '15 13:10 douglascamata

Well, see https://github.com/cobrateam/splinter/pull/437

dwt avatar Oct 08 '15 19:10 dwt

@andrewsmedina Currently, users can supply a FirefoxBinary with a custom path to the Browser object. The auto-detect feature in #437 is interesting, but out of scope from this issue.

I'm closing this since there's nothing to fix. Re-open if you disagree or I misunderstood.

javascript-error avatar Aug 25 '20 17:08 javascript-error