changeset 3438:84fb41b515a1

tests (e2e/libervia/conftest): new `log_in_account1_s2` fixture
author Goffi <goffi@goffi.org>
date Fri, 04 Dec 2020 12:36:06 +0100
parents 42d6d00e4e8a
children b166a59b1724
files tests/e2e/libervia/conftest.py
diffstat 1 files changed, 17 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/tests/e2e/libervia/conftest.py	Fri Dec 04 12:35:00 2020 +0100
+++ b/tests/e2e/libervia/conftest.py	Fri Dec 04 12:36:06 2020 +0100
@@ -31,7 +31,7 @@
 BASE_URL = f"https://{LIBERVIA_HOST}:{LIBERVIA_PORT_HTTPS}"
 SIZE_DESKTOP = (1024, 728)
 SIZE_MOBILE = (380, 640)
-account_1_cookies = None
+accounts_cookies = {}
 
 
 @pytest.hookimpl(tryfirst=True, hookwrapper=True)
@@ -92,20 +92,26 @@
 def nobody_logged_in(browser):
     browser.get_driver().delete_all_cookies()
 
+def log_in(browser, account):
+    try:
+        account_cookies = accounts_cookies[account]
+    except KeyError:
+        browser.get_driver().delete_all_cookies()
+        browser.go_to("https://libervia.test:8443/login")
+        browser.write(account, into="login")
+        browser.write("test", into="password")
+        browser.click("log in")
+        accounts_cookies[account] = browser.get_driver().get_cookies()[0]
+    else:
+        browser.get_driver().add_cookie(account_cookies)
 
 @pytest.fixture
 def log_in_account1(browser):
-    global account_1_cookies
-    if account_1_cookies is None:
-        browser.get_driver().delete_all_cookies()
-        browser.go_to("https://libervia.test:8443/login")
-        browser.write("account1", into="login")
-        browser.write("test", into="password")
-        browser.click("log in")
-        account_1_cookies = browser.get_driver().get_cookies()
-    else:
-        browser.get_driver().add_cookie(account_1_cookies)
+    log_in(browser, "account1")
 
+@pytest.fixture
+def log_in_account1_s2(browser):
+    log_in(browser, "account1_s2")
 
 @pytest.fixture
 def mobile_screen(browser):