Repository: robotframework/SeleniumLibrary (python)

Issue:
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
Selenium [get_cookie](https://seleniumhq.github.io/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html?highlight=get_cookie#selenium.webdriver.remote.webdriver.WebDriver.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](https://github.com/robotframework/SeleniumLibrary/blob/master/src/SeleniumLibrary/keywords/cookie.py#L152) 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 ](https://w3c.github.io/webdriver/#dfn-table-for-cookie-conversion). 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. 

Pull request:
Allow extra arguments for CookieInformation
Fixes #1307 

Patch:
diff --git a/src/SeleniumLibrary/keywords/cookie.py b/src/SeleniumLibrary/keywords/cookie.py
index 1f85948f..493b83b0 100644
--- a/src/SeleniumLibrary/keywords/cookie.py
+++ b/src/SeleniumLibrary/keywords/cookie.py
@@ -90,14 +90,22 @@ class CookieKeywords(LibraryComponent):
         | secure        | When true, cookie is only used with HTTPS connections.     |
         | httpOnly      | When true, cookie is not accessible via JavaScript.        |
         | expiry        | Python datetime object indicating when the cookie expires. |
+        | extra         | Possible attributes outside of the WebDriver specification |
 
         See the
-        [https://w3c.github.io/webdriver/webdriver-spec.html#cookies|WebDriver specification]
+        [https://w3c.github.io/webdriver/#cookies|WebDriver specification]
         for details about the cookie information.
         Notice that ``expiry`` is specified as a
         [https://docs.python.org/3/library/datetime.html#datetime.datetime|datetime object],
         not as seconds since Unix Epoch like WebDriver natively does.
 
+        In some cases, example when running browser in the cloud, it is possible that
+        cookie contains other attributes than is defined in the
+        [https://w3c.github.io/webdriver/#cookies|WebDriver specification].
+        These other attributes are available in a ``extra`` attribute in the cookie
+        object and it contains a dictionary of the other attributes. The ``extra``
+        attribute is new in SeleniumLibrary 4.0.
+
         Example:
         | `Add Cookie`      | foo             | bar |
         | ${cookie} =       | `Get Cookie`    | foo |
@@ -152,7 +160,7 @@ class CookieKeywords(LibraryComponent):
 class CookieInformation(object):
 
     def __init__(self, name, value, path=None, domain=None, secure=False,
-                 httpOnly=False, expiry=None):
+                 httpOnly=False, expiry=None, **extra):
         self.name = name
         self.value = value
         self.path = path
@@ -160,8 +168,12 @@ class CookieInformation(object):
         self.secure = secure
         self.httpOnly = httpOnly
         self.expiry = datetime.fromtimestamp(expiry) if expiry else None
+        self.extra = extra
 
     def __str__(self):
         items = 'name value path domain secure httpOnly expiry'.split()
-        return '\n'.join('%s=%s' % (item, getattr(self, item))
-                         for item in items)
+        string = '\n'.join('%s=%s' % (item, getattr(self, item))
+                           for item in items)
+        if self.extra:
+            string = '%s%s=%s\n' % (string, 'extra', self.extra)
+        return string


Test patch:
diff --git a/utest/test/keywords/test_cookie.py b/utest/test/keywords/test_cookie.py
index c85caaf9..3e951135 100644
--- a/utest/test/keywords/test_cookie.py
+++ b/utest/test/keywords/test_cookie.py
@@ -1,8 +1,10 @@
+from datetime import datetime
 import unittest
 
 from mockito import mock, unstub, verify
 
 from SeleniumLibrary.keywords import CookieKeywords
+from SeleniumLibrary.keywords.cookie import CookieInformation
 
 
 class KeywordArgumentsCookieTest(unittest.TestCase):
@@ -72,3 +74,41 @@ class KeywordArgumentsCookieTest(unittest.TestCase):
         self.cookie.add_cookie('name', 'value', path='None', domain=None,
                                secure=None)
         verify(self.driver).add_cookie(self.default_cookie)
+
+
+class CookieObjecttest(unittest.TestCase):
+
+    all_args = {'name': 'foo', 'value': '123', 'path': '/', 'domain': 'not.Here',
+                'secure': True, 'httpOnly': True, 'expiry': 123}
+
+    def test_name_value_only(self):
+        cookie = CookieInformation(name='foo', value='bar')
+        self.assertEqual(cookie.name, 'foo')
+        self.assertEqual(cookie.value, 'bar')
+
+    def test_all_args(self):
+        cookie = CookieInformation(**self.all_args)
+        self.assertEqual(cookie.name, 'foo')
+        self.assertEqual(cookie.value, '123')
+        self.assertEqual(cookie.path, '/')
+        self.assertEqual(cookie.domain, 'not.Here')
+        self.assertEqual(cookie.secure, True)
+        self.assertEqual(cookie.httpOnly, True)
+        self.assertEqual(cookie.expiry, datetime.fromtimestamp(123))
+        self.assertEqual(cookie.extra, {})
+
+    def test_extra_args(self):
+        cookie_dict = self.all_args.copy()
+        cookie_dict['class_name'] = 'seleniumLibary'
+        cookie = CookieInformation(**cookie_dict)
+        self.assertEqual(cookie.name, 'foo')
+        self.assertEqual(cookie.value, '123')
+        self.assertEqual(cookie.extra, {'class_name': 'seleniumLibary'})
+        string = str(cookie)
+        self.assertIn("extra={'class_name': 'seleniumLibary'}", string)
+
+    def test_no_mandatory_args(self):
+        cookie_dict = self.all_args.copy()
+        del cookie_dict['name']
+        with self.assertRaises(TypeError):
+            CookieInformation(**cookie_dict)