Skip to content

Get Cookies always Returns Empty List using the default Firefox profile #177

Closed

Description

@butterdave

Here's a simple test to run...hopefully I'm wrong!
Dependencies:

  • robotframework-selenium2library==1.1.0
  • firefox 19
  • robotframework==2.7.7

*** Settings ***
Resource Collections
Library Selenium2Library

*** Testcases ***
Test Browser Should Have Cookies
Open Browser http://www.google.com browser=firefox
${cookies}= Get Cookies
Should Not Be Empty ${cookies}

Activity

  1. emanlove commented on Mar 14, 2013

    @emanlove
    Member

    The default Firefox profile has several privacy settings, like browser.privatebrowsing.autostart, turned on so I wouldn't be surprised that the above test fails. I wouldn't expect any cookies. See the Open Browser keyword for more information about the Firefox profile.

  2. butterdave commented on Mar 14, 2013

    @butterdave
    Author

    hi, thanks for the reply, are you talking about a default FF profile that's packaged up with Selenium2Library or my own ff profile? If the former, was this setting changed recently? It works on ff 18 :(

    DP

  3. emanlove commented on Mar 14, 2013

    @emanlove
    Member

    Yes, I was talking about the default FF profile within the Selenium2Library. If it works for FF18 and not FF19 the problem might lie within Selenium and not the Selenium2library. You could try to confirm this by creating a selenium only test as outlined here.

    Sorry I am not much more helpful.

  4. emanlove commented on Mar 20, 2013

    @emanlove
    Member

    @butterdave For what it is worth our internal tests for cookies are currently failing under Firefox 19

  5. butterdave commented on Mar 20, 2013

    @butterdave
    Author

    thanks! i haven't had a chance to write the test to narrow who the guilty party may be. will let you know...also need to peruse the selenium issues list

  6. oscarh commented on Mar 17, 2014

    @oscarh

    Long time and no action, but for what it's worth. If the line:
    user_pref("browser.privatebrowsing.autostart", true);
    is changed to:
    user_pref("browser.privatebrowsing.autostart", false);
    in Selenium2Library/resources/firefoxprofile/prefs.js
    it works for me.

  7. Kristina001 commented on Jun 18, 2014

    @Kristina001

    Wierd, but Oscarhs solution doesn't work for me :(

    Can anybody told me is it an RF or Sel issue or no? So should we expect some new build fith fiz or just leave this and start looking for ... workaround except using coockies ?

  8. ombre42 commented on Jun 19, 2014

    @ombre42
    Contributor
    I think @oscarh is onto something. On ESR 24, with browser.privatebrowsing.autostart = true, cookies set with Add Cookie show up in Get Cookies, but other cookies do not. Here's a test that passes if private browsing autostart is false, but not when it is true:
        Open Browser    http://www.w3schools.com/js/js_cookies.asp    ff
        Click Button    Create Cookie 1    # this sets a simple, session-only cookie
        ${cookies}=    Get Cookies
        Should Contain    ${cookies}    firstname=John
    
  9. ombre42 commented on Jun 20, 2014

    @ombre42
    Contributor

    I noticed that even in the latest release of FF (29), the GCLI/Developer Toolbar (Shift+F2) has a command "cookie list" that will not show cookies that are visible via document.cookie when private browsing. I think the native interface that Selenium uses simply will not work during private browsing except to retrieve cookies set through that same cookie manager.

    I think we should stop using private browsing, but set the profile to behave close to it - not remembering forms, deleting history and cookies on exit, etc. Here are the settings I think we should put in place of user_pref("browser.privatebrowsing.autostart", true);.

    user_pref("places.history.enabled", false);
    user_pref("privacy.sanitize.sanitizeOnShutdown", true);
    user_pref("browser.formfill.enable", false);
    user_pref("network.cookie.lifetimePolicy", 2);
    user_pref("privacy.clearOnShutdown.offlineApps", true);
    user_pref("privacy.clearOnShutdown.passwords", true);
    user_pref("privacy.clearOnShutdown.siteSettings", true);
    
  10. aaltat commented on Jun 30, 2014

    @aaltat
    Contributor

    I have similar problem. I tweaked FF profile:
    user_pref("app.update.auto", false); user_pref("app.update.enabled", false); user_pref("browser.preferences.advanced.selectedTabIndex", 3); user_pref("browser.migration.version", 22); user_pref("browser.startup.homepage", "about:blank"); user_pref("browser.tabs.warnOnClose", false); user_pref("network.cookie.prefsMigrated", true); user_pref("privacy.sanitize.migrateFx3Prefs", true)

    And by this configuration I get the cookies. Could the S2L default profile be updated to allow the Get Cookie* keywords to work.

  11. changed the title [-]Get Cookies Returns Empty List for Firefox 19[/-] [+]Get Cookies always Returns Empty List using the default Firefox profile[/+] on Aug 29, 2014
  12. ombre42 commented on Oct 1, 2014

    @ombre42
    Contributor

    It looks like the capability to access the cookie manager used in private browsing via an API has not been implemented, so I am not going to bother the Selenium developers.
    See Mozilla bugs 823941 and 777620

  13. ombre42 commented on Oct 4, 2014

    @ombre42
    Contributor

    I am still working on a fix.

    I'm pretty sure my fix works but it is causing failures which are due to Get Cookies not working as described. It uses Selenium's get_cookies to fetch cookies which claims are 'of the current page' but it is not filtering. Chrome and Firefox (when not private browsing) return cookies set on the empty path (host?) as well. The same cookie set for /html is also setting it for /, so in Get Cookie's return value, it shows up twice.
    This is not an issue for Get Cookie. In Py and Java, it returns the first cookie with a matching name, and it appears that the cookie for the current page appears before the cookie for an empty path.
    All three things below are describing the exact same functionality:

    • Selenium Py doc for get_cookies: Returns a set of dictionaries, corresponding to cookies visible in the current session.
    • Selenium doc for GET /session/:sessionId/cookie: Retrieve all cookies visible to the current page.
    • Selenium Javadoc for getCookies(): Get all the cookies for the current domain. This is the equivalent of calling "document.cookie" and parsing the result

    Guess we aren't the only ones keeping the documentation consistent and correct :)

    I'm thinking of just changing the documentation for Get Cookies and adjusting the tests to handle the existing behavior.

    After executing

        Add Cookie  test    seleniumlibrary
        Add Cookie  another     value
    

    get_cookies is returning this for Chrome and FF (not private browsing):

        [{u'domain': u'localhost', u'name': u'test', u'value': u'seleniumlibrary', u'expiry': None, u'path': u'', u'secure': False}, 
        {u'domain': u'localhost', u'name': u'another', u'value': u'value', u'expiry': None, u'path': u'', u'secure': False}, 
        {u'domain': u'localhost', u'name': u'test', u'value': u'seleniumlibrary', u'expiry': None, u'path': u'/html/', u'secure': False}, 
        {u'domain': u'localhost', u'name': u'another', u'value': u'value', u'expiry': None, u'path': u'/html/', u'secure': False}]
    
  14. aaltat commented on Oct 4, 2014

    @aaltat
    Contributor

    I am OK with that. Specially if the documentation points to Mozilla doc/bug which explains that in the private browsing one can not access cookies and gives an example ff profile where private browsing is disabled.

  15. andreabisello commented on Jan 19, 2016

    @andreabisello

    can be for this reason that my website with "remember me" functionality that uses cookies will not work?

    i tried to modify

    c:\Python27\Lib\site-packages\Selenium2Library\resources\firefoxprofile\prefs.js

    adding @oscarh or @aaltat code but i still have the problem : cookies seems not to be stored so "remember me" doesn't works.

  16. aaltat commented on Jan 19, 2016

    @aaltat
    Contributor

    No. It is caused in the way selenium works. More details can be found from the answer, to your question, in the user group.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions