def click_font_dropdown(_step): dropdowns = [ drop for drop in world.css_find('.mce-listbox') if drop.text == 'Font Family' ] assert_equal(len(dropdowns), 1) dropdowns[0].click()
def verify_all_setting_entries(expected_entries): settings = world.browser.find_by_css('.wrapper-comp-setting') assert_equal(len(expected_entries), len(settings)) for (counter, setting) in enumerate(settings): world.verify_setting_entry(setting, expected_entries[counter][0], expected_entries[counter][1], expected_entries[counter][2])
def switch_view(_step, view): staff_status = world.css_find('#action-preview-select').first.value if staff_status != view: world.browser.select("select", view) world.wait_for_ajax_complete() assert_equal( world.css_find('#action-preview-select').first.value, view)
def verify_all_setting_entries(expected_entries): settings = world.browser.find_by_css('.wrapper-comp-setting') assert_equal(len(expected_entries), len(settings)) for (counter, setting) in enumerate(settings): world.verify_setting_entry( setting, expected_entries[counter][0], expected_entries[counter][1], expected_entries[counter][2] )
def _verify_page_names(first, second): world.wait_for( func=lambda _: len(world.css_find('.xmodule_StaticTabModule')) == 2, timeout=200, timeout_msg="Timed out waiting for two pages to be present") pages = world.css_find('.xmodule_StaticTabModule') assert_equal(pages[0].text, first) assert_equal(pages[1].text, second)
def use_code_editor(action): # Click on plugin button buttons = world.css_find('div.mce-widget>button') code_editor = [button for button in buttons if button.text == 'HTML'] assert_equal(1, len(code_editor)) code_editor[0].click() perform_action_in_plugin(action)
def use_code_editor(action): # Click on plugin button buttons = world.css_find('div.mce-widget>button') code_editor = [button for button in buttons if button.text == 'HTML'] assert_equal(1, len(code_editor)) code_editor[0].click() perform_action_in_plugin(action)
def check_role(_step, role): world.wait_for_present('iframe') location = world.scenario_dict['LTI'].location.html_id() iframe_name = 'ltiFrame-' + location with world.browser.get_iframe(iframe_name) as iframe: expected_role = 'Role: ' + role role = world.retry_on_exception( lambda: iframe.find_by_tag('h5').first.value, max_attempts=5, ignored_exceptions=ElementDoesNotExist) assert_equal(expected_role, role)
def check_role(_step, role): world.wait_for_present('iframe') location = world.scenario_dict['LTI'].location.html_id() iframe_name = 'ltiFrame-' + location with world.browser.get_iframe(iframe_name) as iframe: expected_role = 'Role: ' + role role = world.retry_on_exception( lambda: iframe.find_by_tag('h5').first.value, max_attempts=5, ignored_exceptions=ElementDoesNotExist ) assert_equal(expected_role, role)
def check_lti_popup(parent_window): # You should now have 2 browser windows open, the original courseware and the LTI windows = world.browser.windows assert_equal(len(windows), 2) # For verification, iterate through the window titles and make sure that # both are there. tabs = [] expected_tabs = [ u'LTI | Test Section | {course} Courseware | {platform}'.format( course=TEST_COURSE_NAME, platform=settings.PLATFORM_NAME), u'TEST TITLE' ] for window in windows: world.browser.switch_to_window(window) tabs.append(world.browser.title) assert_equal(tabs, expected_tabs) # Now verify the contents of the LTI window (which is the 2nd window/tab) # Note: The LTI opens in a new browser window, but Selenium sticks with the # current window until you explicitly switch to the context of the new one. world.browser.switch_to_window(windows[1]) url = world.browser.url basename = os.path.basename(url) pathname = os.path.splitext(basename)[0] assert_equal(pathname, u'correct_lti_endpoint') result = world.css_find('.result').first.text assert_equal(result, u'This is LTI tool. Success.') world.browser.driver.close() # Close the pop-up window world.browser.switch_to_window( parent_window) # Switch to the main window again
def check_lti_popup(parent_window): # You should now have 2 browser windows open, the original courseware and the LTI windows = world.browser.windows assert_equal(len(windows), 2) # For verification, iterate through the window titles and make sure that # both are there. tabs = [] expected_tabs = [ u'LTI | Test Section | {course} Courseware | {platform}'.format( course=TEST_COURSE_NAME, platform=settings.PLATFORM_NAME ), u'TEST TITLE' ] for window in windows: world.browser.switch_to_window(window) tabs.append(world.browser.title) assert_equal(tabs, expected_tabs) # Now verify the contents of the LTI window (which is the 2nd window/tab) # Note: The LTI opens in a new browser window, but Selenium sticks with the # current window until you explicitly switch to the context of the new one. world.browser.switch_to_window(windows[1]) url = world.browser.url basename = os.path.basename(url) pathname = os.path.splitext(basename)[0] assert_equal(pathname, u'correct_lti_endpoint') result = world.css_find('.result').first.text assert_equal(result, u'This is LTI tool. Success.') world.browser.driver.close() # Close the pop-up window world.browser.switch_to_window(parent_window) # Switch to the main window again
def _find_matching_button(category, component_type): """ Find the button with the specified text. There should be one and only one. """ # The tab shows buttons for the given category buttons = world.css_find(u'div.new-component-{} button'.format(category)) # Find the button whose text matches what you're looking for matched_buttons = [btn for btn in buttons if btn.text == component_type] # There should be one and only one assert_equal(len(matched_buttons), 1) return matched_buttons[0]
def _find_matching_button(category, component_type): """ Find the button with the specified text. There should be one and only one. """ # The tab shows buttons for the given category buttons = world.css_find('div.new-component-{} button'.format(category)) # Find the button whose text matches what you're looking for matched_buttons = [btn for btn in buttons if btn.text == component_type] # There should be one and only one assert_equal(len(matched_buttons), 1) return matched_buttons[0]
def cannot_edit_fail(_step): range_css = 'span.letter-grade' ranges = world.css_find(range_css) assert_equal(len(ranges), 2) assert_not_equal(ranges.last.value, 'Failure') # try to change the grade range -- this should throw an exception try: ranges.last.value = 'Failure' except InvalidElementStateException: pass # We should get this exception on failing to edit the element # check to be sure that nothing has changed ranges = world.css_find(range_css) assert_equal(len(ranges), 2) assert_not_equal(ranges.last.value, 'Failure')
def check_link_in_link_plugin(_step, path): # Ensure caret position is within the link just created. script = """ var editor = tinyMCE.activeEditor; editor.selection.select(editor.dom.select('a')[0]);""" world.browser.driver.execute_script(script) world.wait_for_ajax_complete() use_plugin( '.mce-i-link', lambda: assert_equal(path, world.css_find('.mce-textbox')[0].value) )
def check_link_in_link_plugin(_step, path): # Ensure caret position is within the link just created. script = """ var editor = tinyMCE.activeEditor; editor.selection.select(editor.dom.select('a')[0]);""" world.browser.driver.execute_script(script) world.wait_for_ajax_complete() use_plugin( '.mce-i-link', lambda: assert_equal(path, world.css_find('.mce-textbox')[0].value))
def check_toolbar_buttons(_step): dropdowns = world.css_find('.mce-listbox') assert_equal(2, len(dropdowns)) # Format dropdown assert_equal('Paragraph', dropdowns[0].text) # Font dropdown assert_equal('Font Family', dropdowns[1].text) buttons = world.css_find('.mce-ico') # Note that the code editor icon is not present because we are now showing text instead of an icon. # However, other test points user the code editor, so we have already verified its presence. expected_buttons = [ 'bold', 'italic', 'underline', 'forecolor', # This is our custom "code style" button, which uses an image instead of a class. 'none', 'alignleft', 'aligncenter', 'alignright', 'alignjustify', 'bullist', 'numlist', 'outdent', 'indent', 'blockquote', 'link', 'unlink', 'image' ] assert_equal(len(expected_buttons), len(buttons)) for index, button in enumerate(expected_buttons): class_names = buttons[index]._element.get_attribute('class') # pylint: disable=protected-access assert_equal("mce-ico mce-i-" + button, class_names)
def check_toolbar_buttons(_step): dropdowns = world.css_find('.mce-listbox') assert_equal(2, len(dropdowns)) # Format dropdown assert_equal('Paragraph', dropdowns[0].text) # Font dropdown assert_equal('Font Family', dropdowns[1].text) buttons = world.css_find('.mce-ico') # Note that the code editor icon is not present because we are now showing text instead of an icon. # However, other test points user the code editor, so we have already verified its presence. expected_buttons = [ 'bold', 'italic', 'underline', 'forecolor', # This is our custom "code style" button, which uses an image instead of a class. 'none', 'alignleft', 'aligncenter', 'alignright', 'alignjustify', 'bullist', 'numlist', 'outdent', 'indent', 'blockquote', 'link', 'unlink', 'image' ] assert_equal(len(expected_buttons), len(buttons)) for index, button in enumerate(expected_buttons): class_names = buttons[index]._element.get_attribute('class') # pylint: disable=protected-access assert_equal("mce-ico mce-i-" + button, class_names)
def font_selector_dropdown_is_shown(_step): font_panel = get_fonts_list_panel(world) expected_fonts = list(CUSTOM_FONTS.keys()) + list(TINYMCE_FONTS.keys()) actual_fonts = [font.strip() for font in font_panel.text.split('\n')] assert_equal(actual_fonts, expected_fonts)
def verify_setting_entry(setting, display_name, value, explicitly_set): """ Verify the capa module fields are set as expected in the Advanced Settings editor. Parameters ---------- setting: the WebDriverElement object found in the browser display_name: the string expected as the label html: the expected field value explicitly_set: True if the value is expected to have been explicitly set for the problem, rather than derived from the defaults. This is verified by the existence of a "Clear" button next to the field value. """ label_element = setting.find_by_css('.setting-label')[0] assert_equal(display_name, label_element.html.strip()) label_for = label_element['for'] # Check if the web object is a list type # If so, we use a slightly different mechanism for determining its value if setting.has_class('metadata-list-enum') or setting.has_class('metadata-dict') or setting.has_class('metadata-video-translations'): list_value = ', '.join(ele.value for ele in setting.find_by_css('.list-settings-item')) assert_equal(value, list_value) elif setting.has_class('metadata-videolist-enum'): list_value = ', '.join(ele.find_by_css('input')[0].value for ele in setting.find_by_css('.videolist-settings-item')) assert_equal(value, list_value) else: assert_equal(value, setting.find_by_id(label_for).value) # VideoList doesn't have clear button if not setting.has_class('metadata-videolist-enum'): settingClearButton = setting.find_by_css('.setting-clear')[0] assert_equal(explicitly_set, settingClearButton.has_class('active')) assert_equal(not explicitly_set, settingClearButton.has_class('inactive'))
def verify_code_editor_text(_step, text): use_code_editor( lambda: assert_equal(text, get_codemirror_value(0, CODEMIRROR_SELECTOR_PREFIX)) )
def verify_problem_display_name(_step, name): """ name is uppercased because the heading styles are uppercase in css """ assert_equal(name, world.browser.find_by_css('.problem-header').text)
def check_link_in_image_plugin(_step, path): use_plugin( '.mce-i-image', lambda: assert_equal(path, world.css_find('.mce-textbox')[0].value))
def font_selector_dropdown_is_shown(_step): font_panel = get_fonts_list_panel(world) expected_fonts = list(CUSTOM_FONTS.keys()) + list(TINYMCE_FONTS.keys()) actual_fonts = [font.strip() for font in font_panel.text.split('\n')] assert_equal(actual_fonts, expected_fonts)
def view_grade_slider(_step, how_many): grade_slider_css = '.grade-specific-bar' all_grades = world.css_find(grade_slider_css) assert_equal(len(all_grades), int(how_many))
def page_is_visible_or_hidden(step, page_id, visible_or_hidden): hidden = visible_or_hidden == "hidden" assert_equal( world.css_find(CSS_FOR_TAB_ELEMENT.format(page_id)).checked, hidden)
def high_level_source_in_editor(_step): open_high_level_source() assert_equal('hi', world.css_value('.source-edit-box'))
def see_pages_in_expected_order(page_names_in_expected_order): pages = world.css_find("li.course-tab") assert_equal(len(page_names_in_expected_order), len(pages)) for i, page_name in enumerate(page_names_in_expected_order): assert_in(page_name, pages[i].text)
def verify_code_editor_text(_step, text): use_code_editor(lambda: assert_equal( text, get_codemirror_value(0, CODEMIRROR_SELECTOR_PREFIX)))
def check_component_display_name(step, display_name): # The display name for the unit uses the same structure, must differentiate by level-element. label = world.css_html(".level-element>header>div>div>span.xblock-display-name") assert_equal(display_name, label)
def high_level_source_in_editor(_step): open_high_level_source() assert_equal('hi', world.css_value('.source-edit-box'))
def click_font_dropdown(_step): dropdowns = [drop for drop in world.css_find('.mce-listbox') if drop.text == 'Font Family'] assert_equal(len(dropdowns), 1) dropdowns[0].click()
def check_raw_editor_text(step): assert_equal(step.multiline, get_codemirror_value(0))
def check_component_display_name(step, display_name): # The display name for the unit uses the same structure, must differentiate by level-element. label = world.css_html( ".level-element>header>div>div>span.xblock-display-name") assert_equal(display_name, label)
def switch_view(_step, view): staff_status = world.css_find('#action-preview-select').first.value if staff_status != view: world.browser.select("select", view) world.wait_for_ajax_complete() assert_equal(world.css_find('#action-preview-select').first.value, view)
def see_graph(_step, progress): assert_equal( progress, world.css_find('#grade-detail-graph .overallGrade').first.text.split( '\n')[1])
def check_raw_editor_text(step): assert_equal(step.multiline, get_codemirror_value(0))
def see_graph(_step, progress): assert_equal(progress, world.css_find('#grade-detail-graph .overallGrade').first.text.split('\n')[1])
def verify_weight(_step, weight): weight_id = '#course-grading-assignment-gradeweight' assert_equal(world.css_value(weight_id, -1), weight)
def see_a_static_page_named_foo(step, name): pages_css = 'div.xmodule_StaticTabModule' page_name_html = world.css_html(pages_css) assert_equal(page_name_html.strip(), name)
def verify_setting_entry(setting, display_name, value, explicitly_set): """ Verify the capa module fields are set as expected in the Advanced Settings editor. Parameters ---------- setting: the WebDriverElement object found in the browser display_name: the string expected as the label html: the expected field value explicitly_set: True if the value is expected to have been explicitly set for the problem, rather than derived from the defaults. This is verified by the existence of a "Clear" button next to the field value. """ label_element = setting.find_by_css('.setting-label')[0] assert_equal(display_name, label_element.html.strip()) label_for = label_element['for'] # Check if the web object is a list type # If so, we use a slightly different mechanism for determining its value if setting.has_class('metadata-list-enum') or setting.has_class( 'metadata-dict') or setting.has_class( 'metadata-video-translations'): list_value = ', '.join( ele.value for ele in setting.find_by_css('.list-settings-item')) assert_equal(value, list_value) elif setting.has_class('metadata-videolist-enum'): list_value = ', '.join( ele.find_by_css('input')[0].value for ele in setting.find_by_css('.videolist-settings-item')) assert_equal(value, list_value) else: assert_equal(value, setting.find_by_id(label_for).value) # VideoList doesn't have clear button if not setting.has_class('metadata-videolist-enum'): settingClearButton = setting.find_by_css('.setting-clear')[0] assert_equal(explicitly_set, settingClearButton.has_class('active')) assert_equal(not explicitly_set, settingClearButton.has_class('inactive'))
def changes_not_persisted(step): reload_the_page(step) name_id = '#course-grading-assignment-name' assert_equal(world.css_value(name_id), 'Homework')
def i_see_highest_grade_range(_step, range_name): range_css = 'span.letter-grade' grade = world.css_find(range_css).first assert_equal(grade.value, range_name)
def verify_problem_display_name(_step, name): """ name is uppercased because the heading styles are uppercase in css """ assert_equal(name, world.browser.find_by_css('.problem-header').text)