def log_in(self): app.logger.info('Logging in to Canvas') self.hit_homepage() self.wait_for_element_and_type(CalNetPage.USERNAME_INPUT, 'PLEASE LOG IN MANUALLY') Wait(self.driver, util.get_long_timeout()).until( ec.presence_of_element_located(CanvasPage.ADMIN_LINK))
def wait_for_most_recent_job_success(self, async_job): app.logger.info(f'Waiting for {async_job} to succeed') time.sleep(2) tries = 1 retries = util.get_long_timeout() success = By.XPATH, f'{JobsPage.job_most_recent_locator(async_job)[1]}//i[contains(@class, "light-green--text")]' failure = By.XPATH, f'{JobsPage.job_most_recent_locator(async_job)[1]}//i[contains(@class, "red--text")]' while tries <= retries: tries += 1 try: if self.is_present(success): app.logger.info('Job succeeded') break else: if self.is_present(JobsPage.ERROR_REDIRECT): self.load_page() Wait(self.driver, 1).until(ec.visibility_of_element_located(failure)) app.logger.info('Job failed') break except TimeoutException: if tries == retries: raise else: time.sleep(1) Wait(self.driver, 1).until(ec.visibility_of_element_located(success))
def provision_site(self, section, section_ids, site): epoch = int(time.time()) site.name = f'{site.name} {epoch}' site.code = f'{site.code} {epoch}' app.logger.info( f'Creating a site named {site.code} for {section.code} sections {section_ids}' ) # Load tool admin_id = app.config['CANVAS_ADMIN_ID'] tool_id = app.config['CANVAS_SITE_CREATION_TOOL'] self.driver.get( f'{app.config["CANVAS_BASE_URL"]}/users/{admin_id}/external_tools/{tool_id}' ) Wait(self.driver, util.get_medium_timeout()).until( ec.presence_of_element_located(CanvasPage.junction_form_loc())) self.hide_canvas_footer() Wait(self.driver, util.get_medium_timeout()).until( ec.frame_to_be_available_and_switch_to_it(CanvasPage.FRAME)) Wait(self.driver, util.get_medium_timeout()).until( ec.visibility_of_element_located(CanvasPage.CREATE_SITE_LINK)) self.wait_for_element_and_click(CanvasPage.CREATE_SITE_LINK) # Select sections by CCN self.wait_for_element(CanvasPage.SWITCH_TO_CCN_BUTTON, util.get_long_timeout()) self.wait_for_page_and_click(CanvasPage.SWITCH_TO_CCN_BUTTON) self.wait_for_page_and_click(CanvasPage.term_loc()) self.wait_for_element_and_type(CanvasPage.CCN_TEXT_AREA, ', '.join(section_ids)) self.wait_for_page_and_click(CanvasPage.REVIEW_CCNS_BUTTON) self.wait_for_page_and_click(CanvasPage.NEXT_BUTTON) # Name and create site; store site ID self.scroll_to_bottom() self.wait_for_element_and_type(CanvasPage.SITE_NAME_INPUT, f'{site.name}') self.wait_for_element_and_type(CanvasPage.SITE_ABBREV_INPUT, f'{site.code}') self.wait_for_page_and_click(CanvasPage.CREATE_SITE_BUTTON) Wait(self.driver, util.get_long_timeout()).until(ec.url_contains('/courses/')) parts = self.driver.current_url.split('/') site.site_id = [i for i in parts if i][-1] app.logger.info(f'Site {site.code} ID is {site.site_id}') section.sites.append(site)
def wait_for_page_and_click_js(self, locator, addl_pause=0): self.wait_for_element(locator, util.get_long_timeout()) self.click_element_js(locator, addl_pause)
def wait_for_title(self, string): app.logger.info(f'Waiting for page title \'{string}\'') Wait(self.driver, util.get_long_timeout()).until((ec.title_is(string)))