def css_has_value(css_selector, value, index=0): """ Return a boolean indicating whether the element with `css_selector` has the specified `value`. If there are multiple elements matching the css selector, use `index` to indicate which one. """ # If we're expecting a non-empty string, give the page # a chance to fill in values if value: world.wait_for(lambda _: world.css_value(css_selector, index=index)) return world.css_value(css_selector, index=index) == value
def css_has_value(css_selector, value, index=0, allow_blank=False): """ Return a boolean indicating whether the element with `css_selector` has the specified `value`. If `allow_blank` is False, wait for the element to have a value that is a non-empty string. If there are multiple elements matching the css selector, use `index` to indicate which one. """ if not allow_blank: world.wait_for(lambda _: world.css_value(css_selector, index=index)) return world.css_value(css_selector, index=index) == value
def get_type_index(name): name_id = '#course-grading-assignment-name' all_types = world.css_find(name_id) for index in range(len(all_types)): if world.css_value(name_id, index=index) == name: return index return -1
def check_transcripts_field(_step, values, field_name): world.select_editor_tab("Advanced") tab = world.css_find("#settings-tab").first field_id = "#" + tab.find_by_xpath('.//label[text()="%s"]' % field_name.strip())[0]["for"] values_list = [i.strip() == world.css_value(field_id) for i in values.split("|")] assert any(values_list) world.select_editor_tab("Basic")
def set_weight(step, weight): weight_id = '#course-grading-assignment-gradeweight' weight_field = world.css_find(weight_id)[-1] old_weight = world.css_value(weight_id, -1) for count in range(len(old_weight)): weight_field._element.send_keys(Keys.END, Keys.BACK_SPACE) weight_field._element.send_keys(weight)
def try_click(): image_selector = "#imageinput_i4x-{0.org}-{0.course}-problem-image_2_1".format(section_loc) input_selector = "#input_i4x-{0.org}-{0.course}-problem-image_2_1".format(section_loc) world.browser.execute_script('$("body").on("click", function(event) {console.log(event);})') initial_input = world.css_value(input_selector) world.wait_for_visible(image_selector) image = world.css_find(image_selector).first (image.action_chains .move_to_element(image._element) .move_by_offset(offset, offset) .click() .perform()) world.wait_for(lambda _: world.css_value(input_selector) != initial_input)
def check_transcripts_field(_step, values, field_name): world.select_editor_tab('Advanced') tab = world.css_find('#settings-tab').first; field_id = '#' + tab.find_by_xpath('.//label[text()="%s"]' % field_name.strip())[0]['for'] values_list = [i.strip() == world.css_value(field_id) for i in values.split('|')] assert any(values_list) world.select_editor_tab('Basic')
def try_click(): problem_html_loc = section_loc.course_key.make_usage_key('problem', 'image').html_id() image_selector = "#imageinput_{}_2_1".format(problem_html_loc) input_selector = "#input_{}_2_1".format(problem_html_loc) world.browser.execute_script('$("body").on("click", function(event) {console.log(event);})') # pylint: disable=unicode-format-string initial_input = world.css_value(input_selector) world.wait_for_visible(image_selector) image = world.css_find(image_selector).first (image.action_chains .move_to_element(image._element) .move_by_offset(offset, offset) .click() .perform()) world.wait_for(lambda _: world.css_value(input_selector) != initial_input)
def get_index_of(expected_key): for i, element in enumerate(world.css_find(KEY_CSS)): # Sometimes get stale reference if I hold on to the array of elements key = world.css_value(KEY_CSS, index=i) if key == expected_key: return i return -1
def get_index_of(expected_key): for counter in range(len(world.css_find(KEY_CSS))): # Sometimes get stale reference if I hold on to the array of elements key = world.css_value(KEY_CSS, index=counter) if key == expected_key: return counter return -1
def set_the_max_attempts(step, max_attempts_set): # on firefox with selenium, the behaviour is different. eg 2.34 displays as 2.34 and is persisted as 2 index = world.get_setting_entry_index(MAXIMUM_ATTEMPTS) world.css_fill('.wrapper-comp-setting .setting-input', max_attempts_set, index=index) if world.is_firefox(): world.trigger_event('.wrapper-comp-setting .setting-input', index=index) world.save_component_and_reopen(step) value = int(world.css_value('input.setting-input', index=index)) assert value >= 0
def check_transcripts_field(_step, values, field_name): world.wait(DELAY) world.wait_for_ajax_complete() world.click_link_by_text('Advanced') field_id = '#' + world.browser.find_by_xpath('//label[text()="%s"]' % field_name.strip())[0]['for'] values_list = [i.strip() == world.css_value(field_id) for i in values.split('|')] assert any(values_list) world.click_link_by_text('Basic')
def set_the_max_attempts(step, max_attempts_set): # on firefox with selenium, the behavior is different. # eg 2.34 displays as 2.34 and is persisted as 2 index = world.get_setting_entry_index(MAXIMUM_ATTEMPTS) world.set_field_value(index, max_attempts_set) world.save_component_and_reopen(step) value = world.css_value('input.setting-input', index=index) assert value != "", "max attempts is blank" assert int(value) >= 0
def check_transcripts_field(_step, values, field_name): world.click_link_by_text("Advanced") field_id = "#" + world.browser.find_by_xpath('//label[text()="%s"]' % field_name.strip())[0]["for"] values_list = [i.strip() == world.css_value(field_id) for i in values.split("|")] assert any(values_list) world.click_link_by_text("Basic")
def get_display_name_value(): index = get_index_of(DISPLAY_NAME_KEY) return world.css_value(VALUE_CSS, index=index)
def i_see_complete_section_name_with_quote_in_editor(_step): css = '.section-name-edit input[type=text]' assert world.is_css_present(css) assert_equal(world.css_value(css), 'Section with "Quote"')
def i_see_the_span_with_text(step, text): span_locator = '.toggle-button-sections span' assert_true(world.is_css_present(span_locator)) assert_equal(world.css_value(span_locator), text) assert_true(world.css_visible(span_locator))
def high_level_source_in_editor(step): open_high_level_source() assert_equal('hi', world.css_value('.source-edit-box'))
def image_url_present(_step): field_css = '#course-image-url' expected_value = 'image.jpg' assert world.css_value(field_css).endswith(expected_value)
def i_see_complete_subsection_name_with_quote_in_editor(step): css = '.subsection-display-name-input' assert world.is_css_present(css) assert_equal(world.css_value(css), 'Subsection With "Quote"')
def image_url_present(_step): field_css = "#course-image-url" expected_value = "/c4x/MITx/999/asset/image.jpg" assert world.css_value(field_css) == expected_value
def image_url_present(_step): field_css = '#course-image-url' expected_value = '/c4x/MITx/999/asset/image.jpg' assert world.css_value(field_css) == expected_value
def verify_date_or_time(css, date_or_time): """ Verifies date or time field. """ assert_equal(date_or_time, world.css_value(css))
def changes_not_persisted(step): reload_the_page(step) name_id = "#course-grading-assignment-name" assert_equal(world.css_value(name_id), "Homework")
def check_transcripts_field(_step, values, field_name): world.click_link_by_text('Advanced') field_id = '#' + world.browser.find_by_xpath('//label[text()="%s"]' % field_name.strip())[0]['for'] values_list = [i.strip() == world.css_value(field_id) for i in values.split('|')] assert any(values_list) world.click_link_by_text('Basic')
def changes_not_persisted(step): reload_the_page(step) name_id = '#course-grading-assignment-name' assert(world.css_value(name_id) == 'Homework')
def problem_has_answer(course, problem_type, answer_class): if problem_type == "drop down": if answer_class == 'blank': assert world.is_css_not_present('option[selected="true"]') else: actual = world.css_value('option[selected="true"]') expected = 'Option 2' if answer_class == 'correct' else 'Option 3' assert actual == expected elif problem_type == "multiple choice": if answer_class == 'correct': assert_checked(course, 'multiple choice', ['choice_2']) elif answer_class == 'incorrect': assert_checked(course, 'multiple choice', ['choice_1']) else: assert_checked(course, 'multiple choice', []) elif problem_type == "checkbox": if answer_class == 'correct': assert_checked(course, 'checkbox', ['choice_0', 'choice_2']) elif answer_class == 'incorrect': assert_checked(course, 'checkbox', ['choice_3']) else: assert_checked(course, 'checkbox', []) elif problem_type == "radio": if answer_class == 'correct': assert_checked(course, 'radio', ['choice_2']) elif answer_class == 'incorrect': assert_checked(course, 'radio', ['choice_1']) else: assert_checked(course, 'radio', []) elif problem_type == 'string': if answer_class == 'blank': expected = '' else: expected = 'correct string' if answer_class == 'correct' else 'incorrect' assert_textfield(course, 'string', expected) elif problem_type == 'formula': if answer_class == 'blank': expected = '' else: expected = "x^2+2*x+y" if answer_class == 'correct' else 'x^2' assert_textfield(course, 'formula', expected) elif problem_type in ("radio_text", "checkbox_text"): if answer_class == 'blank': expected = ('', '') assert_choicetext_values(course, problem_type, (), expected) elif answer_class == 'incorrect': expected = ('5', '') assert_choicetext_values(course, problem_type, ["choiceinput_1bc"], expected) else: expected = ('8', '') assert_choicetext_values(course, problem_type, ["choiceinput_0bc"], expected) else: # The other response types use random data, # which would be difficult to check # We trade input value coverage in the other tests for # input type coverage in this test. pass
def i_see_it_marked__as_homework(step): assert_equal(world.css_value(".status-label"), 'Homework')
def verify_weight(step, weight): weight_id = '#course-grading-assignment-gradeweight' assert_equal(world.css_value(weight_id, -1), weight)
def assert_textfield(course, problem_type, expected_text, input_num=1): element_value = world.css_value( inputfield(course, problem_type, input_num=input_num)) assert element_value == expected_text
def high_level_source_in_editor(_step): open_high_level_source() assert_equal('hi', world.css_value('.source-edit-box'))
def assert_textfield(problem_type, expected_text, input_num=1): element_value = world.css_value(inputfield(problem_type, input_num=input_num)) assert element_value == expected_text
def high_level_source_in_editor(_step): open_high_level_source() assert_equal("hi", world.css_value(".source-edit-box"))
def changes_not_persisted(step): reload_the_page(step) name_id = '#course-grading-assignment-name' assert_equal(world.css_value(name_id), 'Homework')