You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.1 KiB
Python
80 lines
2.1 KiB
Python
#!/usr/local/monitoring/bin/python
|
|
|
|
import calendar, time, sys
|
|
sys.path.insert (1, '/usr/local/monitoring/princeton/lib')
|
|
from puselenium import init_selenium
|
|
|
|
from selenium import webdriver
|
|
from selenium.webdriver.support.ui import WebDriverWait
|
|
from selenium.webdriver.common.by import By
|
|
from selenium.webdriver.support import expected_conditions as EC
|
|
from selenium.common import exceptions as EXCEP
|
|
from random import sample
|
|
|
|
if len (sys.argv) != 4:
|
|
print "Usage: %s <URL> <username> <password>" % sys.argv[0]
|
|
sys.exit (3)
|
|
|
|
url = sys.argv[1]
|
|
usr = sys.argv[2]
|
|
usrpass = sys.argv[3]
|
|
|
|
ff, fp = init_selenium()
|
|
|
|
try:
|
|
ff.implicitly_wait (10)
|
|
ff.get (url)
|
|
|
|
#WebDriverWait (ff, 10).until (EC.title_contains("Sign On"))
|
|
|
|
uid = ff.find_element_by_id ("userid")
|
|
uid.send_keys (usr)
|
|
uid.submit()
|
|
|
|
#WebDriverWait (ff, 10).until (EC.presence_of_element_located((By.ID, "Bharosa_Password_PadDataField")))
|
|
|
|
pupass = ff.find_element_by_id ("Bharosa_Password_PadDataField")
|
|
pupass.send_keys (usrpass)
|
|
pupass.submit()
|
|
|
|
#WebDriverWait (ff, 10).until (EC.presence_of_element_located((By.XPATH, "//a[text()='Log out']")))
|
|
|
|
logout1 = ff.find_element_by_xpath ("//a[text()='Log out']")
|
|
logout1.click()
|
|
|
|
#WebDriverWait (ff, 10).until (EC.presence_of_element_located((By.XPATH, "//input[@value='LOG OFF']")))
|
|
|
|
logout2 = ff.find_element_by_xpath ("//input[@value='LOG OFF']")
|
|
logout2.click()
|
|
|
|
WebDriverWait (ff, 10).until (EC.title_contains("Single Sign-Off"))
|
|
|
|
time.sleep(5)
|
|
|
|
except EXCEP.ErrorInResponseException, (resp, msg):
|
|
|
|
print "ERROR: An error occured communicating with the browser server: Response: %s; Message: %s" % (resp, msg)
|
|
sys.exit (1)
|
|
|
|
except EXCEP.NoSuchElementException, msg:
|
|
|
|
print "ERROR: Unable to locate webpage element. Probably the page loaded incompletely or incorrectly: %s" % msg
|
|
sys.exit (1)
|
|
|
|
except EXCEP.TimeoutException, msg:
|
|
|
|
print "ERROR: Request timed out. Network??? Response: %s" % msg
|
|
sys.exit (1)
|
|
|
|
except EXCEP.WebDriverException, msg:
|
|
|
|
print "ERROR: I don't know what happened. Read this - %s" % msg
|
|
sys.exit (1)
|
|
|
|
finally:
|
|
ff.quit()
|
|
|
|
print "Successfully logged on to PUAccess and logged off"
|
|
|
|
sys.exit (0)
|