<s> '''<STR_LIT>''' <EOL> from eucaops import Eucaops <EOL> from selenium import webdriver <EOL> from selenium . webdriver . firefox . firefox_profile import FirefoxProfile <EOL> from selenium . common . exceptions import NoSuchElementException <EOL> import unittest , time , re , os , signal , commands <EOL> from subprocess import call <EOL> import euwebglobals , euwebaccount , euwebuser <EOL> import eulogger <EOL> class Eucaweb ( unittest . TestCase ) : <EOL> def __init__ ( self , host = "<STR_LIT:localhost>" , <EOL> browser = "<STR_LIT>" , <EOL> clc = "<STR_LIT>" , <EOL> user = "<STR_LIT>" , <EOL> account = "<STR_LIT>" , <EOL> adminpasswd = "<STR_LIT>" , <EOL> clcpasswd = "<STR_LIT>" , <EOL> needEucaops = True , <EOL> downloadPath = "<STR_LIT>" , <EOL> configFile = "<STR_LIT>" ) : <EOL> self . images = [ ] <EOL> self . loggedIn = False <EOL> self . host = host <EOL> self . browser = str ( browser ) . upper ( ) <EOL> self . clc = clc <EOL> self . clcpasswd = clcpasswd <EOL> self . clcurl = "<STR_LIT>" + clc + "<STR_LIT>" <EOL> self . user = user <EOL> self . account = account <EOL> self . passwd = adminpasswd <EOL> self . defTimeout = <NUM_LIT:10> <EOL> self . configFile = configFile <EOL> self . needEucaops = needEucaops <EOL> self . errs = [ ] <EOL> self . downloadPath = downloadPath <EOL> if ( re . search ( '<STR_LIT>' , self . downloadPath ) ) : <EOL> self . downloadPath = self . downloadPath . rstrip ( '<STR_LIT:/>' ) <EOL> self . wg = euwebglobals . Webui_globals ( ) <EOL> self . setUp ( ) <EOL> def setUp ( self ) : <EOL> try : <EOL> self . logger = eulogger . Eulogger ( name = '<STR_LIT>' ) <EOL> self . log = self . logger . log <EOL> self . printSelf ( ) <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> self . errs = [ ] <EOL> self . startDriver ( ) <EOL> if ( self . configFile == "<STR_LIT>" ) : <EOL> fpath = str ( os . path . abspath ( __file__ ) ) <EOL> thisfile = re . search ( '<STR_LIT>' , fpath ) . group ( <NUM_LIT:0> ) <EOL> fpath = str ( os . path . abspath ( __file__ ) ) . replace ( thisfile , "<STR_LIT>" ) <EOL> self . configFile = str ( fpath ) + "<STR_LIT>" <EOL> self . printSelf ( ) <EOL> if ( self . needEucaops ) : <EOL> try : <EOL> retcode = call ( '<STR_LIT>' , shell = True ) <EOL> print "<STR_LIT>" + str ( retcode ) <EOL> except Exception , e : <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> pass <EOL> try : <EOL> self . eutester = Eucaops ( hostname = "<STR_LIT>" , password = self . clcpasswd , config_file = self . configFile ) <EOL> except Exception , ute : <EOL> self . log . critical ( "<STR_LIT>" + str ( ute ) ) <EOL> raise ute <EOL> if ( self . clc == "<STR_LIT>" ) : <EOL> self . clc = self . eutester . get_clc_ip ( ) <EOL> self . clcurl = "<STR_LIT>" + self . clc + "<STR_LIT>" <EOL> self . driver . implicitly_wait ( <NUM_LIT:10> ) <EOL> self . base_url = self . clcurl <EOL> bname = self . driver . name <EOL> self . log . debug ( "<STR_LIT>" + str ( bname ) ) <EOL> except Exception , e : <EOL> self . log . critical ( "<STR_LIT>" + str ( e ) ) <EOL> self . tearDown ( <NUM_LIT:0> ) <EOL> raise e <EOL> def startDriver ( self ) : <EOL> try : <EOL> self . log . critical ( "<STR_LIT>" ) <EOL> if ( self . browser == "<STR_LIT>" ) : <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> ffprof = FirefoxProfile ( ) <EOL> ffprof . set_preference ( "<STR_LIT>" , <NUM_LIT:2> ) <EOL> ffprof . set_preference ( "<STR_LIT>" , self . downloadPath ) <EOL> ffprof . set_preference ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> ffprof . set_preference ( "<STR_LIT>" , "<STR_LIT:false>" ) <EOL> self . driver = webdriver . Firefox ( ffprof ) <EOL> elif ( self . browser == "<STR_LIT>" ) : <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> self . driver = webdriver . Chrome ( ) <EOL> elif ( self . browser == "<STR_LIT>" ) : <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> self . driver = webdriver . Ie ( ) <EOL> else : <EOL> self . driver = webdriver . Firefox ( ) <EOL> except Exception , de : <EOL> self . log . critical ( "<STR_LIT>" + str ( de ) ) <EOL> raise de <EOL> def printSelf ( self ) : <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> self . log . debug ( "<STR_LIT>" + str ( self . configFile ) ) <EOL> self . log . debug ( "<STR_LIT>" + str ( self . host ) ) <EOL> self . log . debug ( "<STR_LIT>" + str ( self . browser ) ) <EOL> self . log . debug ( "<STR_LIT>" + str ( self . clc ) ) <EOL> self . log . debug ( "<STR_LIT>" + str ( self . clcpasswd ) ) <EOL> self . log . debug ( "<STR_LIT>" + str ( self . user ) ) <EOL> self . log . debug ( "<STR_LIT>" + str ( self . account ) ) <EOL> self . log . debug ( "<STR_LIT>" + str ( self . passwd ) ) <EOL> self . log . debug ( "<STR_LIT>" + str ( self . needEucaops ) ) <EOL> self . log . debug ( "<STR_LIT>" + self . wg . xUserLink ) <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> def waitForText ( self , xpath , text , retry ) : <EOL> '''<STR_LIT>''' <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + str ( text ) + "<STR_LIT>" ) ) <EOL> driver = self . driver <EOL> for i in range ( retry ) : <EOL> self . log . debug ( "<STR_LIT>" + str ( i ) ) <EOL> try : <EOL> cmd = xpath + "<STR_LIT>" + text + "<STR_LIT>" <EOL> self . log . debug ( "<STR_LIT>" + text + "<STR_LIT>" + xpath ) <EOL> driver . find_element_by_xpath ( cmd ) <EOL> self . log . debug ( "<STR_LIT>" + text + "<STR_LIT>" + str ( i ) + "<STR_LIT>" ) <EOL> return <EOL> break <EOL> except Exception , e : <EOL> self . log . critical ( "<STR_LIT>" + str ( i ) + "<STR_LIT::>" + str ( e ) ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> pass <EOL> self . log . critical ( "<STR_LIT>" + text + "<STR_LIT>" + str ( retry ) + "<STR_LIT>" + xpath + "<STR_LIT:)>" ) <EOL> raise Exception ( "<STR_LIT>" + text + "<STR_LIT:)>" ) <EOL> def goLoginPage ( self ) : <EOL> self . log . debug ( self . hd ( "<STR_LIT>" ) ) <EOL> driver = self . driver <EOL> driver . get ( self . clcurl ) <EOL> try : <EOL> self . waitForTextOnPage ( "<STR_LIT>" ) <EOL> except Exception , e : <EOL> self . log . critical ( "<STR_LIT>" + str ( e ) ) <EOL> def get ( self , url ) : <EOL> return self . driver . get ( url ) <EOL> def getElmByText ( self , xpath , text ) : <EOL> '''<STR_LIT>''' <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + str ( text ) ) ) <EOL> driver = self . driver <EOL> cmd = xpath + "<STR_LIT>" + text + "<STR_LIT>" <EOL> self . log . debug ( "<STR_LIT>" + xpath ) <EOL> elm = driver . find_element_by_xpath ( cmd ) <EOL> self . log . debug ( "<STR_LIT>" + text + "<STR_LIT:)>" ) <EOL> return elm <EOL> def hd ( self , msg ) : <EOL> '''<STR_LIT>''' <EOL> myHdr = "<STR_LIT>" + msg + "<STR_LIT>" <EOL> '''<STR_LIT>''' <EOL> return myHdr <EOL> def login ( self , account , user , passwd ) : <EOL> '''<STR_LIT>''' <EOL> account = str ( account ) <EOL> user = str ( user ) <EOL> passwd = str ( passwd ) <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + account + "<STR_LIT>" + user + "<STR_LIT>" + passwd + "<STR_LIT:)>" ) ) <EOL> driver = self . driver <EOL> driver . get ( self . clcurl ) <EOL> driver . find_element_by_id ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_id ( "<STR_LIT>" ) . send_keys ( str ( account ) ) <EOL> driver . find_element_by_id ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_id ( "<STR_LIT>" ) . send_keys ( str ( user ) ) <EOL> driver . find_element_by_id ( "<STR_LIT:password>" ) . clear ( ) <EOL> driver . find_element_by_id ( "<STR_LIT:password>" ) . send_keys ( str ( passwd ) ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . click ( ) <EOL> try : <EOL> self . waitForTextOnPage ( user + '<STR_LIT:@>' + account , <NUM_LIT:3> ) <EOL> self . log . debug ( "<STR_LIT>" + str ( user ) + "<STR_LIT>" + account + "<STR_LIT>" ) <EOL> except Exception , e : <EOL> self . log . critical ( "<STR_LIT>" + account + "<STR_LIT>" + user + "<STR_LIT>" + passwd + "<STR_LIT:)>" ) <EOL> raise e <EOL> def waitForTextOnPage ( self , searchtext , retry = <NUM_LIT:1> ) : <EOL> '''<STR_LIT>''' <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + str ( searchtext ) + "<STR_LIT:)>" ) ) <EOL> xpath = '<STR_LIT>' <EOL> try : <EOL> self . waitForText ( xpath , searchtext , <NUM_LIT:1> ) <EOL> self . log . debug ( "<STR_LIT>" + str ( searchtext ) ) <EOL> except Exception , e : <EOL> self . log . debug ( "<STR_LIT>" + searchtext + "<STR_LIT>" ) <EOL> raise e <EOL> def verifyUserLinkPresent ( self , username , accountname ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> ltext = username + '<STR_LIT:@>' + accountname <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + ltext + "<STR_LIT>" ) ) <EOL> webelm = self . getUserLink ( ) <EOL> self . log . debug ( "<STR_LIT>" + webelm . text ) <EOL> if ( webelm . text == ltext ) : <EOL> self . log . debug ( "<STR_LIT>" + ltext + "<STR_LIT>" + webelm . text ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" + ltext + "<STR_LIT>" + webelm . text ) <EOL> except Exception , e : <EOL> self . log . critical ( "<STR_LIT>" + str ( e ) ) <EOL> def getUserLink ( self , linkstring = "<STR_LIT>" ) : <EOL> '''<STR_LIT>''' <EOL> self . log . debug ( self . hd ( "<STR_LIT>" ) ) <EOL> driver = self . driver <EOL> try : <EOL> if ( linkstring == "<STR_LIT>" ) : <EOL> elm = driver . find_element_by_xpath ( self . wg . xUserLink ) <EOL> else : <EOL> elm = driver . find_element_by_link_text ( linkstring ) <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> return elm <EOL> except Exception , e : <EOL> self . log . critical ( "<STR_LIT>" ) <EOL> raise e <EOL> def downloadCredentials ( self , username , accountname , timeout = <NUM_LIT> , force = False , callBackMethod = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> driver = self . driver <EOL> self . getUserLink ( ) . click ( ) <EOL> retcode = <NUM_LIT:0> <EOL> waitforlock = timeout <EOL> mypid = str ( os . getpid ( ) ) <EOL> mylockfile = self . downloadPath + '<STR_LIT>' + str ( mypid ) <EOL> while ( ( retcode == <NUM_LIT:0> ) and ( waitforlock > <NUM_LIT:0> ) ) : <EOL> retcode = call ( '<STR_LIT>' + self . downloadPath + '<STR_LIT>' , shell = True ) <EOL> if ( retcode == <NUM_LIT:0> ) : <EOL> self . log . debug ( "<STR_LIT>" + str ( waitforlock ) ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> waitforlock -= <NUM_LIT:1> <EOL> if ( retcode == <NUM_LIT:0> ) : <EOL> if ( force ) : <EOL> self . log . critical ( "<STR_LIT>" + str ( timeout ) + "<STR_LIT>" ) <EOL> cmd = '<STR_LIT>' + self . downloadPath + '<STR_LIT>' <EOL> self . log . critical ( "<STR_LIT>" + cmd ) <EOL> call ( cmd , shell = True ) <EOL> retcode = call ( '<STR_LIT>' + self . downloadPath + '<STR_LIT>' , shell = True ) <EOL> if ( retcode == <NUM_LIT:0> ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" + self . downloadPath + "<STR_LIT>" + str ( timeout ) + "<STR_LIT>" ) <EOL> call ( "<STR_LIT>" + mylockfile , shell = True ) <EOL> call ( "<STR_LIT>" + self . downloadPath + "<STR_LIT>" , shell = True ) <EOL> driver . find_element_by_link_text ( "<STR_LIT>" ) . click ( ) <EOL> downloaded = <NUM_LIT:1> <EOL> waitforfile = timeout <EOL> while ( ( downloaded == <NUM_LIT:1> ) and ( waitforfile > <NUM_LIT:0> ) ) : <EOL> downloaded = call ( '<STR_LIT>' + self . downloadPath + '<STR_LIT>' , shell = True ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> waitforfile -= <NUM_LIT:1> <EOL> if ( downloaded == <NUM_LIT:1> ) : <EOL> raise Exception ( "<STR_LIT>" + self . downloadPath + "<STR_LIT>" + str ( waitforfile ) ) <EOL> filelist = os . listdir ( self . downloadPath + "<STR_LIT:/>" ) <EOL> credfile = "<STR_LIT>" <EOL> for f in filelist : <EOL> if ( re . search ( '<STR_LIT>' , f ) ) : <EOL> credfile = self . downloadPath + "<STR_LIT:/>" + f <EOL> self . log . debug ( "<STR_LIT>" + str ( credfile ) ) <EOL> if ( credfile == "<STR_LIT>" ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> try : <EOL> if ( callBackMethod is not None ) : <EOL> callBackMethod ( credfile ) <EOL> except Exception , cbe : <EOL> raise Exception ( "<STR_LIT>" + str ( callBackMethod . __name__ ) + "<STR_LIT>" + str ( cbe ) ) <EOL> except Exception , e : <EOL> self . log . debug ( "<STR_LIT>" + str ( e ) ) <EOL> finally : <EOL> try : <EOL> self . log . debug ( "<STR_LIT>" + credfile ) <EOL> os . remove ( credfile ) <EOL> except Exception , rme : <EOL> self . log . debug ( "<STR_LIT>" + str ( rme ) ) <EOL> pass <EOL> try : <EOL> self . log . debug ( "<STR_LIT>" + mylockfile ) <EOL> os . remove ( mylockfile ) <EOL> except Exception , rme : <EOL> self . log . debug ( "<STR_LIT>" + str ( rme ) ) <EOL> pass <EOL> def unzipCredentialsToDir ( self , sourcefile , destdir ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> self . log . debug ( "<STR_LIT>" + str ( sourcefile ) + "<STR_LIT>" + str ( destdir ) ) <EOL> cmd = '<STR_LIT>' + str ( sourcefile ) + '<STR_LIT>' + str ( destdir ) <EOL> status = call ( cmd , shell = True ) <EOL> if ( status != <NUM_LIT:0> ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> except Exception , e : <EOL> raise Exception ( "<STR_LIT>" + str ( e ) ) <EOL> def sourceEucarcFromDir ( self , srcdir ) : <EOL> try : <EOL> srcdir = str ( srcdir ) <EOL> self . log . debug ( "<STR_LIT>" + srcdir ) <EOL> srcdir = str ( srcdir ) <EOL> filelist = os . listdir ( str ( srcdir ) ) <EOL> if ( not re . search ( '<STR_LIT>' , srcdir ) ) : <EOL> srcdir = srcdir + '<STR_LIT:/>' <EOL> for f in filelist : <EOL> self . log . debug ( "<STR_LIT>" + str ( f ) ) <EOL> if ( re . search ( '<STR_LIT>' , f ) ) : <EOL> cmd = '<STR_LIT>' + srcdir + f <EOL> self . log . debug ( "<STR_LIT>" + str ( cmd ) ) <EOL> status , output = commands . getstatusoutput ( cmd ) <EOL> self . log . debug ( "<STR_LIT>" + str ( output ) ) <EOL> if ( status != <NUM_LIT:0> ) : <EOL> raise Exception ( "<STR_LIT>" + cmd + "<STR_LIT>" + str ( status ) ) <EOL> return <EOL> raise Exception ( "<STR_LIT>" + str ( srcdir ) ) <EOL> except Exception , e : <EOL> raise Exception ( "<STR_LIT>" + str ( e ) ) <EOL> def confirmAccount ( self , acctname ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> acctname = str ( acctname ) <EOL> driver = self . driver <EOL> link = self . getApprovalEmailLink ( acctname ) <EOL> self . driverRestart ( ) <EOL> self . driver . get ( "<STR_LIT>" ) <EOL> driver . get ( str ( link ) ) <EOL> self . waitForTextOnPage ( "<STR_LIT>" , <NUM_LIT:2> ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . click ( ) <EOL> except Exception , e : <EOL> self . log . critical ( "<STR_LIT>" + str ( e ) ) <EOL> raise e <EOL> self . driverRestart ( ) <EOL> def getApprovalEmailLink ( self , acctname ) : <EOL> acctname = str ( acctname ) <EOL> output = [ ] <EOL> line = "<STR_LIT>" <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + acctname + "<STR_LIT:)>" ) ) <EOL> searchcmd = "<STR_LIT>" + acctname + "<STR_LIT>" <EOL> self . log . debug ( "<STR_LIT>" + str ( searchcmd ) ) <EOL> try : <EOL> output = self . eutester . sys ( str ( searchcmd ) ) <EOL> except Exception , e : <EOL> self . log . critical ( "<STR_LIT>" + str ( e ) ) <EOL> raise e <EOL> if ( output != [ ] ) : <EOL> for line in output : <EOL> self . log . debug ( "<STR_LIT>" + str ( line ) ) <EOL> m = re . search ( '<STR_LIT>' , line ) <EOL> if ( m ) : <EOL> self . log . debug ( "<STR_LIT>" + str ( line ) ) <EOL> return line <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def getPasswordResetEmailLink ( self , user , account ) : <EOL> account = str ( account ) <EOL> user = str ( user ) <EOL> output = [ ] <EOL> line = "<STR_LIT>" <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + user + "<STR_LIT:@>" + account + "<STR_LIT:)>" ) ) <EOL> searchcmd = "<STR_LIT>" + user + "<STR_LIT:@>" + account + "<STR_LIT>" <EOL> self . log . debug ( "<STR_LIT>" + str ( searchcmd ) ) <EOL> try : <EOL> output = self . eutester . sys ( str ( searchcmd ) ) <EOL> except Exception , e : <EOL> self . log . critical ( "<STR_LIT>" + str ( e ) ) <EOL> raise e <EOL> if ( output != [ ] ) : <EOL> for line in output : <EOL> self . log . debug ( "<STR_LIT>" + str ( line ) ) <EOL> m = re . search ( '<STR_LIT>' , line ) <EOL> if ( m ) : <EOL> self . log . debug ( "<STR_LIT>" + str ( line ) ) <EOL> return line <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def changePassword ( self , user , account , newpass , verify_pass = "<STR_LIT>" , expect = "<STR_LIT>" ) : <EOL> '''<STR_LIT>''' <EOL> if ( verify_pass == "<STR_LIT>" ) : <EOL> verify_pass = newpass <EOL> if ( expect == "<STR_LIT>" ) : <EOL> expect = self . wg . PasswordRestSuccess <EOL> try : <EOL> user = str ( user ) <EOL> account = str ( account ) <EOL> driver = self . driver <EOL> link = self . getPasswordResetEmailLink ( user , account ) <EOL> self . driverRestart ( ) <EOL> self . driver . get ( "<STR_LIT>" ) <EOL> driver . get ( str ( link ) ) <EOL> self . waitForTextOnPage ( self . wg . PasswordResetForm , <NUM_LIT:2> ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . send_keys ( newpass ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . send_keys ( verify_pass ) <EOL> driver . find_element_by_link_text ( "<STR_LIT:OK>" ) . click ( ) <EOL> self . waitForTextOnPage ( expect , <NUM_LIT:0> ) <EOL> if ( expect == self . wg . PasswordRestSuccess ) : <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . click ( ) <EOL> except Exception , e : <EOL> self . log . critical ( "<STR_LIT>" + str ( e ) ) <EOL> raise e <EOL> self . driverRestart ( ) <EOL> def signUpUser ( self , account , user , passwd , email , expect = "<STR_LIT>" ) : <EOL> '''<STR_LIT>''' <EOL> if ( expect == "<STR_LIT>" ) : <EOL> expect = self . wg . AccountSignUpSuccess <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + account + "<STR_LIT>" + user + "<STR_LIT>" + passwd + "<STR_LIT>" + email ) ) <EOL> try : <EOL> driver = self . driver <EOL> driver . get ( self . clcurl ) <EOL> driver . find_element_by_link_text ( "<STR_LIT>" ) . click ( ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . send_keys ( account ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . send_keys ( email ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . send_keys ( passwd ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . send_keys ( passwd ) <EOL> driver . find_element_by_link_text ( "<STR_LIT:OK>" ) . click ( ) <EOL> self . waitForTextOnPage ( expect , <NUM_LIT:1> ) <EOL> if ( expect == self . wg . AccountSignUpSuccess ) : <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . click ( ) <EOL> self . waitForText ( self . wg . xPage , "<STR_LIT>" , <NUM_LIT:3> ) <EOL> except Exception , e : <EOL> self . log . critical ( "<STR_LIT>" + user + "<STR_LIT:@>" + account + "<STR_LIT>" + str ( e ) ) <EOL> raise e <EOL> def clickButtonXpathAndVerify ( self , xpath , verify_text ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + str ( xpath ) + "<STR_LIT>" + verify_text ) ) <EOL> driver = self . driver <EOL> button = xpath <EOL> driver . find_element_by_xpath ( button ) . click ( ) <EOL> self . waitForTextOnPage ( verify_text ) <EOL> except Exception , e : <EOL> self . log . critical ( "<STR_LIT>" + str ( e ) ) <EOL> raise e <EOL> def getAccountListAll ( self ) : <EOL> self . log . critical ( self . hd ( "<STR_LIT>" ) ) <EOL> return self . getAccountList ( None , None , None ) <EOL> def getAccountById ( self , uid ) : <EOL> self . log . critical ( self . hd ( "<STR_LIT>" + str ( uid ) ) ) <EOL> if ( not uid ) : <EOL> self . log . critical ( "<STR_LIT>" ) <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> return self . getAccountList ( None , uid , None ) <EOL> def getAccountByName ( self , name ) : <EOL> acct = euwebaccount . Euwebaccount ( ) <EOL> self . log . critical ( self . hd ( "<STR_LIT>" + str ( name ) + "<STR_LIT>" ) ) <EOL> if ( not name ) : <EOL> self . log . critical ( "<STR_LIT>" ) <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> acct = self . getAccountList ( name , None , None ) <EOL> if ( acct is None ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> acct . printSelf ( ) <EOL> return acct <EOL> def getAccountsByStat ( self , stat ) : <EOL> self . log . critical ( self . hd ( "<STR_LIT>" + str ( stat ) ) ) <EOL> if ( not stat ) : <EOL> self . log . critical ( "<STR_LIT>" ) <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> return self . getAccountList ( None , None , stat ) <EOL> def getAccountList ( self , name , uid , status ) : <EOL> '''<STR_LIT>''' <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + str ( name ) + "<STR_LIT>" + str ( uid ) + "<STR_LIT>" + str ( status ) + "<STR_LIT:)>" ) ) <EOL> if ( name is not None ) : <EOL> name = str ( name ) <EOL> if ( uid is not None ) : <EOL> uid = str ( uid ) <EOL> if ( status is not None ) : <EOL> status = str ( status ) <EOL> if ( ( name is None ) and ( uid is None ) and ( status is None ) ) : <EOL> getall = True <EOL> else : <EOL> getall = False <EOL> try : <EOL> accountlist = [ ] <EOL> driver = self . driver <EOL> self . clickButtonXpathAndVerify ( self . wg . xLn_Accounts , self . wg . AccountsTxt ) <EOL> self . driver . refresh ( ) <EOL> try : <EOL> driver . find_elements_by_xpath ( self . wg . xAccountsTable ) <EOL> except Exception , e : <EOL> self . debug ( "<STR_LIT>" + str ( e ) ) <EOL> return accountlist <EOL> prange = str ( driver . find_element_by_xpath ( self . wg . xAccountPageRange ) . get_attribute ( "<STR_LIT>" ) ) <EOL> accountsonpage = int ( prange . split ( '<STR_LIT>' ) . pop ( ) ) <EOL> row_xpath = self . wg . xAccountsRow1 <EOL> tr = <NUM_LIT:1> <EOL> page = <NUM_LIT:1> <EOL> retry = <NUM_LIT:1> <EOL> driver . implicitly_wait ( <NUM_LIT:1> ) <EOL> while ( True ) : <EOL> try : <EOL> if ( tr == <NUM_LIT:1> ) : <EOL> self . log . debug ( "<STR_LIT>" + str ( tr ) + "<STR_LIT:)>" ) <EOL> gAccount = euwebaccount . Euwebaccount ( ) <EOL> gAccount . row_xpath = row_xpath <EOL> tr += <NUM_LIT:1> <EOL> if ( tr > <NUM_LIT:2> ) : <EOL> retry = <NUM_LIT:1> <EOL> row_xpath = self . wg . xAccountsRow1 + "<STR_LIT:[>" + str ( tr ) + "<STR_LIT:]>" <EOL> id_xpath = row_xpath + '<STR_LIT>' <EOL> name_xpath = row_xpath + '<STR_LIT>' <EOL> status_xpath = row_xpath + '<STR_LIT>' <EOL> gAccount . id = driver . find_element_by_xpath ( id_xpath ) . get_attribute ( "<STR_LIT>" ) <EOL> gAccount . id_xpath = id_xpath <EOL> self . log . debug ( "<STR_LIT>" + gAccount . id ) <EOL> if ( ( not getall ) and ( uid != None ) ) : <EOL> if ( uid == gAccount . id ) : <EOL> addtolist = True <EOL> else : <EOL> addtolist = False <EOL> continue <EOL> gAccount . name = driver . find_element_by_xpath ( name_xpath ) . get_attribute ( "<STR_LIT>" ) <EOL> gAccount . name_xpath = name_xpath <EOL> self . log . debug ( "<STR_LIT>" + gAccount . name ) <EOL> if ( ( not getall ) and ( name != None ) ) : <EOL> if ( name == gAccount . name ) : <EOL> addtolist = True <EOL> else : <EOL> addtolist = False <EOL> continue <EOL> gAccount . status = driver . find_element_by_xpath ( status_xpath ) . get_attribute ( "<STR_LIT>" ) <EOL> gAccount . status_elm = status_xpath <EOL> self . log . debug ( "<STR_LIT>" + gAccount . status ) <EOL> if ( ( not getall ) and ( status != None ) ) : <EOL> if ( status == gAccount . status ) : <EOL> addtolist = True <EOL> else : <EOL> addtolist = False <EOL> continue <EOL> if ( addtolist and ( not getall ) and ( not status ) ) : <EOL> self . log . debug ( "<STR_LIT>" + str ( tr ) + "<STR_LIT>" + str ( page ) + "<STR_LIT>" + gAccount . name ) <EOL> return gAccount <EOL> if ( getall or addtolist ) : <EOL> self . log . debug ( "<STR_LIT>" + str ( tr ) + "<STR_LIT>" ) <EOL> accountlist . append ( gAccount ) <EOL> except NoSuchElementException : <EOL> print "<STR_LIT>" + str ( tr ) + "<STR_LIT>" + str ( retry ) + "<STR_LIT>" + str ( accountsonpage ) <EOL> if ( ( accountsonpage > <NUM_LIT:0> ) and ( retry < <NUM_LIT:5> ) and ( tr == <NUM_LIT:2> ) ) : <EOL> self . log . debug ( "<STR_LIT>" + str ( accountsonpage ) + "<STR_LIT>" + str ( retry ) + "<STR_LIT>" + str ( tr ) ) <EOL> retry += <NUM_LIT:1> <EOL> tr = <NUM_LIT:1> <EOL> time . sleep ( <NUM_LIT:3> ) <EOL> else : <EOL> try : <EOL> self . log . debug ( "<STR_LIT>" + str ( tr ) + "<STR_LIT>" + str ( retry ) + "<STR_LIT>" ) <EOL> prange = str ( driver . find_element_by_xpath ( self . wg . xAccountPageRange ) . get_attribute ( "<STR_LIT>" ) ) <EOL> accountsonpage = int ( prange . split ( '<STR_LIT>' ) . pop ( ) ) <EOL> try : <EOL> driver . implicitly_wait ( <NUM_LIT:3> ) <EOL> self . clickButtonXpathAndVerify ( self . wg . xAccountForwardButton , prange ) <EOL> button_failed = True <EOL> except Exception , be : <EOL> self . log . debug ( "<STR_LIT>" + prange + "<STR_LIT>" + str ( be ) ) <EOL> button_failed = False <EOL> pass <EOL> if ( button_failed ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> row_xpath = self . wg . xAccountsRow1 <EOL> tr = <NUM_LIT:1> <EOL> page += <NUM_LIT:1> <EOL> driver . find_elements_by_xpath ( self . wg . xAccountsTable ) <EOL> driver . find_element_by_xpath ( row_xpath ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> driver . implicitly_wait ( <NUM_LIT:1> ) <EOL> except Exception , e : <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> if ( accountlist == [ ] ) : <EOL> raise Exception ( "<STR_LIT>" + str ( name ) + "<STR_LIT>" + str ( uid ) + "<STR_LIT>" + str ( status ) + "<STR_LIT>" ) <EOL> else : <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> return accountlist <EOL> raise Exception ( "<STR_LIT>" ) <EOL> except Exception , e : <EOL> self . log . critical ( "<STR_LIT>" + str ( e ) ) <EOL> raise e <EOL> finally : <EOL> driver . implicitly_wait ( <NUM_LIT:10> ) <EOL> def searchForElementByUrl ( self , url ) : <EOL> '''<STR_LIT>''' <EOL> url = self . clcurl + str ( url ) <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + str ( url ) + "<STR_LIT:)>" ) ) <EOL> driver = self . driver <EOL> driver . get ( url ) <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> pairs = re . findall ( '<STR_LIT>' , url ) <EOL> for p in pairs : <EOL> verifytext = p . split ( '<STR_LIT:=>' ) . pop ( ) <EOL> self . log . debug ( "<STR_LIT>" + verifytext ) <EOL> self . waitForTextOnPage ( verifytext , <NUM_LIT:2> ) <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> def searchForUser ( self , user , account ) : <EOL> '''<STR_LIT>''' <EOL> user = str ( user ) <EOL> account = str ( account ) <EOL> url = self . wg . urlSearchUserByAccount + account + "<STR_LIT>" + user <EOL> self . log . debug ( "<STR_LIT>" + str ( url ) + "<STR_LIT:)>" ) <EOL> self . searchForElementByUrl ( str ( url ) ) <EOL> def getUserRowValuesByXpath ( self , row_xpath ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + str ( row_xpath ) ) ) <EOL> driver = self . driver <EOL> user = euwebuser . Euwebuser ( makerandom = False ) <EOL> driver . find_element_by_xpath ( row_xpath ) <EOL> id_xpath = row_xpath + '<STR_LIT>' <EOL> name_xpath = row_xpath + '<STR_LIT>' <EOL> path_xpath = row_xpath + '<STR_LIT>' <EOL> account_xpath = row_xpath + '<STR_LIT>' <EOL> enabled_xpath = row_xpath + '<STR_LIT>' <EOL> status_xpath = row_xpath + '<STR_LIT>' <EOL> user . id = driver . find_element_by_xpath ( id_xpath ) . get_attribute ( "<STR_LIT>" ) <EOL> user . user = driver . find_element_by_xpath ( name_xpath ) . get_attribute ( "<STR_LIT>" ) <EOL> user . path = driver . find_element_by_xpath ( path_xpath ) . get_attribute ( "<STR_LIT>" ) <EOL> user . account = driver . find_element_by_xpath ( account_xpath ) . get_attribute ( "<STR_LIT>" ) <EOL> user . enabled = driver . find_element_by_xpath ( enabled_xpath ) . get_attribute ( "<STR_LIT>" ) <EOL> user . status = driver . find_element_by_xpath ( status_xpath ) . get_attribute ( "<STR_LIT>" ) <EOL> user . printUser ( ) <EOL> return user <EOL> except Exception , e : <EOL> raise Exception ( "<STR_LIT>" + str ( e ) ) <EOL> def enableDisableUser ( self , user , account , enable_flag = True ) : <EOL> '''<STR_LIT>''' <EOL> driver = self . driver <EOL> if ( enable_flag ) : <EOL> entxt = "<STR_LIT:true>" <EOL> else : <EOL> entxt = "<STR_LIT:false>" <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + user + "<STR_LIT>" + str ( enable_flag ) ) ) <EOL> self . searchForUser ( user , account ) <EOL> self . clickButtonXpathAndVerify ( self . wg . xUsersRow1Id , user ) <EOL> state = self . getRightNavValueByName ( self . wg . UsersRightNav_Enabled , attribute = "<STR_LIT>" ) <EOL> self . log . debug ( "<STR_LIT>" + state + "<STR_LIT>" + entxt ) <EOL> if ( ( state == "<STR_LIT:true>" ) == enable_flag ) : <EOL> self . log . debug ( "<STR_LIT>" + str ( state ) ) <EOL> return <EOL> self . log . debug ( "<STR_LIT>" + entxt ) <EOL> checkBoxXpath = self . getRightNavValueByName ( "<STR_LIT>" , returnXpath = True ) <EOL> driver . find_element_by_xpath ( checkBoxXpath ) . click ( ) <EOL> time . sleep ( <NUM_LIT:2> ) <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> time . sleep ( <NUM_LIT:5> ) <EOL> driver . find_element_by_xpath ( self . wg . xRighNavSaveButton ) . click ( ) <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> time . sleep ( <NUM_LIT:5> ) <EOL> driver . refresh ( ) <EOL> self . clickButtonXpathAndVerify ( self . wg . xUsersRow1Id , user ) <EOL> newstate = self . getRightNavValueByName ( self . wg . UsersRightNav_Enabled , attribute = "<STR_LIT>" ) <EOL> if ( newstate == state ) : <EOL> raise Exception ( "<STR_LIT>" + str ( state ) + "<STR_LIT>" + str ( newstate ) ) <EOL> def addUserToAccount ( self , accountname , username , path = "<STR_LIT>" , verifyLog = True ) : <EOL> if ( path == "<STR_LIT>" ) : <EOL> path = "<STR_LIT:/>" + username <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + accountname + "<STR_LIT>" + username + "<STR_LIT>" + path + "<STR_LIT:)>" ) ) <EOL> driver = self . driver <EOL> self . searchForElementByUrl ( self . wg . urlSearchAccountByName + accountname ) <EOL> self . clickButtonXpathAndVerify ( self . wg . xAccountsRow1Id , self . wg . rightNavTxt ) <EOL> driver . find_element_by_link_text ( "<STR_LIT>" ) . click ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . send_keys ( username ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . send_keys ( path ) <EOL> driver . find_element_by_link_text ( "<STR_LIT:OK>" ) . click ( ) <EOL> if ( verifyLog ) : <EOL> result = self . getOnScreenLogMesg ( ) <EOL> if ( result == "<STR_LIT>" ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> self . log . debug ( "<STR_LIT>" + result ) <EOL> def changeUserPassword ( self , accountname , username , adminpass , newpass , expect = "<STR_LIT>" , vpass = "<STR_LIT>" , verifyLog = True ) : <EOL> if ( vpass == "<STR_LIT>" ) : <EOL> vpass = newpass <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + accountname + "<STR_LIT>" + username + "<STR_LIT>" + adminpass + "<STR_LIT>" + newpass + "<STR_LIT:)>" ) ) <EOL> driver = self . driver <EOL> url = self . wg . urlSearchUserByAccount + accountname + "<STR_LIT>" + username <EOL> self . searchForElementByUrl ( url ) <EOL> self . clickButtonXpathAndVerify ( self . wg . xUsersRow1Id , self . wg . rightNavTxt ) <EOL> passwdxpath = self . getRightNavValueByName ( self . wg . UsersRighNav_Password , attribute = "<STR_LIT>" , returnXpath = True , input_path = "<STR_LIT>" ) <EOL> driver . find_element_by_xpath ( passwdxpath ) . click ( ) <EOL> self . waitForTextOnPage ( "<STR_LIT>" , <NUM_LIT:1> ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . send_keys ( adminpass ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . send_keys ( newpass ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . send_keys ( vpass ) <EOL> driver . find_element_by_link_text ( "<STR_LIT:OK>" ) . click ( ) <EOL> if ( expect != "<STR_LIT>" ) : <EOL> self . waitForTextOnPage ( expect , <NUM_LIT:1> ) <EOL> if ( verifyLog == True ) : <EOL> result = self . getOnScreenLogMesg ( ) <EOL> self . log . debug ( "<STR_LIT>" + result ) <EOL> if ( result == "<STR_LIT>" ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> elif ( result == "<STR_LIT>" ) : <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> else : <EOL> self . log . critical ( "<STR_LIT>" ) <EOL> def getOnScreenLogMesg ( self ) : <EOL> try : <EOL> message = self . driver . find_element_by_xpath ( self . wg . xLogMessage ) . get_attribute ( "<STR_LIT>" ) <EOL> message = str ( message ) <EOL> self . log . debug ( "<STR_LIT>" + message ) <EOL> return message <EOL> except NoSuchElementException : <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> return "<STR_LIT>" <EOL> def userFirstTimeLogin ( self , email , oldpass , newpass , newpass2 = "<STR_LIT>" , expect = "<STR_LIT>" ) : <EOL> '''<STR_LIT>''' <EOL> if ( newpass2 == "<STR_LIT>" ) : <EOL> newpass2 = newpass <EOL> driver = self . driver <EOL> try : <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . clear ( ) <EOL> except Exception , e : <EOL> raise ( "<STR_LIT>" + str ( e ) ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . send_keys ( email ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . send_keys ( oldpass ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . send_keys ( newpass ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . send_keys ( newpass2 ) <EOL> driver . find_element_by_link_text ( "<STR_LIT:OK>" ) . click ( ) <EOL> if ( expect != "<STR_LIT>" ) : <EOL> self . waitForTextOnPage ( expect , <NUM_LIT:1> ) <EOL> def deleteAccount ( self , accountname , expect = "<STR_LIT>" , verifylog = True ) : <EOL> driver = self . driver <EOL> self . searchForElementByUrl ( self . wg . urlSearchAccountByName + accountname ) <EOL> driver . find_element_by_link_text ( "<STR_LIT>" ) . click ( ) <EOL> driver . find_element_by_link_text ( "<STR_LIT:OK>" ) . click ( ) <EOL> if ( verifylog == True ) : <EOL> result = self . getOnScreenLogMesg ( ) <EOL> if ( result != "<STR_LIT>" ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> else : <EOL> self . log . debug ( "<STR_LIT>" + result ) <EOL> def clickAndApproveAccount ( self , bool_approve , bool_ok ) : <EOL> driver = self . driver <EOL> if ( bool_approve ) : <EOL> driver . find_element_by_link_text ( "<STR_LIT>" ) . click ( ) <EOL> else : <EOL> driver . find_element_by_link_text ( "<STR_LIT>" ) . click ( ) <EOL> if ( bool_ok ) : <EOL> driver . find_element_by_link_text ( "<STR_LIT:OK>" ) . click ( ) <EOL> else : <EOL> driver . find_element_by_link_text ( "<STR_LIT>" ) . click ( ) <EOL> driver . refresh ( ) <EOL> def addNewGroupToAccount ( self , accountname , newgroupname , path = "<STR_LIT>" , verifyLog = True ) : <EOL> if ( path == "<STR_LIT>" ) : <EOL> path = "<STR_LIT:/>" + newgroupname <EOL> driver = self . driver <EOL> self . searchForElementByUrl ( self . wg . urlSearchAccountByName + accountname ) <EOL> self . driver . find_element_by_xpath ( self . wg . xAccountsRow1Id ) . click ( ) <EOL> driver . find_element_by_link_text ( "<STR_LIT>" ) . click ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . send_keys ( newgroupname ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . send_keys ( path ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . click ( ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> if ( verifyLog == True ) : <EOL> result = self . getOnScreenLogMesg ( ) <EOL> if ( result . lower ( ) . find ( '<STR_LIT>' ) >= <NUM_LIT:0> ) : <EOL> self . log . critical ( "<STR_LIT>" + result + "<STR_LIT:)>" ) <EOL> raise Exception ( "<STR_LIT>" + newgroupname + "<STR_LIT>" ) <EOL> else : <EOL> self . log . debug ( "<STR_LIT>" + result + "<STR_LIT:)>" ) <EOL> def addExistingUserToGroup ( self , accountname , groupname , username , verifyLog = True ) : <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + str ( accountname ) + "<STR_LIT>" + str ( groupname ) + "<STR_LIT>" + str ( username ) + "<STR_LIT:)>" ) ) <EOL> driver = self . driver <EOL> url = self . wg . urlSearchGroupByName + groupname + "<STR_LIT>" + accountname <EOL> self . searchForElementByUrl ( url ) <EOL> time . sleep ( <NUM_LIT:3> ) <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> driver . find_element_by_xpath ( self . wg . xGroupRow1Id ) . click ( ) <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> driver . find_element_by_link_text ( "<STR_LIT>" ) . click ( ) <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . send_keys ( username ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . click ( ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> if ( verifyLog == True ) : <EOL> result = self . getOnScreenLogMesg ( ) <EOL> if ( result . lower ( ) . find ( '<STR_LIT>' ) >= <NUM_LIT:0> ) : <EOL> self . log . critical ( "<STR_LIT>" + result + "<STR_LIT:)>" ) <EOL> raise Exception ( "<STR_LIT>" + groupname + "<STR_LIT>" ) <EOL> else : <EOL> self . log . debug ( "<STR_LIT>" + result + "<STR_LIT:)>" ) <EOL> def addPolicyToAccount ( self , accountname , newpolicyname , policytext , verifyLog = True ) : <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + str ( accountname ) + "<STR_LIT>" + str ( policytext ) + "<STR_LIT:)>" ) ) <EOL> driver = self . driver <EOL> self . searchForElementByUrl ( self . wg . urlSearchAccountByName + accountname ) <EOL> self . driver . find_element_by_xpath ( self . wg . xAccountsRow1Id ) . click ( ) <EOL> driver . find_element_by_link_text ( "<STR_LIT>" ) . click ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . send_keys ( newpolicyname ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . send_keys ( policytext ) <EOL> driver . find_element_by_link_text ( "<STR_LIT:OK>" ) . click ( ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> if ( verifyLog == True ) : <EOL> result = self . getOnScreenLogMesg ( ) <EOL> if ( result . lower ( ) . find ( '<STR_LIT>' ) >= <NUM_LIT:0> ) : <EOL> self . log . critical ( "<STR_LIT>" + result + "<STR_LIT:)>" ) <EOL> raise Exception ( "<STR_LIT>" + str ( newpolicyname ) + "<STR_LIT>" + str ( accountname ) + "<STR_LIT:)>" ) <EOL> else : <EOL> self . log . debug ( "<STR_LIT>" + result + "<STR_LIT:)>" ) <EOL> def addPolicyToUser ( self , username , accountname , newpolicyname , policytext , verifyLog = True ) : <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + str ( accountname ) + "<STR_LIT>" + str ( policytext ) + "<STR_LIT:)>" ) ) <EOL> driver = self . driver <EOL> url = self . wg . urlSearchUserByName + username + "<STR_LIT>" + accountname <EOL> self . searchForElementByUrl ( url ) <EOL> self . driver . find_element_by_xpath ( self . wg . xUsersRow1Id ) . click ( ) <EOL> driver . find_element_by_link_text ( "<STR_LIT>" ) . click ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . send_keys ( newpolicyname ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . send_keys ( policytext ) <EOL> driver . find_element_by_link_text ( "<STR_LIT:OK>" ) . click ( ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> if ( verifyLog == True ) : <EOL> result = self . getOnScreenLogMesg ( ) <EOL> if ( result . lower ( ) . find ( '<STR_LIT>' ) >= <NUM_LIT:0> ) : <EOL> self . log . critical ( "<STR_LIT>" + result + "<STR_LIT:)>" ) <EOL> raise Exception ( "<STR_LIT>" + str ( newpolicyname ) + "<STR_LIT>" + str ( username ) + "<STR_LIT:@>" + str ( accountname ) + "<STR_LIT:)>" ) <EOL> else : <EOL> self . log . debug ( "<STR_LIT>" + result + "<STR_LIT:)>" ) <EOL> def addPolicyToGroup ( self , groupname , accountname , newpolicyname , policytext , verifyLog = True ) : <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + str ( accountname ) + "<STR_LIT>" + str ( policytext ) + "<STR_LIT:)>" ) ) <EOL> driver = self . driver <EOL> url = self . wg . urlSearchGroupByName + groupname + "<STR_LIT>" + accountname <EOL> self . searchForElementByUrl ( url ) <EOL> self . driver . find_element_by_xpath ( self . wg . xGroupRow1Id ) . click ( ) <EOL> driver . find_element_by_link_text ( "<STR_LIT>" ) . click ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . send_keys ( newpolicyname ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . send_keys ( policytext ) <EOL> driver . find_element_by_link_text ( "<STR_LIT:OK>" ) . click ( ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> if ( verifyLog == True ) : <EOL> result = self . getOnScreenLogMesg ( ) <EOL> if ( result . lower ( ) . find ( '<STR_LIT>' ) >= <NUM_LIT:0> ) : <EOL> self . log . critical ( "<STR_LIT>" + result + "<STR_LIT:)>" ) <EOL> raise Exception ( "<STR_LIT>" + str ( newpolicyname ) + "<STR_LIT>" + str ( groupname ) + "<STR_LIT:@>" + str ( accountname ) + "<STR_LIT:)>" ) <EOL> else : <EOL> self . log . debug ( "<STR_LIT>" + result + "<STR_LIT:)>" ) <EOL> def modifyVmType ( self , vmtype , attr , value , verifyLog = True ) : <EOL> '''<STR_LIT>''' <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + str ( vmtype ) + "<STR_LIT>" + str ( attr ) + "<STR_LIT>" + str ( value ) + "<STR_LIT:)>" ) ) <EOL> driver = self . driver <EOL> driver . get ( self . clcurl + self . wg . urlSearchVmType ) <EOL> self . waitForTextOnPage ( self . wg . VmTypesTxt ) <EOL> driver . find_element_by_xpath ( self . getTableRowXpathByString ( self . wg . xVmTypeTable , vmtype ) + "<STR_LIT>" ) . click ( ) <EOL> attrxpath = self . getRightNavValueByName ( attr , returnXpath = True ) <EOL> driver . find_element_by_xpath ( attrxpath ) . clear ( ) <EOL> driver . find_element_by_xpath ( attrxpath ) . send_keys ( str ( value ) ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> driver . find_element_by_xpath ( self . wg . xRighNavSaveButton ) . click ( ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> if ( verifyLog == True ) : <EOL> result = self . getOnScreenLogMesg ( ) <EOL> if ( result . lower ( ) . find ( '<STR_LIT>' ) >= <NUM_LIT:0> ) : <EOL> self . log . critical ( "<STR_LIT>" + result + "<STR_LIT:)>" ) <EOL> raise Exception ( "<STR_LIT>" + str ( vmtype ) + "<STR_LIT>" + str ( attr ) + "<STR_LIT>" + str ( value ) + "<STR_LIT:)>" ) <EOL> else : <EOL> self . log . debug ( "<STR_LIT>" + result + "<STR_LIT:)>" ) <EOL> def getTableRowXpathByString ( self , table_xpath , match , startcol = <NUM_LIT:1> , endcol = <NUM_LIT:1> , case = False , highlightrow = False ) : <EOL> '''<STR_LIT>''' <EOL> if ( case == False ) : <EOL> match = str ( match ) . upper ( ) <EOL> table_xpath = str ( table_xpath ) <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + table_xpath + "<STR_LIT>" + match + "<STR_LIT:)>" ) ) <EOL> driver = self . driver <EOL> row_xpath = table_xpath + "<STR_LIT>" <EOL> tr = <NUM_LIT:1> <EOL> td = startcol <EOL> try : <EOL> driver . find_elements_by_xpath ( table_xpath ) <EOL> except Exception , nfe : <EOL> self . log . critical ( "<STR_LIT>" + str ( table_xpath ) ) <EOL> raise nfe <EOL> driver . implicitly_wait ( <NUM_LIT:1> ) <EOL> try : <EOL> while ( True ) : <EOL> td = startcol <EOL> if ( td > <NUM_LIT:1> ) : <EOL> element_xpath = row_xpath + "<STR_LIT>" + str ( td ) + "<STR_LIT:]>" <EOL> else : <EOL> element_xpath = row_xpath + "<STR_LIT>" <EOL> if ( highlightrow == True ) : <EOL> self . driver . find_element_by_xpath ( row_xpath + "<STR_LIT>" ) . click ( ) <EOL> self . log . debug ( "<STR_LIT>" + str ( td ) + "<STR_LIT>" + str ( row_xpath ) ) <EOL> try : <EOL> while ( td <= endcol ) : <EOL> self . log . debug ( "<STR_LIT>" + match + "<STR_LIT>" + str ( element_xpath ) ) <EOL> vstr = str ( driver . find_element_by_xpath ( element_xpath ) . get_attribute ( "<STR_LIT>" ) ) <EOL> if ( case == False ) : <EOL> vstr = vstr . upper ( ) <EOL> self . log . debug ( "<STR_LIT>" + str ( tr ) + "<STR_LIT>" + str ( td ) + "<STR_LIT>" + str ( vstr ) + "<STR_LIT:)>" ) <EOL> if ( vstr == match ) : <EOL> self . log . debug ( "<STR_LIT>" + match + "<STR_LIT>" + vstr + "<STR_LIT>" ) <EOL> return row_xpath <EOL> td += <NUM_LIT:1> <EOL> element_xpath = row_xpath + "<STR_LIT>" + str ( td ) + "<STR_LIT:]>" <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> tr += <NUM_LIT:1> <EOL> row_xpath = row_xpath + "<STR_LIT:[>" + str ( tr ) + "<STR_LIT:]>" <EOL> except NoSuchElementException , nse : <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> tr += <NUM_LIT:1> <EOL> row_xpath = row_xpath + "<STR_LIT:[>" + str ( tr ) + "<STR_LIT:]>" <EOL> except NoSuchElementException , nse : <EOL> self . log . debug ( "<STR_LIT>" + match ) <EOL> driver . implicitly_wait ( <NUM_LIT:10> ) <EOL> raise nse <EOL> finally : <EOL> driver . implicitly_wait ( <NUM_LIT:10> ) <EOL> def getRightNavValueByName ( self , name , attribute = "<STR_LIT:value>" , table_xpath = "<STR_LIT>" , row1_xpath = "<STR_LIT>" , returnXpath = False , input_path = "<STR_LIT>" ) : <EOL> '''<STR_LIT>''' <EOL> if ( table_xpath == "<STR_LIT>" ) : <EOL> table_xpath = self . wg . xRightNavTable <EOL> if ( row1_xpath == "<STR_LIT>" ) : <EOL> row1_xpath = table_xpath + "<STR_LIT>" <EOL> try : <EOL> name = str ( name ) <EOL> nav_val = "<STR_LIT>" <EOL> self . log . debug ( self . hd ( "<STR_LIT>" + str ( name ) + "<STR_LIT>" + str ( returnXpath ) + "<STR_LIT>" ) ) <EOL> driver = self . driver <EOL> try : <EOL> driver . find_elements_by_xpath ( table_xpath ) <EOL> except Exception , e : <EOL> self . debug ( "<STR_LIT>" + str ( e ) ) <EOL> return nav_val <EOL> row_xpath = row1_xpath + "<STR_LIT>" <EOL> tr = <NUM_LIT:1> <EOL> driver . implicitly_wait ( <NUM_LIT:1> ) <EOL> try : <EOL> while ( True ) : <EOL> self . log . debug ( "<STR_LIT>" + name + "<STR_LIT>" + row_xpath ) <EOL> vstr = str ( driver . find_element_by_xpath ( row_xpath ) . get_attribute ( "<STR_LIT>" ) ) <EOL> self . log . debug ( "<STR_LIT>" + vstr ) <EOL> if ( vstr == name ) : <EOL> self . log . debug ( "<STR_LIT>" + vstr ) <EOL> nav_xpath = row_xpath + input_path <EOL> self . log . debug ( "<STR_LIT>" + nav_xpath ) <EOL> try : <EOL> nav_val = str ( driver . find_element_by_xpath ( nav_xpath ) . get_attribute ( attribute ) ) <EOL> except NoSuchElementException , nse : <EOL> self . log . debug ( "<STR_LIT>" ) <EOL> nav_xpath = row_xpath + "<STR_LIT>" <EOL> nav_val = str ( driver . find_element_by_xpath ( nav_xpath ) . get_attribute ( attribute ) ) <EOL> self . log . debug ( "<STR_LIT>" + name + "<STR_LIT>" + nav_val + "<STR_LIT:)>" ) <EOL> if ( returnXpath ) : <EOL> self . log . debug ( "<STR_LIT>" + nav_xpath ) <EOL> return nav_xpath <EOL> else : <EOL> return nav_val <EOL> tr += <NUM_LIT:1> <EOL> row_xpath = row1_xpath + "<STR_LIT:[>" + str ( tr ) + "<STR_LIT>" <EOL> except NoSuchElementException , nse : <EOL> self . log . debug ( "<STR_LIT>" + name ) <EOL> driver . implicitly_wait ( <NUM_LIT:10> ) <EOL> raise nse <EOL> finally : <EOL> driver . implicitly_wait ( <NUM_LIT:10> ) <EOL> except Exception , e : <EOL> self . log . critical ( "<STR_LIT>" + name ) <EOL> raise e <EOL> def requestPasswordReset ( self , user , account , email , expect = "<STR_LIT>" ) : <EOL> self . log . debug ( self . hd ( "<STR_LIT>" ) ) <EOL> if ( expect == "<STR_LIT>" ) : <EOL> expect = self . wg . PasswordResetTxt <EOL> driver = self . driver <EOL> driver . find_element_by_link_text ( "<STR_LIT>" ) . click ( ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . send_keys ( user ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . send_keys ( account ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . clear ( ) <EOL> driver . find_element_by_xpath ( "<STR_LIT>" ) . send_keys ( email ) <EOL> driver . find_element_by_link_text ( "<STR_LIT:OK>" ) . click ( ) <EOL> self . waitForTextOnPage ( expect , <NUM_LIT:0> ) <EOL> if ( expect == self . wg . PasswordResetTxt ) : <EOL> driver . find_element_by_css_selector ( "<STR_LIT>" ) . click ( ) <EOL> self . waitForTextOnPage ( self . wg . PasswordTxt , <NUM_LIT:0> ) <EOL> def driverRestart ( self ) : <EOL> self . log . debug ( self . hd ( "<STR_LIT>" ) ) <EOL> self . driver . delete_all_cookies ( ) <EOL> self . driver . get ( "<STR_LIT>" ) <EOL> def tearDown ( self , stayOpenAfterError ) : <EOL> if ( stayOpenAfterError != <NUM_LIT:0> ) : <EOL> time . sleep ( stayOpenAfterError ) <EOL> self . driver . quit ( ) <EOL> self . driver . stop_client ( ) <EOL> def sig_handler ( self , sig ) : <EOL> self . log . critical ( '<STR_LIT>' + sig ) <EOL> self . tearDown ( <NUM_LIT:0> ) <EOL> signal . signal ( signal . SIGINT , sig_handler ) <EOL> class LoginFailure ( Exception ) : <EOL> def __init__ ( self , value ) : <EOL> self . value = value <EOL> def __str__ ( self ) : <EOL> return repr ( self . value ) </s>
