Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Cookies keyword will fail if the Selenium get_cookie method return value contains more keys than: name, value, path, domain, secure, httpOnly and expiry #1307

Closed
aaltat opened this issue Feb 12, 2019 · 5 comments

Comments

@aaltat
Copy link
Contributor

aaltat commented Feb 12, 2019

Selenium get_cookie returns a dictionary. If the dictionary contains more keys then the name, value, path, domain, secure, httpOnly and expiry, then the Get Cookies keyword will fail:

20190212 16:54:43.113 :  FAIL : TypeError: __init__() got an unexpected keyword argument 'hCode'
20190212 16:54:43.113 : DEBUG :
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\SeleniumLibrary\__init__.py", line 369, in run_keyword
    return DynamicCore.run_keyword(self, name, args, kwargs)
  File "C:\Python27\lib\site-packages\SeleniumLibrary\base\robotlibcore.py", line 102, in run_keyword
    return self.keywords[name](*args, **kwargs)
  File "C:\Python27\lib\site-packages\SeleniumLibrary\keywords\cookie.py", line 99, in get_cookie
    return CookieInformation(**cookie)

This is because the Get Cookies keywords has hard coded keys what Selenium response can contain in the CookieInformation object. The limitation has been in place since the SeleniumLibrary 3.0 release, but there was issue reported in Slack, that for that particular user, Selenium get_cookie did return the following:

{u'domain': u'1.2.3.4', u'name': u'components_state', u'value': u'alsdjaslkdjasdlkj', u'path': u'/', u'hCode': -1693023704, u'class': u'org.openqa.selenium.Cookie', u'httpOnly': False, u'secure': False}

SeleniumLibrary should not fail, if the Selenium get_cookie returns more keys that is specified . Instead we should allow extra keys to be passed to the CookieInformation object and allow access to the extra keys in similar way as the specified keys.

@aaltat aaltat added this to the v.4.0.0 milestone Feb 12, 2019
@vyvital
Copy link

vyvital commented Feb 13, 2019

Found more about 'hCode' and 'class' here nightwatchjs/nightwatch#470 and SeleniumHQ/selenium-google-code-issue-archive#1227
I noticed when im using my browser trying to reach google.com it returns :
{u'domain': u'.google.com', u'secure': False, u'value': u'158=Q_smyAojkcCcMosB0O-z8SB6SZfYsJj8QQu9CV5R2CejUPUaBdVbndAvRi0tNAZActD_tdPs_McMnuuKJ6QCE8n3Xt8fP8EeRKe3SpbA7ghZYKA5u3wmtFHSOpYgS-MP11W4lA5EvG3NqTWTl3jXVtl-s4Rj71KbrfbZ4qeVX6s', u'expiry': 1565866084.894618, u'path': u'/', u'httpOnly': True, u'name': u'NID'}

But when using a remote connection such as Browserstack service I get
{u'domain': u'.google.com', u'name': u'NID', u'value': u'158=e2cyaJdHpNrgWpildw2PFvy0Oa4jxdv4axq8_HUw5PMBlU7-cnllxdS6u9BcfnCC7BBBtCMzIcp6zctnb5g0QRBK4bHgrnIwCdrw7-fxCqW2dyvOCgMeRhFEoMP9ItGA0i2e-xP-B1kcYWSAXct_Nlvnac6m6JrPQu_ilKgXkC4', u'expiry': 1565866484, u'path': u'/', u'hCode': 77289, u'class': u'org.openqa.selenium.Cookie', u'httpOnly': True, u'secure': False}

@aaltat
Copy link
Contributor Author

aaltat commented Feb 13, 2019

So BrowserStack adds some attributes to the cookie, interesting. No idea why it's done, but I guess they have their reasons. In any case, it's not hard to fix, would you @vyvital be interested providing a pull request?

@aaltat
Copy link
Contributor Author

aaltat commented Feb 16, 2019

@vyvital this issue should be fixed. Could you install from master and give it a try?

@vyvital
Copy link

vyvital commented Feb 17, 2019

Log returns:

value=160=QBIeJlxJ5aeZj8ql2eODrDSVR74YlHT_5hkY190L42rcpcGHzVBuULZkl5Yazx4pT95N8sAhkvSkdNrVV2kn9b9M6K0LF9cp_TQPD5UDKvbMQEShKxqWRSjJD7K5HHANk5_LqMhb5GyBIudD3BSjmppU_qcKtgs_cCMWM9ltYUs
path=/
domain=.google.com
secure=False
httpOnly=True
expiry=2019-08-19 10:54:11extra={u'hCode': 77289, u'class': u'org.openqa.selenium.Cookie'}

So maybe a new line between expiry and extra?
Managed to access it with C['hCode'] successfully

Thank you very much

@aaltat
Copy link
Contributor Author

aaltat commented Feb 17, 2019

Ah, very good point, will make the changes.

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

No branches or pull requests

2 participants