Commit d0e97a5a authored by Georges Racinet's avatar Georges Racinet 🌳
Browse files

User: removed login() method in favor of webdriver property

It was just there as a refactoring step, and had the
drawback to depend on the `_webdriver` attribute not to be None,
which is an implementation detail.

All callers should use the `webdriver` property.
parent 6d0c5253aacc
......@@ -107,23 +107,6 @@ class User(object):
def store_in_heptapod(self):
self.heptapod.users[self.name] = self
def login(self):
"""Perform the webdriver login sequence if not already done.
Assumes :attr:`_webdriver` not to be None
"""
heptapod, driver, name = self.heptapod, self._webdriver, self.name
if name == 'root':
login_as_root(driver, heptapod, self.password)
else:
start = time.time()
webdriver_wait_get(heptapod, driver, relative_uri='/users/sign_in')
sign_in_page_login(driver, heptapod, self.name,
password=self.password)
logger.info("Signed in user %s in %.2f seconds",
self.name, time.time() - start)
return driver
@property
def webdriver(self):
"""Selenium webdriver, authentified as self.
......@@ -136,8 +119,19 @@ class User(object):
self.name)
# guaranteeing driver to be available for teardown as soon as created
self._webdriver = self.heptapod.new_webdriver()
return self.login()
driver = self._webdriver = self.heptapod.new_webdriver()
heptapod = self.heptapod
if self.name == 'root':
login_as_root(driver, heptapod, self.password)
else:
start = time.time()
webdriver_wait_get(heptapod, driver, relative_uri='/users/sign_in')
sign_in_page_login(driver, heptapod, self.name,
password=self.password)
logger.info("Signed in user %s in %.2f seconds",
self.name, time.time() - start)
return driver
def close_webdriver(self):
"""Close current web driver if there is one."""
......
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