Commit 1c846701 authored by Roque's avatar Roque Committed by Klaus Wölfel

testbrowser: regular expression to get cookie value

parent acf40150
...@@ -783,23 +783,25 @@ class MainForm(Form): ...@@ -783,23 +783,25 @@ class MainForm(Form):
(self.browser._username, self.browser._password)) (self.browser._username, self.browser._password))
def login(form): def login(form):
print "Login with user-pass: " + self.browser._username + " - " + self.browser._password
form.getControl(name='__ac_name').value = self.browser._username form.getControl(name='__ac_name').value = self.browser._username
form.getControl(name='__ac_password').value = self.browser._password form.getControl(name='__ac_password').value = self.browser._password
form.submit() form.submit()
def setCookies(): def setCookies():
"""
Gets the __ac value from the browser headers and sets it as cookie in order to keep
the user logged during the tests. If SimpleCookie can't parse the values,
regular expressions are used.
"""
headers_cookie = self.browser.headers['set-cookie'] headers_cookie = self.browser.headers['set-cookie']
cookie = Cookie.SimpleCookie() cookie = Cookie.SimpleCookie()
cookie.load(headers_cookie) cookie.load(headers_cookie)
if '__ac' in cookie.keys(): if '__ac' in cookie.keys():
ac_value = cookie['__ac'].value ac_value = cookie['__ac'].value
else: else:
for part in headers_cookie.split(","): reg = '__ac=\"([A-Za-z0-9%]+)*\"'
if '__ac=' in part: match = re.search(reg, headers_cookie)
for subpart in part.split(";"): ac_value = match.group(1) if match else None
if '__ac=' in subpart:
ac_value = subpart.split("=")[1].replace('"','')
self.browser.cookies["__ac"] = ac_value self.browser.cookies["__ac"] = ac_value
try: try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment