Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Read only prefs.js in Firefox profile causes Webdriver exception #4228

Closed
lukeis opened this issue Mar 3, 2016 · 3 comments
Closed

Read only prefs.js in Firefox profile causes Webdriver exception #4228

lukeis opened this issue Mar 3, 2016 · 3 comments

Comments

@lukeis
Copy link
Member

lukeis commented Mar 3, 2016

Originally reported on Google Code with ID 4228

What steps will reproduce the problem?
1. Create a directory and copy prefs.js from your firefox profile.
2. Make prefs.js readonly
3. While instantiating firefox webdriver, pass in the created directory as firefox
profile directory.

What is the expected output? 
Firefox starts and webdriver is connected to it.


What do you see instead?
Firefox starts without a webdriver connection. Selenium raises a webdriver exception.


Selenium version: 2.24
OS: Win 7 64 bit
Browser: Firefox
Browser version: 13.01
Language: Python 2.7


Additional information:

We have checked into perforce (as part of the robot framework and its Selenium library)
the firefox profile that is to be used with the webdriver. The problem is perforce
makes the files as read-only unless you check them out for editing. Hence the tests
fail with the following error.

<error>

WebDriverException: Message: 'Can\'t load the profile. Profile Dir: c:\\users\\<USER_NAME>\\appdata\\local\\temp\\tmpj0oyp_\\webdriver-py-profilecopy
Firefox output: *** LOG addons.manager: Application has been upgraded\r\n*** LOG addons.xpi:
startup\r\n*** LOG addons.xpi: Skipping unavailable install location app-system-local\r\n***
LOG addons.xpi: Skipping unavailable install location app-system-share\r\n*** LOG addons.xpi:
checkForChanges\r\n*** LOG addons.xpi: Opening database\r\n*** ERROR addons.xpi: Error
during startup file checks, rolling back any database changes: [Exception... "Component
returned failure code: 0x80520015 (NS_ERROR_FILE_ACCESS_DENIED) [nsIPrefService.savePrefFile]"
 nsresult: "0x80520015 (NS_ERROR_FILE_ACCESS_DENIED)"  location: "JS frame :: resource:///modules/XPIProvider.jsm
:: XPIDB_openConnection :: line 4351"  data: no]\r\n*** ERROR addons.manager: Exception
calling provider startup: [Exception... "Component returned failure code: 0x80004005
(NS_ERROR_FAILURE) [mozIStorageStatement.execute]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"
 location: "JS frame :: resource:///modules/XPIProvider.jsm :: XPIDB_rollbackTransaction
:: line 4208"  data: no]\r\n' 

</error>


I traced this message to selenium\webdriver\firefox\firefox_binary.py  -> _wait_until_connectable()
 ->  utils.is_connectable(self.profile.port)  -> socket_.connect(("localhost", port)).
The execution is timing out because the it is not able to connect to a socket on the
local machine.

Making the profile files write-able (once they are copied into the new temp dir), in
the __init__ of selenium\webdriver\firefox\firefox_profile.py  fixes the error.:
        for profile_file in os.listdir(self.profile_dir):
            profile_file = os.path.join(self.profile_dir, profile_file)
            if not os.access(profile_file, os.W_OK):
                os.chmod(profile_file, shutil.stat.S_IWRITE)

The above code makes all files in the profile dir writeable. I am doing this even though
I know only prefs.js is causing the problem right now because I don't know what other
files will trigger the same exception.

Is there a cleaner way to handle this? ..  without altering our existing setup/workflow
- i.e. having the firefox profile (and hence the test framework) outside source control
or setting a flag in our source control system to keep the file as writable.

Is this a common enough scenario for this code to be checked into the main branch?
(I don't want to have the burden of maintaining this patch in our source control)

I am not even sure this is a selenium issue. It seems like it could be a firefox issue
as selenium copies the given profile files into a new dir and  launches firefox. Maybe
it is firefox that is rejecting a read-only prefs.js. But even in that case, if it
is decided that this is not a selenium issue and that we shouldn't be fixing this -
a nicer error message would be great (one that wouldn't have required me to spend ~2
days chasing this issue).

Reported by mohanraj.cit on 2012-07-10 17:12:26

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by luke.semerau on 2012-07-10 18:59:04

  • Labels added: Lang-Python, Component-WebDriver, Browser-Firefox
  • Labels removed: Status-Untriaged

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

I would recommend not storing the prefs file in a repository.

You can create profiles with http://selenium.googlecode.com/svn/trunk/docs/api/py/webdriver_firefox/selenium.webdriver.firefox.firefox_profile.html
and then pass it in as webdriver.Firefox(firefox_profile=profile)

or for passing it over the Grid you can use profile.encoded to the remote server.

The error message passed back is one that is passed back from Firefox and we dont touch
it in case there is something important in there.

Reported by david.burns@theautomatedtester.co.uk on 2012-07-10 19:16:41

  • Status changed: WorkingAsIntended

@lukeis
Copy link
Member Author

lukeis commented Mar 3, 2016

Reported by luke.semerau on 2015-09-17 18:15:46

  • Labels added: Restrict-AddIssueComment-Commit

@lukeis lukeis closed this as completed Mar 3, 2016
@SeleniumHQ SeleniumHQ locked and limited conversation to collaborators Mar 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant