clean up
This commit is contained in:
parent
5cf90558c0
commit
b2890216dc
@ -6,6 +6,7 @@ working_directory = ./tmp
|
|||||||
tenant_id =
|
tenant_id =
|
||||||
app_url = https://app.flightschedulepro.com
|
app_url = https://app.flightschedulepro.com
|
||||||
timeout = 10
|
timeout = 10
|
||||||
|
use_working_dir_for_tmp = false
|
||||||
|
|
||||||
|
|
||||||
[firefox]
|
[firefox]
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from selenium.webdriver.support.ui import WebDriverWait
|
from selenium.webdriver.support.ui import WebDriverWait
|
||||||
|
from selenium.common.exceptions import TimeoutException
|
||||||
from selenium.webdriver.support import expected_conditions as EC
|
from selenium.webdriver.support import expected_conditions as EC
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
from selenium.webdriver.common.print_page_options import PrintOptions
|
from selenium.webdriver.common.print_page_options import PrintOptions
|
||||||
@ -45,6 +46,10 @@ config.read(args.config)
|
|||||||
working_dir = config['main'].get('working_directory', DEFAULT_WORKING_DIRECTORY)
|
working_dir = config['main'].get('working_directory', DEFAULT_WORKING_DIRECTORY)
|
||||||
app_url = config['main'].get('app_url', DEFAULT_APP_URL)
|
app_url = config['main'].get('app_url', DEFAULT_APP_URL)
|
||||||
timeout = config['main'].get('timeout', DEFAULT_TIMEOUT)
|
timeout = config['main'].get('timeout', DEFAULT_TIMEOUT)
|
||||||
|
tenant_id = config['main'].get('tenant_id')
|
||||||
|
if tenant_id is None or tenant_id == "":
|
||||||
|
print('No Tenant ID configured!')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.makedirs(working_dir)
|
os.makedirs(working_dir)
|
||||||
@ -56,7 +61,8 @@ except OSError as exception:
|
|||||||
os.remove(f)
|
os.remove(f)
|
||||||
|
|
||||||
# HACK maybe Ubuntu specific
|
# HACK maybe Ubuntu specific
|
||||||
os.environ["TMPDIR"] = working_dir
|
if config['main'].getboolean('use_working_dir_for_tmp', False):
|
||||||
|
os.environ["TMPDIR"] = working_dir
|
||||||
|
|
||||||
driver_type = config['main']['driver']
|
driver_type = config['main']['driver']
|
||||||
# TODO only firefox for now
|
# TODO only firefox for now
|
||||||
@ -79,10 +85,10 @@ else:
|
|||||||
def die(message=None):
|
def die(message=None):
|
||||||
if message is not None:
|
if message is not None:
|
||||||
print(message)
|
print(message)
|
||||||
driver.close()
|
driver.quit()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
login_url = app_url + '/Account/Login?company='+ config['main']['tenant_id']
|
login_url = app_url + '/Account/Login?company='+ tenant_id
|
||||||
driver.get(login_url)
|
driver.get(login_url)
|
||||||
|
|
||||||
# wait for stupid cookie modal to load and accept all ¯\_(ツ)_/¯
|
# wait for stupid cookie modal to load and accept all ¯\_(ツ)_/¯
|
||||||
@ -101,18 +107,30 @@ username = driver.find_element(By.ID, 'username')
|
|||||||
username.send_keys(config['main']['username'])
|
username.send_keys(config['main']['username'])
|
||||||
username.submit()
|
username.submit()
|
||||||
|
|
||||||
WebDriverWait(driver, timeout).until(
|
try:
|
||||||
EC.presence_of_all_elements_located((By.ID, 'password'))
|
WebDriverWait(driver, timeout).until(
|
||||||
)
|
EC.presence_of_all_elements_located((By.ID, 'password'))
|
||||||
|
)
|
||||||
|
except TimeoutException:
|
||||||
|
if len(driver.find_elements(By.XPATH, '//div[@id="alerts"]')) > 0:
|
||||||
|
die('Bad username')
|
||||||
|
die('unknown authentication error')
|
||||||
|
|
||||||
password = driver.find_element(By.ID, 'password')
|
password = driver.find_element(By.ID, 'password')
|
||||||
password.send_keys(config['main']['password'])
|
password.send_keys(config['main']['password'])
|
||||||
|
|
||||||
password.submit()
|
password.submit()
|
||||||
|
|
||||||
# Wait for app to load and naviagte to students "page"
|
# Wait for app to load and naviagte to students "page"
|
||||||
WebDriverWait(driver, timeout).until(
|
try:
|
||||||
EC.presence_of_all_elements_located((By.CLASS_NAME, 'fsp-main-drawer-content'))
|
WebDriverWait(driver, timeout).until(
|
||||||
)
|
EC.presence_of_all_elements_located((By.CLASS_NAME, 'fsp-main-drawer-content'))
|
||||||
|
)
|
||||||
|
except TimeoutException:
|
||||||
|
if len(driver.find_elements(By.XPATH, '//div[@id="alerts"]')) > 0:
|
||||||
|
die('Bad password')
|
||||||
|
die('unknown authentication error')
|
||||||
|
|
||||||
def get_student_rows():
|
def get_student_rows():
|
||||||
driver.get(app_url + '/App/Students')
|
driver.get(app_url + '/App/Students')
|
||||||
WebDriverWait(driver, timeout).until(
|
WebDriverWait(driver, timeout).until(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user