Exemplo n.º 1
0
    def add_course(self,driver,courseCode):
        """
        in webreg, adds the course specified with the classCode

        type lectureCode: string
        """
        find_n_click_xpath(driver,elements.ADD_RADIO)
        find_n_sendkeys(driver,elements.INPUT_COURSECODE,courseCode)
        find_n_click_xpath(driver,elements.SEND_REQUEST)
Exemplo n.º 2
0
    def logout_webreg(self,driver):
        """
        method to log out of webreg safely; don't rly need to handle exceptions?

        type driver: webdriver
        """
        try:
            find_n_click_xpath(self.driver, elements.LOGOUT_BUTTON)
        except:
            print("Couldn't log out safely, for some reason.")
Exemplo n.º 3
0
    def login_status(self, checkLoginSoup, loginTimer=0):
        """
        uses checkLoginSoup to find what state the login is in and returns success or fail
        can extend to check webreg status with last two arguments

        type checkLoginSoup: BeautifulSoup
        type WebRegExtend: boolean
        type loginTimer: int

        rtype: boolean
        """
        if checkLoginSoup.find_all(
                string=re.compile("Invalid UCInetID or password")):
            print("Your UCInetID and password are incorrect. ")
            return False
        elif checkLoginSoup.find(
                id="status"):  # too many failed logins, and maybe others?
            print('Unable to log in. "{msg}"'.format(
                msg=self.build_err_msg(checkLoginSoup, "status")))
            return False
        elif checkLoginSoup.find(
                class_="webauth-alert"):  # general error messages (hopefully)
            print('Unable to log in. "{msg}"'.format(
                msg=self.build_err_msg(checkLoginSoup, "error-message")))
            return False
        elif checkLoginSoup.find_all(
                string=re.compile("UCInetID Secure Web Login")):
            print('Unable to log in for some reason.')
            self.save_page(self.driver)
            return False
        else:  # means we're in webreg
            if self.testing:
                print(
                    "Your credentials successfully logged in!\nLogging out safely..."
                )
                self.testing = False
                try:
                    find_n_click_xpath(self.driver, elements.TEST_LOGOUT)
                except Exception as e:
                    print("Couldn't log out safely:")
                    print(f"{type(e)}: {e}")
                    print("Continuing anyway...")
                    pass
                print(
                    "------------------------------------------------------------------"
                )
                self.clean_driver()
            return True
Exemplo n.º 4
0
    def redir_login(self, driver):
        """
        had to implement because after webreg goes down, "access webreg" doesn't lead to webauth
        login anymore; so have to find another link to validate; self.testing, will
        redirect to diff places

        type driver: webdriver
        """
        try:
            if self.testing:
                self.driver.get(
                    "https://www.reg.uci.edu/access/student/welcome/")
                find_n_click_xpath(self.driver, elements.TEST_LOGIN)
            else:
                self.driver.get(
                    "https://www.reg.uci.edu/registrar/soc/webreg.html")
                find_n_click_xpath(self.driver,
                                   elements.ACCESS_WEBREG_registrar)
        except Exception as e:
            print("Something went wrong with redirecting to login:"******"{type(e)}: {e}")
Exemplo n.º 5
0
    def webreg_login_status(self,checkLoginSoup,loginTimer=0):
        """
        extends login_status to handle WebReg statuses

        type checkLoginSoup: BeautifulSoup
        """
        if LoginSetup.login_status(self,checkLoginSoup,loginTimer): # if in webreg
            if checkLoginSoup.find_all(string=re.compile('WebReg is experiencing high traffic at this time.')):
                print('In WebReg, but can\'t log in because of high traffic.')
                self.WebRegWait(loginTimer)
                self.driver.refresh()
            elif checkLoginSoup.find("div","WebRegErrorMsg"):
                print('In WebReg, but can\'t log in: {msg}"'.format(msg=checkLoginSoup.find("div","WebRegErrorMsg").string.strip()))
                self.WebRegWait(loginTimer)
                find_n_click_xpath(self.driver,elements.ACCESS_WEBREG_webreg)
            else: # some other error we can't catch with class='WebRegErrorMsg'
                print("In WebReg, but can't log in for some reason.")
                self.save_page(self.driver)
                self.WebRegWait(loginTimer)
                try:
                    find_n_click_xpath(self.driver,elements.ACCESS_WEBREG_webreg)
                except:
                    self.redir_login(self.driver)
Exemplo n.º 6
0
    def login(self):
        """
        logging in while handling exceptions and checking status

        type headless: bool
        """
        if not self.driver:
            self.init_browser(self.headless)

        loggedIn = False
        while not loggedIn:
            try:
                self.login_webauth(self.driver)
                find_n_click_xpath(self.driver,elements.ENROLLMENT_MENU) # exception here if can't log in
                loggedIn = True
                print('Successfully logged into WebReg!')
            except NoSuchElementException: # if login was unsuccessful...
                checkLoginSoup = BeautifulSoup(self.driver.page_source,'html.parser')
                self.webreg_login_status(checkLoginSoup,self.loginTimer)
            except Exception as e:
                print("Something went wrong during the login process:")
                print(f"{type(e)}: {e}")
                self.save_page(self.driver)