[IMP] tests: delete session cookie after each test
During an HttpCase, when a browser_js test is finished, cookies are removed to ensure that the next call will start on a clean base. From time to times, when an HttpCase have multiple tests methods that call browser_js, the user session of the previous test is being used. With this commit, the session cookie is explicitely deleted and should prevent that kind of problem. By the way, the browser's cache is also cleared.
This commit is contained in:
@@ -776,6 +776,12 @@ class ChromeBrowser():
|
||||
_id = self._websocket_send('Network.setCookie', params=params)
|
||||
return self._websocket_wait_id(_id)
|
||||
|
||||
def delete_cookie(self, name, **kwargs):
|
||||
params = {kw:kwargs[kw] for kw in kwargs if kw in ['url', 'domain', 'path']}
|
||||
params.update({'name': name})
|
||||
_id = self._websocket_send('Network.deleteCookies', params=params)
|
||||
return self._websocket_wait_id(_id)
|
||||
|
||||
def _wait_ready(self, ready_code, timeout=60):
|
||||
self._logger.info('Evaluate ready code "%s"', ready_code)
|
||||
awaited_result = {'result': {'type': 'boolean', 'value': True}}
|
||||
@@ -872,6 +878,8 @@ class ChromeBrowser():
|
||||
self.screencast_frames = []
|
||||
self._websocket_send('Page.stopLoading')
|
||||
self._logger.info('Deleting cookies and clearing local storage')
|
||||
dc_id = self._websocket_send('Network.clearBrowserCache')
|
||||
self._websocket_wait_id(dc_id)
|
||||
dc_id = self._websocket_send('Network.clearBrowserCookies')
|
||||
self._websocket_wait_id(dc_id)
|
||||
cl_id = self._websocket_send('Runtime.evaluate', params={'expression': 'localStorage.clear()'})
|
||||
@@ -1037,6 +1045,7 @@ class HttpCase(TransactionCase):
|
||||
finally:
|
||||
# clear browser to make it stop sending requests, in case we call
|
||||
# the method several times in a test method
|
||||
self.browser.delete_cookie('session_id', domain=HOST)
|
||||
self.browser.clear()
|
||||
self._wait_remaining_requests()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user