def log_in_via_calnet(self): app.logger.info('Logging in to Kaltura') self.driver.get(f'{app.config["KALTURA_MEDIA_SPACE_URL"]}/user/login') self.wait_for_element_and_type(CalNetPage.USERNAME_INPUT, 'PLEASE LOG IN MANUALLY') Wait(self.driver, util.get_medium_timeout()).until( ec.presence_of_element_located(KalturaPage.LOG_OUT_LINK))
def delete_site(self, site_id): app.logger.info(f'Deleting course site ID {site_id}') self.driver.get( f'{app.config["CANVAS_BASE_URL"]}/courses/{site_id}/confirm_action?event=delete' ) self.wait_for_page_and_click_js(CanvasPage.DELETE_COURSE_BUTTON) Wait(self.driver, util.get_medium_timeout()).until( ec.visibility_of_element_located(CanvasPage.DELETE_COURSE_SUCCESS))
def load_my_media_tool(self, site): app.logger.info(f'Loading My Media on site ID {site.site_id}') tool_id = app.config['CANVAS_MY_MEDIA_TOOL'] self.driver.get( f'{app.config["CANVAS_BASE_URL"]}/courses/{site.site_id}/external_tools/{tool_id}' ) Wait(self.driver, util.get_medium_timeout()).until( ec.presence_of_element_located(CanvasPage.kaltura_form_loc()))
def load_site(self, site_id): app.logger.info(f'Loading course site ID "{site_id}"') self.driver.get(f'{app.config["CANVAS_BASE_URL"]}/courses/{site_id}') Wait(self.driver, util.get_medium_timeout()).until(ec.url_contains(site_id)) if self.is_present(CanvasPage.ACCEPT_INVITE_BUTTON): self.wait_for_element_and_click(CanvasPage.ACCEPT_INVITE_BUTTON) self.when_not_present(CanvasPage.ACCEPT_INVITE_BUTTON)
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 is_tool_configured(self, tool_id): self.driver.get( f'{app.config["CANVAS_BASE_URL"]}/api/v1/accounts/{app.config["CANVAS_ROOT_ACCOUNT"]}/external_tools/{tool_id}' ) loc = By.XPATH, '//pre' Wait(self.driver, util.get_medium_timeout()).until( ec.presence_of_element_located(loc)) json_string = self.element(loc).text return True if f'{app.config["KALTURA_TOOL_URL"]}' in json_string else False
def masquerade_as(self, user, site_id=None): app.logger.info(f'Masquerading as Canvas ID {user.canvas_id}') self.driver.get( f'{app.config["CANVAS_BASE_URL"]}/users/{user.canvas_id}/masquerade' ) self.wait_for_element_and_click(CanvasPage.MASQUERADE_LINK) Wait(self.driver, util.get_medium_timeout()).until( ec.visibility_of_element_located(CanvasPage.STOP_MASQUERADE_LINK)) if site_id: self.load_site(site_id)
def delete_series(self, recording_schedule): app.logger.info('Clicking the delete button') self.load_event_edit_page(recording_schedule.series_id) self.wait_for_element(KalturaPage.SERIES_DELETE_BUTTON, util.get_medium_timeout()) self.scroll_to_bottom() self.wait_for_page_and_click(KalturaPage.SERIES_DELETE_BUTTON, 3) self.wait_for_element_and_click( KalturaPage.SERIES_DELETE_CONFIRM_BUTTON) redirect_url = f'{app.config["KALTURA_MEDIA_SPACE_URL"]}/calendar/index/calendar/' Wait(self.driver, util.get_short_timeout()).until(ec.url_to_be(redirect_url))
def log_in(self): app.logger.info('Logging in to email') self.driver.get('https://login.yahoo.com') self.wait_for_element_and_type_js('login-username', app.config['XENA_EMAIL_USERNAME']) self.click_element_js(EmailPage.NEXT_BUTTON, 2) self.wait_for_element_and_type_js('login-passwd', app.config['XENA_EMAIL_PASSWORD']) self.click_element_js(EmailPage.NEXT_BUTTON, 2) Wait(self.driver, util.get_medium_timeout()).until( ec.presence_of_element_located(EmailPage.LOG_OUT_LINK)) time.sleep(1)
def enable_tool(self, site, tool): if self.is_present(CanvasPage.tool_nav_link_locator(tool)): app.logger.info(f'{tool} is already enabled') else: app.logger.info(f'Enabling {tool} on site ID {site.site_id}') self.driver.get( f'{app.config["CANVAS_BASE_URL"]}/courses/{site.site_id}/settings' ) self.wait_for_page_and_click(CanvasPage.NAVIGATION_LINK) self.hide_canvas_footer() self.wait_for_element_and_click( CanvasPage.disabled_tool_locator(tool)) self.wait_for_element_and_click( CanvasPage.enable_tool_link_locator(tool)) Wait(self.driver, util.get_medium_timeout()).until( ec.visibility_of_element_located( CanvasPage.enabled_tool_locator(tool)), ) self.wait_for_element_and_click(CanvasPage.TOOL_SAVE_BUTTON) Wait(self.driver, util.get_medium_timeout()).until( ec.visibility_of_element_located( CanvasPage.tool_nav_link_locator(tool)), )
def delete_all_messages(self): self.load_page() if self.elements(EmailPage.MESSAGE_ROW): app.logger.info('Deleting all messages') self.wait_for_page_and_click_js(EmailPage.SELECT_ALL_CBX, 2) self.wait_for_page_and_click_js(EmailPage.DELETE_BUTTON, 2) Wait(self.driver, util.get_medium_timeout()).until( ec.invisibility_of_element_located(EmailPage.MESSAGE_ROW)) elif self.is_present(EmailPage.EMPTY_FOLDER): app.logger.info('There are no messages to delete') else: app.logger.warning( 'Unable to tell if there are messages in the inbox')
def wait_for_title(self, string): app.logger.info(f"'Waiting for page title '{string}'") Wait(self.driver, util.get_medium_timeout()).until( method=(ec.title_is(string)), message=f'Failed wait_for_title: {string}', )
def wait_for_publish_category_el(self): self.wait_for_element(KalturaPage.SERIES_CATEGORY_ROW, util.get_medium_timeout())
def confirm_unscheduling_ineligible(self, recording_schedule): self.click_unschedule_button() self.wait_for_element_and_click(SignUpPage.UNSCHEDULE_CONFIRM_BUTTON) Wait(self.driver, util.get_medium_timeout()).until(ec.visibility_of_element_located(SignUpPage.OPTED_OUT)) recording_schedule.scheduling_status = RecordingSchedulingStatus.NOT_SCHEDULED
def wait_for_page_and_click_js(self, locator, addl_pause=None): self.wait_for_element(locator, util.get_medium_timeout()) self.click_element_js(locator, addl_pause)
def wait_for_title_containing(self, string): Wait(self.driver, util.get_medium_timeout()).until(ec.title_contains(string))
def stop_masquerading(self): app.logger.info('Ending masquerade') self.hit_homepage() self.wait_for_page_and_click(CanvasPage.STOP_MASQUERADE_LINK) Wait(self.driver, util.get_medium_timeout()).until(ec.staleness_of)
def wait_for_404(self): Wait(self.driver, util.get_medium_timeout()).until(ec.url_contains('404'))
def click_my_media_tool(self): app.logger.info('Clicking the My Media LTI tool') self.hide_canvas_footer() self.wait_for_page_and_click(CanvasPage.MY_MEDIA_LINK) Wait(self.driver, util.get_medium_timeout()).until( ec.presence_of_element_located(CanvasPage.kaltura_form_loc()))