def asset_chapter(_step, name, ordinal): index = ["first", "second", "third"].index(ordinal) input_css = ".textbook .chapter{i} input.chapter-asset-path".format( i=index + 1) world.css_fill(input_css, name) if world.is_firefox(): world.trigger_event(input_css)
def add_subsection(name='Subsection One'): css = 'a.new-subsection-item' world.css_click(css) name_css = 'input.new-subsection-name-input' save_css = 'input.new-subsection-name-save' world.css_fill(name_css, name) world.css_click(save_css)
def add_subsection(name="Subsection One"): css = "a.new-subsection-item" world.css_click(css) name_css = "input.new-subsection-name-input" save_css = "input.new-subsection-name-save" world.css_fill(name_css, name) world.css_click(save_css)
def answer_problem(problem_type, correctness): if problem_type == "drop down": select_name = "input_i4x-edx-model_course-problem-drop_down_2_1" option_text = 'Option 2' if correctness == 'correct' else 'Option 3' world.browser.select(select_name, option_text) elif problem_type == "multiple choice": if correctness == 'correct': world.css_check(inputfield('multiple choice', choice='choice_2')) else: world.css_check(inputfield('multiple choice', choice='choice_1')) elif problem_type == "checkbox": if correctness == 'correct': world.css_check(inputfield('checkbox', choice='choice_0')) world.css_check(inputfield('checkbox', choice='choice_2')) else: world.css_check(inputfield('checkbox', choice='choice_3')) elif problem_type == 'radio': if correctness == 'correct': world.css_check(inputfield('radio', choice='choice_2')) else: world.css_check(inputfield('radio', choice='choice_1')) elif problem_type == 'string': textvalue = 'correct string' if correctness == 'correct' else 'incorrect' world.css_fill(inputfield('string'), textvalue) elif problem_type == 'numerical': textvalue = "pi + 1" if correctness == 'correct' else str(random.randint(-2, 2)) world.css_fill(inputfield('numerical'), textvalue) elif problem_type == 'formula': textvalue = "x^2+2*x+y" if correctness == 'correct' else 'x^2' world.css_fill(inputfield('formula'), textvalue) elif problem_type == 'script': # Correct answer is any two integers that sum to 10 first_addend = random.randint(-100, 100) second_addend = 10 - first_addend # If we want an incorrect answer, then change # the second addend so they no longer sum to 10 if correctness == 'incorrect': second_addend += random.randint(1, 10) world.css_fill(inputfield('script', input_num=1), str(first_addend)) world.css_fill(inputfield('script', input_num=2), str(second_addend)) elif problem_type == 'code': # The fake xqueue server is configured to respond # correct / incorrect no matter what we submit. # Furthermore, since the inline code response uses # JavaScript to make the code display nicely, it's difficult # to programatically input text # (there's not <textarea> we can just fill text into) # For this reason, we submit the initial code in the response # (configured in the problem XML above) pass
def i_can_modify_the_display_name(step): # Verifying that the display name can be a string containing a floating point value # (to confirm that we don't throw an error because it is of the wrong type). index = world.get_setting_entry_index(DISPLAY_NAME) world.css_fill('.wrapper-comp-setting .setting-input', '3.4', index=index) if world.is_firefox(): world.trigger_event('.wrapper-comp-setting .setting-input', index=index) verify_modified_display_name()
def answer_problem(self, step): r"""I answer that annotation problem$""" world.css_fill(self.active_problem_selector('.comment'), 'Test Response') world.css_click( self.active_problem_selector('.tag[data-id="{}"]'.format( self.active_problem))) world.css_click(self.active_problem_selector('.check'))
def i_can_modify_the_display_name(_step): # Verifying that the display name can be a string containing a floating point value # (to confirm that we don't throw an error because it is of the wrong type). index = world.get_setting_entry_index(DISPLAY_NAME) world.css_fill('.wrapper-comp-setting .setting-input', '3.4', index=index) if world.is_firefox(): world.trigger_event('.wrapper-comp-setting .setting-input', index=index) verify_modified_display_name()
def set_date_or_time(css, date_or_time): """ Sets date or time field. """ world.css_fill(css, date_or_time) e = world.css_find(css).first # hit Enter to apply the changes e._element.send_keys(Keys.ENTER)
def change_name(step, new_name): settings_css = '.settings-button' world.css_click(settings_css) input_css = 'input.setting-input' world.css_fill(input_css, new_name) if world.is_firefox(): world.trigger_event(input_css) world.save_component()
def set_weight(weight): index = world.get_setting_entry_index(PROBLEM_WEIGHT) world.css_fill('.wrapper-comp-setting .setting-input', weight, index=index) if world.is_firefox(): world.trigger_event('.wrapper-comp-setting .setting-input', index=index, event='blur') world.trigger_event('a.save-button', event='focus')
def i_can_modify_the_display_name_with_special_chars(step): index = world.get_setting_entry_index(DISPLAY_NAME) world.css_fill('.wrapper-comp-setting .setting-input', "updated ' \" &", index=index) if world.is_firefox(): world.trigger_event('.wrapper-comp-setting .setting-input', index=index) verify_modified_display_name_with_special_chars()
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 change_name(_step, new_name): settings_css = "#settings-mode a" world.css_click(settings_css) input_css = "input.setting-input" world.css_fill(input_css, new_name) if world.is_firefox(): world.trigger_event(input_css) save_button = "a.save-button" world.css_click(save_button)
def add_section(name="My Section"): link_css = "a.new-courseware-section-button" world.css_click(link_css) name_css = "input.new-section-name" save_css = "input.new-section-name-save" world.css_fill(name_css, name) world.css_click(save_css) span_css = "span.section-name-span" assert_true(world.is_css_present(span_css))
def change_name(step, new_name): settings_css = '#settings-mode a' world.css_click(settings_css) input_css = 'input.setting-input' world.css_fill(input_css, new_name) if world.is_firefox(): world.trigger_event(input_css) save_button = 'a.save-button' world.css_click(save_button)
def set_date_and_time(date_css, desired_date, time_css, desired_time): world.css_fill(date_css, desired_date) # hit TAB to get to the time field e = world.css_find(date_css).first e._element.send_keys(Keys.TAB) world.css_fill(time_css, desired_time) e = world.css_find(time_css).first e._element.send_keys(Keys.TAB) time.sleep(float(1))
def add_section(name='My Section'): link_css = 'a.new-courseware-section-button' world.css_click(link_css) name_css = 'input.new-section-name' save_css = 'input.new-section-name-save' world.css_fill(name_css, name) world.css_click(save_css) span_css = 'span.section-name-span' assert_true(world.is_css_present(span_css))
def clear_field(_step, index): index = int(index) - 1 world.css_fill(SELECTORS['url_inputs'], '', index) # For some reason ChromeDriver doesn't trigger an 'input' event after filling # the field with an empty value. That's why we trigger it manually via jQuery. world.trigger_event(SELECTORS['url_inputs'], event='input', index=index) world.wait(DELAY) world.wait_for_ajax_complete()
def add_other_user(_step, name): new_user_css = 'a.create-user-button' world.css_click(new_user_css) world.wait(0.5) email_css = 'input#user-email-input' world.css_fill(email_css, name + '@edx.org') if world.is_firefox(): world.trigger_event(email_css) confirm_css = 'form.create-user button.action-primary' world.css_click(confirm_css)
def i_enter_a_source(_step, link, index): index = int(index) - 1 if index is not 0 and not world.css_visible(SELECTORS["collapse_bar"]): world.css_click(SELECTORS["collapse_link"]) assert world.css_visible(SELECTORS["collapse_bar"]) world.css_fill(SELECTORS["url_inputs"], link, index) world.wait(DELAY) world.wait_for_ajax_complete()
def i_enter_a_source(_step, link, index): index = int(index) - 1 if index is not 0 and not world.css_visible(SELECTORS['collapse_bar']): world.css_click(SELECTORS['collapse_link']) assert world.css_visible(SELECTORS['collapse_bar']) world.css_fill(SELECTORS['url_inputs'], link, index) world.wait(DELAY) world.wait_for_ajax_complete()
def fill_in_course_info( name='Robot Super Course', org='MITx', num='101', run='2013_Spring', subject='Mathematics'): world.css_fill('.new-course-name', name) world.css_fill('.new-course-org', org) world.css_fill('.new-course-number', num) world.css_fill('.new-course-run', run) world.css_fill('.new-course-subject', subject)
def add_other_user(_step, name): new_user_css = 'a.create-user-button' world.css_click(new_user_css) world.wait(0.5) email_css = 'input#user-email-input' world.css_fill(email_css, name + EMAIL_EXTENSION) if world.is_firefox(): world.trigger_event(email_css) confirm_css = 'form.create-user button.action-primary' world.css_click(confirm_css)
def add_other_user(_step, name): new_user_css = 'a.create-user-button' world.css_click(new_user_css) # Wait for the css animation to apply the is-shown class shown_css = 'div.wrapper-create-user.is-shown' world.wait_for_present(shown_css) email_css = 'input#user-email-input' world.css_fill(email_css, name + '@edx.org') if world.is_firefox(): world.trigger_event(email_css) confirm_css = 'form.create-user button.action-primary' world.css_click(confirm_css)
def fill_in_course_info(name='Robot Super Course', org='MITx', num='101', run='2013_Spring'): world.css_fill('.new-course-name', name) world.css_fill('.new-course-org', org) world.css_fill('.new-course-number', num) world.css_fill('.new-course-run', run)
def when_i_send_an_email(step, recipient): # Check that the recipient is valid assert_in( recipient, SEND_TO_OPTIONS, msg="Invalid recipient: {}".format(recipient) ) # Clear the queue of existing emails while not mail.queue.empty(): # pylint: disable=E1101 mail.queue.get() # pylint: disable=E1101 # Because we flush the database before each run, # we need to ensure that the email template fixture # is re-loaded into the database call_command('loaddata', 'course_email_template.json') # Go to the email section of the instructor dash world.visit('/courses/edx/999/Test_Course') world.css_click('a[href="/courses/edx/999/Test_Course/instructor"]') world.css_click('div.beta-button-wrapper>a') world.css_click('a[data-section="send_email"]') # Select the recipient world.select_option('send_to', SEND_TO_OPTIONS[recipient]) # Enter subject and message world.css_fill('input#id_subject', 'Hello') with world.browser.get_iframe('mce_0_ifr') as iframe: editor = iframe.find_by_id('tinymce')[0] editor.fill('test message') # Click send world.css_click('input[name="send"]') # Confirm the alert world.browser.get_alert().accept() # Expect to see a message that the email was sent expected_msg = "Your email was successfully queued for sending." world.wait_for_visible('#request-response') assert_in( expected_msg, world.css_text('#request-response'), msg="Could not find email success message." )
def fill_in_course_info( name='Robot Super Course', org='MITx', num='999'): world.css_fill('.new-course-name', name) world.css_fill('.new-course-org', org) world.css_fill('.new-course-number', num)
def fill_in_course_info( name=_COURSE_NAME, org=_COURSE_ORG, num=_COURSE_NUM): world.css_fill('.new-course-name', name) world.css_fill('.new-course-org', org) world.css_fill('.new-course-number', num)
def when_i_send_an_email(step, recipient): # pylint: disable=unused-argument # Check that the recipient is valid assert_in(recipient, SEND_TO_OPTIONS, msg="Invalid recipient: {}".format(recipient)) # Clear the queue of existing emails while not mail.queue.empty(): # pylint: disable=no-member mail.queue.get() # pylint: disable=no-member # Because we flush the database before each run, # we need to ensure that the email template fixture # is re-loaded into the database call_command("loaddata", "course_email_template.json") # Go to the email section of the instructor dash url = "/courses/{}".format(world.bulk_email_course_key) world.visit(url) world.css_click('a[href="{}/instructor"]'.format(url)) world.css_click('a[data-section="send_email"]') # Select the recipient world.select_option("send_to", SEND_TO_OPTIONS[recipient]) # Enter subject and message world.css_fill("input#id_subject", "Hello") with world.browser.get_iframe("mce_0_ifr") as iframe: editor = iframe.find_by_id("tinymce")[0] editor.fill("test message") # Click send world.css_click('input[name="send"]', dismiss_alert=True) # Expect to see a message that the email was sent expected_msg = "Your email was successfully queued for sending." world.wait_for_visible("#request-response") assert_in(expected_msg, world.css_text("#request-response"), msg="Could not find email success message.")
def save_section_name(name): name_css = '.new-section-name' save_css = '.new-section-name-save' world.css_fill(name_css, name) world.css_click(save_css)
def save_subsection_name(name): name_css = 'input.new-subsection-name-input' save_css = 'input.new-subsection-name-save' world.css_fill(name_css, name) world.css_click(save_css)
def asset_chapter(_step, name, ordinal): index = ["first", "second", "third"].index(ordinal) input_css = ".textbook .chapter{i} input.chapter-asset-path".format(i=index+1) world.css_fill(input_css, name) if world.is_firefox(): world.trigger_event(input_css)
def name_textbook(_step, name): input_css = ".textbook input[name=textbook-name]" world.css_fill(input_css, name) if world.is_firefox(): world.trigger_event(input_css)
def answer_problem(self, step): r"""I answer that annotation problem$""" world.css_fill(self.active_problem_selector('.comment'), 'Test Response') world.css_click(self.active_problem_selector('.tag[data-id="{}"]'.format(self.active_problem))) world.css_click(self.active_problem_selector('.check'))
def answer_problem(problem_type, correctness): if problem_type == "drop down": select_name = "input_i4x-edx-model_course-problem-drop_down_2_1" option_text = 'Option 2' if correctness == 'correct' else 'Option 3' world.select_option(select_name, option_text) elif problem_type == "multiple choice": if correctness == 'correct': world.css_check(inputfield('multiple choice', choice='choice_2')) else: world.css_check(inputfield('multiple choice', choice='choice_1')) elif problem_type == "checkbox": if correctness == 'correct': world.css_check(inputfield('checkbox', choice='choice_0')) world.css_check(inputfield('checkbox', choice='choice_2')) else: world.css_check(inputfield('checkbox', choice='choice_3')) elif problem_type == 'radio': if correctness == 'correct': world.css_check(inputfield('radio', choice='choice_2')) else: world.css_check(inputfield('radio', choice='choice_1')) elif problem_type == 'string': textvalue = 'correct string' if correctness == 'correct' else 'incorrect' world.css_fill(inputfield('string'), textvalue) elif problem_type == 'numerical': textvalue = "pi + 1" if correctness == 'correct' else str( random.randint(-2, 2)) world.css_fill(inputfield('numerical'), textvalue) elif problem_type == 'formula': textvalue = "x^2+2*x+y" if correctness == 'correct' else 'x^2' world.css_fill(inputfield('formula'), textvalue) elif problem_type == 'script': # Correct answer is any two integers that sum to 10 first_addend = random.randint(-100, 100) second_addend = 10 - first_addend # If we want an incorrect answer, then change # the second addend so they no longer sum to 10 if correctness == 'incorrect': second_addend += random.randint(1, 10) world.css_fill(inputfield('script', input_num=1), str(first_addend)) world.css_fill(inputfield('script', input_num=2), str(second_addend)) elif problem_type == 'code': # The fake xqueue server is configured to respond # correct / incorrect no matter what we submit. # Furthermore, since the inline code response uses # JavaScript to make the code display nicely, it's difficult # to programatically input text # (there's not <textarea> we can just fill text into) # For this reason, we submit the initial code in the response # (configured in the problem XML above) pass elif problem_type == 'radio_text' or problem_type == 'checkbox_text': input_value = "8" if correctness == 'correct' else "5" choice = "choiceinput_0bc" if correctness == 'correct' else "choiceinput_1bc" world.css_fill( inputfield(problem_type, choice="choiceinput_0_numtolerance_input_0"), input_value) world.css_check(inputfield(problem_type, choice=choice))
def answer_problem(course, problem_type, correctness): # Make sure that the problem has been completely rendered before # starting to input an answer. world.wait_for_ajax_complete() section_loc = section_location(course) if problem_type == "drop down": select_name = "input_{}_2_1".format( section_loc.course_key.make_usage_key('problem', 'drop_down').html_id() ) option_text = 'Option 2' if correctness == 'correct' else 'Option 3' world.select_option(select_name, option_text) elif problem_type == "multiple choice": if correctness == 'correct': world.css_check(inputfield(course, 'multiple choice', choice='choice_2')) else: world.css_check(inputfield(course, 'multiple choice', choice='choice_1')) elif problem_type == "checkbox": if correctness == 'correct': world.css_check(inputfield(course, 'checkbox', choice='choice_0')) world.css_check(inputfield(course, 'checkbox', choice='choice_2')) else: world.css_check(inputfield(course, 'checkbox', choice='choice_3')) elif problem_type == 'radio': if correctness == 'correct': world.css_check(inputfield(course, 'radio', choice='choice_2')) else: world.css_check(inputfield(course, 'radio', choice='choice_1')) elif problem_type == 'string': textvalue = 'correct string' if correctness == 'correct' else 'incorrect' world.css_fill(inputfield(course, 'string'), textvalue) elif problem_type == 'numerical': textvalue = "pi + 1" if correctness == 'correct' else str(random.randint(-2, 2)) world.css_fill(inputfield(course, 'numerical'), textvalue) elif problem_type == 'formula': textvalue = "x^2+2*x+y" if correctness == 'correct' else 'x^2' world.css_fill(inputfield(course, 'formula'), textvalue) elif problem_type == 'script': # Correct answer is any two integers that sum to 10 first_addend = random.randint(-100, 100) second_addend = 10 - first_addend # If we want an incorrect answer, then change # the second addend so they no longer sum to 10 if correctness == 'incorrect': second_addend += random.randint(1, 10) world.css_fill(inputfield(course, 'script', input_num=1), str(first_addend)) world.css_fill(inputfield(course, 'script', input_num=2), str(second_addend)) elif problem_type == 'code': # The fake xqueue server is configured to respond # correct / incorrect no matter what we submit. # Furthermore, since the inline code response uses # JavaScript to make the code display nicely, it's difficult # to programatically input text # (there's not <textarea> we can just fill text into) # For this reason, we submit the initial code in the response # (configured in the problem XML above) pass elif problem_type == 'radio_text' or problem_type == 'checkbox_text': input_value = "8" if correctness == 'correct' else "5" choice = "choiceinput_0bc" if correctness == 'correct' else "choiceinput_1bc" world.css_fill( inputfield( course, problem_type, choice="choiceinput_0_numtolerance_input_0" ), input_value ) world.css_check(inputfield(course, problem_type, choice=choice)) elif problem_type == 'image': offset = 25 if correctness == "correct" else -25 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);})') 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) world.retry_on_exception(try_click)
def fill_in_link_fields(): world.css_fill('.mce-textbox', path, 0) world.css_fill('.mce-textbox', 'picture', 1)
def i_click_on_image_plugin_icon(step, path): use_plugin( '.mce-i-image', lambda: world.css_fill('.mce-textbox', path, 0) )
def i_edit_the_password_field(step): password_css = 'form#login_form input#password' world.css_fill(password_css, 'test')
def i_submit_the_answer_text(step, text): world.css_fill('textarea', text) world.css_click('input.check')
def fill_inputs(_step): input_css = '.input_cloud_section .input-cloud' world.css_fill(input_css, 'text1', 0) for index in range(1, 4): world.css_fill('.input_cloud_section .input-cloud', 'text2', index)
def enter_the_answer_text(step, text): world.css_fill('textarea', text)
def i_click_on_image_plugin_icon(_step, path): use_plugin('.mce-i-image', lambda: world.css_fill('.mce-textbox', path, 0))
def answer_problem(course, problem_type, correctness): # Make sure that the problem has been completely rendered before # starting to input an answer. world.wait_for_ajax_complete() section_loc = section_location(course) if problem_type == "drop down": select_name = "input_{}_2_1".format( section_loc.course_key.make_usage_key('problem', 'drop_down').html_id()) option_text = 'Option 2' if correctness == 'correct' else 'Option 3' world.select_option(select_name, option_text) elif problem_type == "multiple choice": if correctness == 'correct': world.css_check( inputfield(course, 'multiple choice', choice='choice_2')) else: world.css_check( inputfield(course, 'multiple choice', choice='choice_1')) elif problem_type == "checkbox": if correctness == 'correct': world.css_check(inputfield(course, 'checkbox', choice='choice_0')) world.css_check(inputfield(course, 'checkbox', choice='choice_2')) else: world.css_check(inputfield(course, 'checkbox', choice='choice_3')) elif problem_type == 'radio': if correctness == 'correct': world.css_check(inputfield(course, 'radio', choice='choice_2')) else: world.css_check(inputfield(course, 'radio', choice='choice_1')) elif problem_type == 'string': textvalue = 'correct string' if correctness == 'correct' else 'incorrect' world.css_fill(inputfield(course, 'string'), textvalue) elif problem_type == 'numerical': textvalue = "pi + 1" if correctness == 'correct' else str( random.randint(-2, 2)) world.css_fill(inputfield(course, 'numerical'), textvalue) elif problem_type == 'formula': textvalue = "x^2+2*x+y" if correctness == 'correct' else 'x^2' world.css_fill(inputfield(course, 'formula'), textvalue) elif problem_type == 'script': # Correct answer is any two integers that sum to 10 first_addend = random.randint(-100, 100) second_addend = 10 - first_addend # If we want an incorrect answer, then change # the second addend so they no longer sum to 10 if correctness == 'incorrect': second_addend += random.randint(1, 10) world.css_fill(inputfield(course, 'script', input_num=1), str(first_addend)) world.css_fill(inputfield(course, 'script', input_num=2), str(second_addend)) elif problem_type == 'code': # The fake xqueue server is configured to respond # correct / incorrect no matter what we submit. # Furthermore, since the inline code response uses # JavaScript to make the code display nicely, it's difficult # to programatically input text # (there's not <textarea> we can just fill text into) # For this reason, we submit the initial code in the response # (configured in the problem XML above) pass elif problem_type == 'radio_text' or problem_type == 'checkbox_text': input_value = "8" if correctness == 'correct' else "5" choice = "choiceinput_0bc" if correctness == 'correct' else "choiceinput_1bc" world.css_fill( inputfield(course, problem_type, choice="choiceinput_0_numtolerance_input_0"), input_value) world.css_check(inputfield(course, problem_type, choice=choice)) elif problem_type == 'image': offset = 25 if correctness == "correct" else -25 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);})') 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) world.retry_on_exception(try_click)