checklists.py 4.43 KB
Newer Older
1 2 3
#pylint: disable=C0111
#pylint: disable=W0621

4
from lettuce import world, step
5
from nose.tools import assert_true, assert_equal, assert_in
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 17


18 19 20 21 22 23
@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')


24 25
@step('I see the four default edX checklists$')
def i_see_default_checklists(step):
26
    checklists = world.css_find('.checklist-title')
27 28 29 30
    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
31
    assert_true(checklists[3].text.endswith('Draft Your Course About Page'))
32 33


34 35
@step('I can check and uncheck tasks in a checklist$')
def i_can_check_and_uncheck_tasks(step):
36
    # Use the 2nd checklist as a reference
37 38 39 40 41 42 43 44 45
    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)
46 47


48 49
@step('They are correctly selected after I reload the page$')
def tasks_correctly_selected_after_reload(step):
50
    reload_the_page(step)
51 52 53 54 55 56
    verifyChecklist2Status(2, 7, 29)
    # verify that task 7 is still selected by toggling its checkbox state and making sure that it deselects
    toggleTask(1, 6)
    verifyChecklist2Status(1, 7, 14)


57 58 59 60 61 62 63
@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):
64
    assert_in('Course Outline', world.css_find('.outline .page-header')[0].text)
65 66 67
    assert_equal(1, len(world.browser.windows))


68 69 70 71 72 73 74 75
@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)


76 77 78 79 80 81 82 83 84 85 86 87 88 89
@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)


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

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


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


109 110
# 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
111 112 113
def clickActionLink(checklist, task, actionText):
    # toggle checklist item to make sure that the link button is showing
    toggleTask(checklist, task)
114
    action_link = world.css_find('#course-checklist' + str(checklist) + ' a')[task]
115 116 117 118 119

    # text will be empty initially, wait for it to populate
    def verify_action_link_text(driver):
        return action_link.text == actionText

120
    world.wait_for(verify_action_link_text)
121
    action_link.click()