code: def set_cookie(self, key, value, expiration='Infinity', path='/', domain='', secure=False):
          
  
          secure = 'true' if secure else 'false'
          self.app_instance.execute_javascript("""
              var sKey = "%(sKey)s";
              var sValue = "%(sValue)s";
              var vEnd = eval("%(vEnd)s");
              var sPath = "%(sPath)s"; 
              var sDomain = "%(sDomain)s"; 
              var bSecure = %(bSecure)s;
              if( (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) == false ){
                  var sExpires = "";
                  if (vEnd) {
                      switch (vEnd.constructor) {
                          case Number:
                              sExpires = vEnd === Infinity ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + vEnd;
                          break;
                          case String:
                              sExpires = "; expires=" + vEnd;
                          break;
                          case Date:
                              sExpires = "; expires=" + vEnd.toUTCString();
                          break;
                      }
                  }
                  document.cookie = encodeURIComponent(sKey) + "=" + encodeURIComponent(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : "");
              }
              """%{'sKey': key, 'sValue': value, 'vEnd': expiration, 'sPath': path, 'sDomain': domain, 'bSecure': secure})
docs: expiration (int): seconds after with the cookie automatically gets deleted