working do_login and __del__, check_in/out stubs.
This commit is contained in:
parent
1fed09c655
commit
f6c55655a2
|
@ -4,13 +4,14 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
import typing as T
|
import typing as T
|
||||||
|
|
||||||
os.environ['PATH'] = os.environ['PATH'] + \
|
os.environ['PATH'] = os.environ['PATH'] + \
|
||||||
':' + os.path.join(os.path.abspath(os.path.curdir), 'bin')
|
':' + os.path.join(os.path.abspath(os.path.curdir), 'bin')
|
||||||
|
|
||||||
from selenium import webdriver as wd
|
from selenium import webdriver as wd
|
||||||
from selenium.common.exceptions import WebDriverException
|
from selenium.common.exceptions import WebDriverException, NoSuchElementException
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
|
@ -76,8 +77,10 @@ class Operator(wd.Firefox):
|
||||||
Do the login and proceed.
|
Do the login and proceed.
|
||||||
"""
|
"""
|
||||||
# Retrieve login page
|
# 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)
|
self.logger.debug("After login get: %s", self.current_url)
|
||||||
|
time.sleep(3)
|
||||||
# Username
|
# Username
|
||||||
user_form = self.find_element_by_name('m_cUserName')
|
user_form = self.find_element_by_name('m_cUserName')
|
||||||
# Password
|
# Password
|
||||||
|
@ -96,10 +99,16 @@ class Operator(wd.Firefox):
|
||||||
login_butt.submit()
|
login_butt.submit()
|
||||||
self.logger.debug("After clicking: %s", self.current_url)
|
self.logger.debug("After clicking: %s", self.current_url)
|
||||||
self.logger.debug("Login result: %s", self.title)
|
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
|
# TODO: reckon a proper timeout mechanism
|
||||||
# based on cookie expire time
|
# based on cookie expire time
|
||||||
self._logged_in = True
|
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
|
@safely
|
||||||
def check_in(self, force: bool=False) -> None:
|
def check_in(self, force: bool=False) -> None:
|
||||||
|
@ -130,3 +139,6 @@ class Operator(wd.Firefox):
|
||||||
# Click the check in button and change
|
# Click the check in button and change
|
||||||
# self._checked_in state in case of success
|
# self._checked_in state in case of success
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
self.quit()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user