working do_login and __del__, check_in/out stubs.

Leonardo Barcaroli 2019-01-13 00:04:02 +01:00
parent 5822d62f0d
commit 9c2599d954
1 changed files with 15 additions and 3 deletions

View File

@ -4,13 +4,14 @@
import logging
import os
import time
import typing as T
os.environ['PATH'] = os.environ['PATH'] + \
':' + os.path.join(os.path.abspath(os.path.curdir), 'bin')
from selenium import webdriver as wd
from selenium.common.exceptions import WebDriverException
from selenium.common.exceptions import WebDriverException, NoSuchElementException
logging.basicConfig(
@ -76,8 +77,10 @@ class Operator(wd.Firefox):
Do the login and proceed.
"""
# Retrieve login page
self.get('{}/jsp/login.jsp'.format(self.base_uri))
#self.get('{}/jsp/login.jsp'.format(self.base_uri))
self.get(self.base_uri)
self.logger.debug("After login get: %s", self.current_url)
time.sleep(3)
# Username
user_form = self.find_element_by_name('m_cUserName')
# Password
@ -96,10 +99,16 @@ class Operator(wd.Firefox):
login_butt.submit()
self.logger.debug("After clicking: %s", self.current_url)
self.logger.debug("Login result: %s", self.title)
if '404' not in self.title:
if 'Routine window' in self.title:
self.refresh()
try:
self.find_element_by_xpath('//input[contains(@value, "Accedi")]')
# TODO: reckon a proper timeout mechanism
# based on cookie expire time
self._logged_in = True
self.logger.info("Login success for user: %s", user)
except NoSuchElementException as e:
self.logger.error("Login failed: %s", e)
@safely
def check_in(self, force: bool=False) -> None:
@ -130,3 +139,6 @@ class Operator(wd.Firefox):
# Click the check in button and change
# self._checked_in state in case of success
pass
def __del__(self):
self.quit()