def _do_studio_prompt_action(intent, action): """ Wait for a studio prompt to appear and press the specified action button See common/js/components/views/feedback_prompt.js for implementation """ assert intent in [ 'warning', 'error', 'confirmation', 'announcement', 'step-required', 'help', 'mini', ] assert action in ['primary', 'secondary'] world.wait_for_present( 'div.wrapper-prompt.is-shown#prompt-{}'.format(intent)) action_css = 'li.nav-item > button.action-{}'.format(action) world.trigger_event(action_css, event='focus') world.browser.execute_script("$('{}').click()".format(action_css)) world.wait_for_ajax_complete() world.wait_for_present( 'div.wrapper-prompt.is-hiding#prompt-{}'.format(intent))
def press_the_notification_button(_step, name): # TODO: fix up this code. Selenium is not dealing well with css transforms, # as it thinks that the notification and the buttons are always visible # First wait for the notification to pop up notification_css = 'div#page-notification div.wrapper-notification' world.wait_for_visible(notification_css) # You would think that the above would have worked, but it doesn't. # Brute force wait for now. world.wait(.5) # Now make sure the button is there btn_css = 'div#page-notification a.action-%s' % name.lower() world.wait_for_visible(btn_css) # You would think that the above would have worked, but it doesn't. # Brute force wait for now. world.wait(.5) if world.is_firefox(): # This is done to explicitly make the changes save on firefox. # It will remove focus from the previously focused element world.trigger_event(btn_css, event='focus') world.browser.execute_script("$('{}').click()".format(btn_css)) else: world.css_click(btn_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 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 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 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_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 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 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 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 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 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 + 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) 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 type_in_codemirror(index, text): world.css_click("div.CodeMirror-lines", index=index) world.browser.execute_script("$('div.CodeMirror.CodeMirror-focused > div').css('overflow', '')") g = world.css_find("div.CodeMirror.CodeMirror-focused > div > textarea") if world.is_mac(): g._element.send_keys(Keys.COMMAND + 'a') else: g._element.send_keys(Keys.CONTROL + 'a') g._element.send_keys(Keys.DELETE) g._element.send_keys(text) if world.is_firefox(): world.trigger_event('div.CodeMirror', index=index, event='blur')
def press_the_notification_button(_step, name): # Because the notification uses a CSS transition, # Selenium will always report it as being visible. # This makes it very difficult to successfully click # the "Save" button at the UI level. # Instead, we use JavaScript to reliably click # the button. btn_css = 'div#page-notification button.action-%s' % name.lower() world.trigger_event(btn_css, event='focus') world.browser.execute_script("$('{}').click()".format(btn_css)) world.wait_for_ajax_complete()
def type_in_codemirror(index, text): world.wait(1) # For now, slow this down so that it works. TODO: fix it. world.css_click("div.CodeMirror-lines", index=index) world.browser.execute_script("$('div.CodeMirror.CodeMirror-focused > div').css('overflow', '')") g = world.css_find("div.CodeMirror.CodeMirror-focused > div > textarea") if world.is_mac(): g._element.send_keys(Keys.COMMAND + "a") else: g._element.send_keys(Keys.CONTROL + "a") g._element.send_keys(Keys.DELETE) g._element.send_keys(text) if world.is_firefox(): world.trigger_event("div.CodeMirror", index=index, event="blur")
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 type_in_codemirror(index, text): world.wait(1) # For now, slow this down so that it works. TODO: fix it. world.css_click("div.CodeMirror-lines", index=index) world.browser.execute_script( "$('div.CodeMirror.CodeMirror-focused > div').css('overflow', '')") g = world.css_find("div.CodeMirror.CodeMirror-focused > div > textarea") if world.is_mac(): g._element.send_keys(Keys.COMMAND + 'a') else: g._element.send_keys(Keys.CONTROL + 'a') g._element.send_keys(Keys.DELETE) g._element.send_keys(text) if world.is_firefox(): world.trigger_event('div.CodeMirror', index=index, event='blur') world.wait_for_ajax_complete()
def press_the_notification_button(_step, name): css = 'a.action-%s' % name.lower() # The button was clicked if either the notification bar is gone, # or we see an error overlaying it (expected for invalid inputs). def button_clicked(): confirmation_dismissed = world.is_css_not_present('.is-shown.wrapper-notification-warning') error_showing = world.is_css_present('.is-shown.wrapper-notification-error') return confirmation_dismissed or error_showing if world.is_firefox(): # This is done to explicitly make the changes save on firefox. It will remove focus from the previously focused element world.trigger_event(css, event='focus') world.browser.execute_script("$('{}').click()".format(css)) else: world.css_click(css, success_condition=button_clicked), '%s button not clicked after 5 attempts.' % name
def _do_studio_prompt_action(intent, action): """ Wait for a studio prompt to appear and press the specified action button See cms/static/js/views/feedback_prompt.js for implementation """ assert intent in ["warning", "error", "confirmation", "announcement", "step-required", "help", "mini"] assert action in ["primary", "secondary"] world.wait_for_present("div.wrapper-prompt.is-shown#prompt-{}".format(intent)) action_css = "li.nav-item > a.action-{}".format(action) world.trigger_event(action_css, event="focus") world.browser.execute_script("$('{}').click()".format(action_css)) world.wait_for_ajax_complete() world.wait_for_present("div.wrapper-prompt.is-hiding#prompt-{}".format(intent))
def _do_studio_prompt_action(intent, action): """ Wait for a studio prompt to appear and press the specified action button See cms/static/js/views/feedback_prompt.js for implementation """ assert intent in ['warning', 'error', 'confirmation', 'announcement', 'step-required', 'help', 'mini'] assert action in ['primary', 'secondary'] world.wait_for_present('div.wrapper-prompt.is-shown#prompt-{}'.format(intent)) action_css = 'li.nav-item > a.action-{}'.format(action) world.trigger_event(action_css, event='focus') world.browser.execute_script("$('{}').click()".format(action_css)) world.wait_for_ajax_complete() world.wait_for_present('div.wrapper-prompt.is-hiding#prompt-{}'.format(intent))
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 i_mouseover_on_html_component(step, element_class): action_css = '.{}'.format(element_class) world.trigger_event(action_css, event='mouseover')
def clear_field(_step, index): index = int(index) - 1 world.css_fill(SELECTORS['url_inputs'], '', index) # In some reason chromeDriver doesn't trigger 'input' event after filling # field by an empty value. That's why we trigger it manually via jQuery. world.trigger_event(SELECTORS['url_inputs'], event='input', index=index)
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 _clear_field(index): world.css_fill(SELECTORS["url_inputs"], "", index) # In some reason chromeDriver doesn't trigger 'input' event after filling # field by an empty value. That's why we trigger it manually via jQuery. world.trigger_event(SELECTORS["url_inputs"], event="input", index=index)