Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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")
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
        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)
Ejemplo n.º 7
0
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')
Ejemplo n.º 8
0
        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)
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
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
Ejemplo n.º 11
0
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
Ejemplo n.º 12
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')
Ejemplo n.º 13
0
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
Ejemplo n.º 14
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")
Ejemplo n.º 15
0
def get_display_name_value():
    index = get_index_of(DISPLAY_NAME_KEY)
    return world.css_value(VALUE_CSS, index=index)
Ejemplo n.º 16
0
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))
Ejemplo n.º 18
0
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))
Ejemplo n.º 19
0
def high_level_source_in_editor(step):
    open_high_level_source()
    assert_equal('hi', world.css_value('.source-edit-box'))
Ejemplo n.º 20
0
def image_url_present(_step):
    field_css = '#course-image-url'
    expected_value = 'image.jpg'
    assert world.css_value(field_css).endswith(expected_value)
Ejemplo n.º 21
0
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"')
Ejemplo n.º 22
0
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
Ejemplo n.º 23
0
def get_display_name_value():
    index = get_index_of(DISPLAY_NAME_KEY)
    return world.css_value(VALUE_CSS, index=index)
Ejemplo n.º 24
0
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
Ejemplo n.º 25
0
def verify_date_or_time(css, date_or_time):
    """
    Verifies date or time field.
    """
    assert_equal(date_or_time, world.css_value(css))
Ejemplo n.º 26
0
def changes_not_persisted(step):
    reload_the_page(step)
    name_id = "#course-grading-assignment-name"
    assert_equal(world.css_value(name_id), "Homework")
Ejemplo n.º 27
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')
Ejemplo n.º 28
0
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"')
Ejemplo n.º 29
0
def changes_not_persisted(step):
    reload_the_page(step)
    name_id = '#course-grading-assignment-name'
    assert(world.css_value(name_id) == 'Homework')
Ejemplo n.º 30
0
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
Ejemplo n.º 31
0
def i_see_it_marked__as_homework(step):
    assert_equal(world.css_value(".status-label"), 'Homework')
Ejemplo n.º 32
0
def verify_weight(step, weight):
    weight_id = '#course-grading-assignment-gradeweight'
    assert_equal(world.css_value(weight_id, -1), weight)
Ejemplo n.º 33
0
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
Ejemplo n.º 34
0
def verify_date_or_time(css, date_or_time):
    """
    Verifies date or time field.
    """
    assert_equal(date_or_time, world.css_value(css))
Ejemplo n.º 35
0
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
Ejemplo n.º 36
0
def high_level_source_in_editor(_step):
    open_high_level_source()
    assert_equal('hi', world.css_value('.source-edit-box'))
Ejemplo n.º 37
0
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"')
Ejemplo n.º 38
0
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
Ejemplo n.º 39
0
def image_url_present(_step):
    field_css = '#course-image-url'
    expected_value = 'image.jpg'
    assert world.css_value(field_css).endswith(expected_value)
Ejemplo n.º 40
0
def verify_weight(step, weight):
    weight_id = '#course-grading-assignment-gradeweight'
    assert_equal(world.css_value(weight_id, -1), weight)
Ejemplo n.º 41
0
def high_level_source_in_editor(_step):
    open_high_level_source()
    assert_equal("hi", world.css_value(".source-edit-box"))
Ejemplo n.º 42
0
def i_see_it_marked__as_homework(step):
    assert_equal(world.css_value(".status-label"), 'Homework')
Ejemplo n.º 43
0
def changes_not_persisted(step):
    reload_the_page(step)
    name_id = '#course-grading-assignment-name'
    assert_equal(world.css_value(name_id), 'Homework')