3

I am starting to learn how to become a better test driven developer when creating web applications in Django. I am trying to use Selenium to open a browser, but I am getting an error.

selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: /var/folders/xn/bvyw0fm97j1_flsyggj0xn9r0000gp/T/tmptoxt890d If you specified a log_file in the FirefoxBinary constructor, check it for details.

I read that by "Installing the FF extension "Disable Add-on Compatibility Checks" skips this and everything is fine." selenium.common.exceptions.WebDriverException: Message: Can't load the profile. I did this, but It is still not working. I used Python2.7 and Python3.5 with Selenium version 2.53.6.

Python file

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import unittest

caps = DesiredCapabilities.FIREFOX
caps["marionette"] = True

class NewVisitorTest(unittest.TestCase):  

    def setUp(self):  
        self.browser = webdriver.Firefox(capabilities=caps)

    def tearDown(self):  
        self.browser.quit()

    def test_can_start_a_list_and_retrieve_it_later(self):  
        self.browser.get('http://localhost:8000')

        self.assertIn('To-Do', self.browser.title)  

if __name__ == '__main__':  
    unittest.main(warnings='ignore') 

Stack Trace

Creating test database for alias 'default'...
EException ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x103f652b0>>
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 151, in __del__
    self.stop()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 123, in stop
    if self.process is None:
AttributeError: 'Service' object has no attribute 'process'

======================================================================
ERROR: test_can_start_a_list_and_retrieve_it_later (functional_tests.NewVisitorTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/timothybaney/Treehouse/TDD/superlists/functional_tests.py", line 13, in setUp
    self.browser = webdriver.Firefox(capabilities=caps)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 82, in __init__
    self.service.start()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 62, in start
    stdout=self.log_file, stderr=self.log_file)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg)
NotADirectoryError: [Errno 20] Not a directory

----------------------------------------------------------------------
Ran 1 test in 0.012s

FAILED (errors=1)
Destroying test database for alias 'default'...
Community
  • 1
  • 1
TJB
  • 3,706
  • 9
  • 51
  • 102

1 Answers1

3

That error is because you are using FF 48. For FF>=47 FirefoxDriver stop working. You must use the new MarionetteDriver

Set up this:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

caps = DesiredCapabilities.FIREFOX
caps["marionette"] = True

browser = webdriver.Firefox(capabilities=caps)
browser.get('http://localhost:8000')

assert 'Django' in browser.title
  • Awesome, it worked. Thanks Yacdaniel Hurtado ! Now I can get on with my learnings. – TJB Sep 05 '16 at 05:14
  • I had this working, and I'm not sure what happened over night, but now I am getting this issue. NotADirectoryError: [Errno 20] Not a directory. Do I have to pass in a path to the firefox executable on my computer to Firefox alongside capabilities ? – TJB Sep 05 '16 at 17:44
  • yes you can, add it: `caps["binary"] = "/usr/bin/firefox"` but it looks like other kind of problem, did you change your code or something? – Yacdaniel Hurtado Sep 05 '16 at 18:12
  • Not by a lot, just by putting unit tests into a TestCase class. I updated my post with the new code. – TJB Sep 05 '16 at 18:16
  • As well as the stack trace – TJB Sep 05 '16 at 18:19