def assert_answer_mark(_step, problem_type, isnt_marked, correctness): """ Assert that the expected answer mark is visible for a given problem type. *problem_type* is a string identifying the type of problem (e.g. 'drop down') *correctness* is in ['correct', 'incorrect', 'unanswered'] """ # Determine which selector(s) to look for based on correctness assert(correctness in ['correct', 'incorrect', 'unanswered']) assert(problem_type in PROBLEM_DICT) # At least one of the correct selectors should be present for sel in PROBLEM_DICT[problem_type][correctness]: if bool(isnt_marked): world.wait_for(lambda _: world.is_css_not_present(sel)) # pylint: disable=cell-var-from-loop has_expected = world.is_css_not_present(sel) else: world.css_find(sel) # css_find includes a wait_for pattern has_expected = world.is_css_present(sel) # As soon as we find the selector, break out of the loop if has_expected: break # Expect that we found the expected selector assert(has_expected)
def verify_high_level_source_links(step, visible): if visible: assert_true(world.is_css_present('.launch-latex-compiler'), msg="Expected to find the latex button but it is not present.") else: assert_true(world.is_css_not_present('.launch-latex-compiler'), msg="Expected not to find the latex button but it is present.") world.cancel_component(step) if visible: assert_true(world.is_css_present('.upload-button'), msg="Expected to find the upload button but it is not present.") else: assert_true(world.is_css_not_present('.upload-button'), msg="Expected not to find the upload button but it is present.")
def shows_captions(_step, video_type, show_captions): # Prevent cookies from overriding course settings world.browser.cookies.delete('hide_captions') if show_captions == 'does not': assert world.css_has_class('.%s' % video_type, 'closed') else: assert world.is_css_not_present('.%s.closed' % video_type)
def i_see_button(_step, not_see, button_type): button = button_type.strip() if not_see.strip(): assert world.is_css_not_present(TRANSCRIPTS_BUTTONS[button][0]) else: assert world.css_has_text(TRANSCRIPTS_BUTTONS[button][0], TRANSCRIPTS_BUTTONS[button][1])
def shows_captions(step, show_captions): # Prevent cookies from overriding course settings world.browser.cookies.delete('hide_captions') if show_captions == 'does not': assert world.css_find('.video')[0].has_class('closed') else: assert world.is_css_not_present('.video.closed')
def shows_captions(step, show_captions): # Prevent cookies from overriding course settings world.browser.cookies.delete("hide_captions") if show_captions == "does not": assert world.css_has_class(".video", "closed") else: assert world.is_css_not_present(".video.closed")
def marked_as_admin(_step, name, inverted): flag_css = '.user-item[data-email="{email}"] .flag-role.flag-role-admin'.format( email=name+EMAIL_EXTENSION) if inverted: assert world.is_css_not_present(flag_css) else: assert world.is_css_present(flag_css)
def marked_as_admin(_step, name, inverted): flag_css = '.user-item[data-email="{email}"] .flag-role.flag-role-admin'.format( email=name + EMAIL_EXTENSION) if inverted: assert world.is_css_not_present(flag_css) else: assert world.is_css_present(flag_css)
def shows_captions(step, show_captions): # Prevent cookies from overriding course settings world.browser.cookies.delete('hide_captions') if show_captions == 'does not': assert world.css_has_class('.video', 'closed') else: assert world.is_css_not_present('.video.closed')
def marked_as_admin(_step, name, not_marked_admin): flag_css = '.user-item[data-email="{name}@edx.org"] .flag-role.flag-role-admin'.format( name=name) if not_marked_admin: assert world.is_css_not_present(flag_css) else: assert world.is_css_present(flag_css)
def set_captions_visibility_state(_step, captions_state): SELECTOR = ".closed .subtitles" if world.is_css_not_present(SELECTOR): if captions_state == "closed": world.css_click(".hide-subtitles") else: if captions_state != "closed": world.css_click(".hide-subtitles")
def set_captions_visibility_state(_step, captions_state): SELECTOR = '.closed .subtitles' if world.is_css_not_present(SELECTOR, wait_time=30): if captions_state == 'closed': world.css_click('.hide-subtitles') else: if captions_state != 'closed': world.css_click('.hide-subtitles')
def see_course(_step, do_not_see, gender='self'): class_css = 'h3.course-title' if do_not_see: assert world.is_css_not_present(class_css) else: all_courses = world.css_find(class_css) all_names = [item.html for item in all_courses] assert_in(world.scenario_dict['COURSE'].display_name, all_names)
def check_not_there(_step, file_name): # Either there are no files, or there are files but # not the one I expect not to exist. # Since our only test for deletion right now deletes # the only file that was uploaded, our success criteria # will be that there are no files. # In the future we can refactor if necessary. assert world.is_css_not_present(ASSET_NAMES_CSS)
def check_lti_component_no_elem(_step, text): selector_map = { 'a launch button': '.link_lti_new_window', 'an provider iframe': '.ltiLaunchFrame', 'feedback': '.problem-feedback', 'progress': '.problem-progress', } assert_in(text, selector_map) assert_true(world.is_css_not_present(selector_map[text]))
def set_captions_visibility_state(_step, captions_state): SELECTOR = '.closed .subtitles' world.wait_for_visible('.hide-subtitles') if captions_state == 'closed': if world.is_css_not_present(SELECTOR): world.css_find('.hide-subtitles').click() else: if world.is_css_present(SELECTOR): world.css_find('.hide-subtitles').click()
def i_see_button_with_custom_text(_step, not_see, button_type, custom_text, index): button = button_type.strip() custom_text = custom_text.strip() index = int(index.strip()) - 1 if not_see.strip(): assert world.is_css_not_present(TRANSCRIPTS_BUTTONS[button][0]) else: assert world.css_has_text(TRANSCRIPTS_BUTTONS[button][0], TRANSCRIPTS_BUTTONS[button][1].format(custom_text), index)
def set_captions_visibility_state(_step, captions_state): SELECTOR = ".closed .subtitles" world.wait_for_visible(".hide-subtitles") if captions_state == "closed": if world.is_css_not_present(SELECTOR): world.css_find(".hide-subtitles").click() else: if world.is_css_present(SELECTOR): world.css_find(".hide-subtitles").click()
def shows_captions(_step, show_captions): if show_captions == 'does not': assert world.is_css_present('div.video.closed') else: assert world.is_css_not_present('div.video.closed') # Prevent cookies from overriding course settings world.browser.cookies.delete('hide_captions') world.browser.cookies.delete('current_player_mode')
def check_problem(step): # first scroll down so the loading mathjax button does not # cover up the Check button world.browser.execute_script("window.scrollTo(0,1024)") assert world.is_css_not_present("button.check.is-disabled") world.css_click("button.check") # Wait for the problem to finish re-rendering world.wait_for_ajax_complete()
def check_not_there(_step, file_name): # Either there are no files, or there are files but # not the one I expect not to exist. # Since our only test for deletion right now deletes # the only file that was uploaded, our success criteria # will be that there are no files. # In the future we can refactor if necessary. assert(world.is_css_not_present(ASSET_NAMES_CSS))
def check_lti_component_no_elem(_step, text): selector_map = { "a launch button": ".link_lti_new_window", "an provider iframe": ".ltiLaunchFrame", "feedback": ".problem-feedback", "progress": ".problem-progress", } assert_in(text, selector_map) assert_true(world.is_css_not_present(selector_map[text]))
def can_make_course_admin(_step, inverted, outer_capture, name): if outer_capture == "myself": email = world.scenario_dict["USER"].email else: email = name + EMAIL_EXTENSION add_button_css = '.user-item[data-email="{email}"] .add-admin-role'.format(email=email) if inverted: assert world.is_css_not_present(add_button_css) else: assert world.is_css_present(add_button_css)
def not_see_page(step, page): # Either there are no pages, or there are pages but # not the one I expect not to exist. # Since our only test for deletion right now deletes # the only static page that existed, our success criteria # will be that there are no static pages. # In the future we can refactor if necessary. tabs_css = 'li.component' assert (world.is_css_not_present(tabs_css, wait_time=30))
def i_see_button(_step, not_see, button_type): world.wait(DELAY) world.wait_for_ajax_complete() button = button_type.strip() if not_see.strip(): assert world.is_css_not_present(TRANSCRIPTS_BUTTONS[button][0]) else: assert world.css_has_text(TRANSCRIPTS_BUTTONS[button][0], TRANSCRIPTS_BUTTONS[button][1])
def can_make_course_admin(_step, can_not_make_admin, outer_capture, name): if outer_capture == "myself": email = world.scenario_dict["USER"].email else: email = name + '@edx.org' add_button_css = '.user-item[data-email="{email}"] .add-admin-role'.format(email=email) if can_not_make_admin: assert world.is_css_not_present(add_button_css) else: assert world.is_css_present(add_button_css)
def shows_captions(_step, show_captions): world.wait_for_js_variable_truthy("Video") world.wait(0.5) if show_captions == "does not": assert world.is_css_present("div.video.closed") else: assert world.is_css_not_present("div.video.closed") # Prevent cookies from overriding course settings world.browser.cookies.delete("hide_captions") world.browser.cookies.delete("current_player_mode")
def check_visibility(self, step, visible): r"the conditional contents are (?P<visible>\w+)$" world.wait_for_ajax_complete() assert_in(visible, ("visible", "hidden")) if visible == "visible": world.wait_for_visible(".hidden-contents") assert_true(world.css_visible(".hidden-contents")) else: assert_true(world.is_css_not_present(".hidden-contents"))
def shows_captions(_step, show_captions): world.wait_for_js_variable_truthy("Video") world.wait(0.5) if show_captions == 'does not': assert_true(world.is_css_present('div.video.closed')) else: assert_true(world.is_css_not_present('div.video.closed')) # Prevent cookies from overriding course settings world.browser.cookies.delete('hide_captions') world.browser.cookies.delete('current_player_mode')
def check_visibility(self, step, visible): r'the conditional contents are (?P<visible>\w+)$' world.wait_for_ajax_complete() assert_in(visible, ('visible', 'hidden')) if visible == 'visible': world.wait_for_visible('.hidden-contents') assert_true(world.css_visible('.hidden-contents')) else: assert_true(world.is_css_not_present('.hidden-contents'))
def check_visibility(self, step, visible): r'the conditional contents are (?P<visible>\w+)$' world.wait_for_ajax_complete() assert_in(visible, ('visible', 'hidden')) if visible == 'visible': world.wait_for_visible('.hidden-contents') assert_true(world.css_visible('.hidden-contents')) else: assert_true(world.is_css_not_present('.hidden-contents')) assert_true(world.css_contains_text('.conditional-message', 'must be attempted before this will become visible.')) # sarina
def upload_file(filename, sub_path=''): # The file upload dialog is a faux modal, a div that takes over the display attach_file(filename, sub_path) modal_css = 'div.wrapper-modal-window-assetupload' button_css = '{} .action-upload'.format(modal_css) world.css_click(button_css) # Clicking the Upload button triggers an AJAX POST. world.wait_for_ajax_complete() # The modal stays up with a "File uploaded succeeded" confirmation message, then goes away. # It should take under 2 seconds, so wait up to 10. # Note that is_css_not_present will return as soon as the element is gone. assert world.is_css_not_present(modal_css, wait_time=10)
def lti_is_not_rendered(_step): # lti div has no class rendered assert world.is_css_not_present('div.lti.rendered') # error is shown assert world.css_visible('.error_message') # iframe is not visible assert not world.css_visible('iframe') #inside iframe test content is not presented with world.browser.get_iframe('ltiLaunchFrame') as iframe: # iframe does not contain functions from terrain/ui_helpers.py assert iframe.is_element_not_present_by_css('.result', wait_time=5)
def lti_is_not_rendered(_step): # lti div has no class rendered assert world.is_css_not_present('div.lti.rendered') # error is shown assert world.css_visible('.error_message') # iframe is not visible assert not world.css_visible('iframe') #inside iframe test content is not presented with world.browser.get_iframe('ltiLaunchFrame') as iframe: # iframe does not contain functions from terrain/ui_helpers.py world.browser.driver.implicitly_wait(1) try: assert iframe.is_element_not_present_by_css('.result', wait_time=1) except: raise finally: world.browser.driver.implicitly_wait(world.IMPLICIT_WAIT)
def see_no_components(steps): assert world.is_css_not_present('li.component')
def action_button_present(_step, buttonname, doesnt_appear): button_css = 'section.action input[value*="%s"]' % buttonname if doesnt_appear: assert world.is_css_not_present(button_css) else: assert world.is_css_present(button_css)
def see_no_components(steps): assert world.is_css_not_present('li.studio-xblock-wrapper')
def i_should_see_that_course_in_my_dashboard(_step, doesnt_appear, course): course_link_css = '.my-courses a[href*="%s"]' % course if doesnt_appear: assert world.is_css_not_present(course_link_css) else: assert world.is_css_present(course_link_css)
def video_takes_a_single_click(_step): component_css = '.xmodule_VideoModule' assert world.is_css_not_present(component_css) world.css_click("a[data-category='video']") assert world.is_css_present(component_css)
def not_see_any_static_pages(step): pages_css = 'div.xmodule_StaticTabModule' assert (world.is_css_not_present(pages_css, wait_time=30))
def no_student_profile_table(step): # pylint: disable=unused-argument world.is_css_not_present('input[name="list-profiles"]')