checklists.py 4.69 KB
Newer Older
1
# pylint: disable=missing-docstring
2
# pylint: disable=redefined-outer-name
3

4
from lettuce import world, step
5
from nose.tools import assert_true, assert_equal  # pylint: disable=no-name-in-module
6
from terrain.steps import reload_the_page
7
from selenium.common.exceptions import StaleElementReferenceException
8

9

10 11 12
############### ACTIONS ####################
@step('I select Checklists from the Tools menu$')
def i_select_checklists(step):
David Baumgold committed
13
    world.click_tools()
14
    link_css = 'li.nav-course-tools-checklists a'
15
    world.css_click(link_css)
16
    world.wait_for_ajax_complete()
17 18


19 20 21 22 23 24
@step('I have opened Checklists$')
def i_have_opened_checklists(step):
    step.given('I have opened a new course in Studio')
    step.given('I select Checklists from the Tools menu')


25 26
@step('I see the four default edX checklists$')
def i_see_default_checklists(step):
27
    checklists = world.css_find('.checklist-title')
28 29 30 31
    assert_equal(4, len(checklists))
    assert_true(checklists[0].text.endswith('Getting Started With Studio'))
    assert_true(checklists[1].text.endswith('Draft a Rough Course Outline'))
    assert_true(checklists[2].text.endswith("Explore edX\'s Support Tools"))
cahrens committed
32
    assert_true(checklists[3].text.endswith('Draft Your Course About Page'))
33 34


35 36
@step('I can check and uncheck tasks in a checklist$')
def i_can_check_and_uncheck_tasks(step):
37
    # Use the 2nd checklist as a reference
38 39 40 41 42 43 44 45 46
    verifyChecklist2Status(0, 7, 0)
    toggleTask(1, 0)
    verifyChecklist2Status(1, 7, 14)
    toggleTask(1, 3)
    verifyChecklist2Status(2, 7, 29)
    toggleTask(1, 6)
    verifyChecklist2Status(3, 7, 43)
    toggleTask(1, 3)
    verifyChecklist2Status(2, 7, 29)
47 48


49 50
@step('the tasks are correctly selected$')
def tasks_correctly_selected(step):
51 52
    verifyChecklist2Status(2, 7, 29)
    # verify that task 7 is still selected by toggling its checkbox state and making sure that it deselects
53
    world.browser.execute_script("window.scrollBy(0,1000)")
54 55 56 57
    toggleTask(1, 6)
    verifyChecklist2Status(1, 7, 14)


58 59 60 61 62 63 64
@step('I select a link to the course outline$')
def i_select_a_link_to_the_course_outline(step):
    clickActionLink(1, 0, 'Edit Course Outline')


@step('I am brought to the course outline page$')
def i_am_brought_to_course_outline(step):
65
    assert world.is_css_present('body.view-outline')
66 67 68
    assert_equal(1, len(world.browser.windows))


69 70 71 72 73 74 75 76
@step('I am brought back to the course outline in the correct state$')
def i_am_brought_back_to_course_outline(step):
    step.given('I see the four default edX checklists')
    # In a previous step, we selected (1, 0) in order to click the 'Edit Course Outline' link.
    # Make sure the task is still showing as selected (there was a caching bug with the collection).
    verifyChecklist2Status(1, 7, 14)


77 78 79 80 81 82 83 84 85 86 87 88 89 90
@step('I select a link to help page$')
def i_select_a_link_to_the_help_page(step):
    clickActionLink(2, 0, 'Visit Studio Help')


@step('I am brought to the help page in a new window$')
def i_am_brought_to_help_page_in_new_window(step):
    step.given('I see the four default edX checklists')
    windows = world.browser.windows
    assert_equal(2, len(windows))
    world.browser.switch_to_window(windows[1])
    assert_equal('http://help.edge.edx.org/', world.browser.url)


91 92 93 94
############### HELPER METHODS ####################
def verifyChecklist2Status(completed, total, percentage):
    def verify_count(driver):
        try:
95
            statusCount = world.css_find('#course-checklist1 .status-count').first
96 97 98 99
            return statusCount.text == str(completed)
        except StaleElementReferenceException:
            return False

100 101
    world.wait_for(verify_count)
    assert_equal(str(total), world.css_find('#course-checklist1 .status-amount').first.text)
102
    # Would like to check the CSS width, but not sure how to do that.
103
    assert_equal(str(percentage), world.css_find('#course-checklist1 .viz-checklist-status-value .int').first.text)
104 105 106


def toggleTask(checklist, task):
107
    world.css_click('#course-checklist' + str(checklist) + '-task' + str(task))
108
    world.wait_for_ajax_complete()
109 110


111 112
# TODO: figure out a way to do this in phantom and firefox
# For now we will mark the scenerios that use this method as skipped
113 114 115
def clickActionLink(checklist, task, actionText):
    # text will be empty initially, wait for it to populate
    def verify_action_link_text(driver):
116 117 118 119 120 121 122
        actualText = world.css_text('#course-checklist' + str(checklist) + ' a', index=task)
        if actualText == actionText:
            return True
        else:
            # toggle checklist item to make sure that the link button is showing
            toggleTask(checklist, task)
            return False
123

124
    world.wait_for(verify_action_link_text)
125
    world.css_click('#course-checklist' + str(checklist) + ' a', index=task)
126
    world.wait_for_ajax_complete()