Commit cdadcba9 by Jonah Stanley

Merge pull request #10 from edx/jonahstanley/add-more-tests

Jonahstanley/add more tests
parents 8d7a2f31 6af54ead
...@@ -72,4 +72,5 @@ Giulio Gratta <giulio@giuliogratta.com> ...@@ -72,4 +72,5 @@ Giulio Gratta <giulio@giuliogratta.com>
David Baumgold <david@davidbaumgold.com> David Baumgold <david@davidbaumgold.com>
Jason Bau <jbau@stanford.edu> Jason Bau <jbau@stanford.edu>
Frances Botsford <frances@edx.org> Frances Botsford <frances@edx.org>
Jonah Stanley <Jonah_Stanley@brown.edu>
Slater Victoroff <slater.r.victoroff@gmail.com> Slater Victoroff <slater.r.victoroff@gmail.com>
...@@ -47,12 +47,6 @@ def i_see_the_course_in_my_courses(step): ...@@ -47,12 +47,6 @@ def i_see_the_course_in_my_courses(step):
assert world.css_has_text(course_css, 'Robot Super Course') assert world.css_has_text(course_css, 'Robot Super Course')
@step('the course is loaded$')
def course_is_loaded(step):
class_css = 'a.class-name'
assert world.css_has_text(course_css, 'Robot Super Cousre')
@step('I am on the "([^"]*)" tab$') @step('I am on the "([^"]*)" tab$')
def i_am_on_tab(step, tab_name): def i_am_on_tab(step, tab_name):
header_css = 'div.inner-wrapper h1' header_css = 'div.inner-wrapper h1'
......
...@@ -112,7 +112,7 @@ def all_sections_are_expanded(step): ...@@ -112,7 +112,7 @@ def all_sections_are_expanded(step):
@step(u'all sections are collapsed$') @step(u'all sections are collapsed$')
def all_sections_are_expanded(step): def all_sections_are_collapsed(step):
subsection_locator = 'div.subsection-list' subsection_locator = 'div.subsection-list'
subsections = world.css_find(subsection_locator) subsections = world.css_find(subsection_locator)
for s in subsections: for s in subsections:
......
...@@ -129,9 +129,12 @@ def should_have_link_with_id_and_text(step, link_id, text): ...@@ -129,9 +129,12 @@ def should_have_link_with_id_and_text(step, link_id, text):
assert_equals(link.text, text) assert_equals(link.text, text)
@step(r'should see "(.*)" (?:somewhere|anywhere) in (?:the|this) page') @step(r'should( not)? see "(.*)" (?:somewhere|anywhere) (?:in|on) (?:the|this) page')
def should_see_in_the_page(step, text): def should_see_in_the_page(step, doesnt_appear, text):
assert_in(text, world.css_text('body')) if doesnt_appear:
assert world.browser.is_text_not_present(text, wait_time=5)
else:
assert world.browser.is_text_present(text, wait_time=5)
@step('I am logged in$') @step('I am logged in$')
......
...@@ -32,8 +32,13 @@ def url_equals(url): ...@@ -32,8 +32,13 @@ def url_equals(url):
@world.absorb @world.absorb
def is_css_present(css_selector): def is_css_present(css_selector, wait_time=5):
return world.browser.is_element_present_by_css(css_selector, wait_time=4) return world.browser.is_element_present_by_css(css_selector, wait_time=wait_time)
@world.absorb
def is_css_not_present(css_selector, wait_time=5):
return world.browser.is_element_not_present_by_css(css_selector, wait_time=wait_time)
@world.absorb @world.absorb
...@@ -42,11 +47,11 @@ def css_has_text(css_selector, text): ...@@ -42,11 +47,11 @@ def css_has_text(css_selector, text):
@world.absorb @world.absorb
def css_find(css): def css_find(css, wait_time=5):
def is_visible(driver): def is_visible(driver):
return EC.visibility_of_element_located((By.CSS_SELECTOR, css,)) return EC.visibility_of_element_located((By.CSS_SELECTOR, css,))
world.browser.is_element_present_by_css(css, 5) world.browser.is_element_present_by_css(css, wait_time=wait_time)
wait_for(is_visible) wait_for(is_visible)
return world.browser.find_by_css(css) return world.browser.find_by_css(css)
...@@ -56,6 +61,7 @@ def css_click(css_selector): ...@@ -56,6 +61,7 @@ def css_click(css_selector):
""" """
Perform a click on a CSS selector, retrying if it initially fails Perform a click on a CSS selector, retrying if it initially fails
""" """
assert is_css_present(css_selector)
try: try:
world.browser.find_by_css(css_selector).click() world.browser.find_by_css(css_selector).click()
...@@ -89,6 +95,7 @@ def id_click(elem_id): ...@@ -89,6 +95,7 @@ def id_click(elem_id):
@world.absorb @world.absorb
def css_fill(css_selector, text): def css_fill(css_selector, text):
assert is_css_present(css_selector)
world.browser.find_by_css(css_selector).first.fill(text) world.browser.find_by_css(css_selector).first.fill(text)
...@@ -114,6 +121,7 @@ def css_text(css_selector): ...@@ -114,6 +121,7 @@ def css_text(css_selector):
@world.absorb @world.absorb
def css_visible(css_selector): def css_visible(css_selector):
assert is_css_present(css_selector)
return world.browser.find_by_css(css_selector).visible return world.browser.find_by_css(css_selector).visible
......
...@@ -12,7 +12,6 @@ def i_click_on_view_courseware(step): ...@@ -12,7 +12,6 @@ def i_click_on_view_courseware(step):
@step('I click on the "([^"]*)" tab$') @step('I click on the "([^"]*)" tab$')
def i_click_on_the_tab(step, tab_text): def i_click_on_the_tab(step, tab_text):
world.click_link(tab_text) world.click_link(tab_text)
world.save_the_html()
@step('I visit the courseware URL$') @step('I visit the courseware URL$')
...@@ -20,11 +19,6 @@ def i_visit_the_course_info_url(step): ...@@ -20,11 +19,6 @@ def i_visit_the_course_info_url(step):
world.visit('/courses/MITx/6.002x/2012_Fall/courseware') world.visit('/courses/MITx/6.002x/2012_Fall/courseware')
@step(u'I do not see "([^"]*)" anywhere on the page')
def i_do_not_see_text_anywhere_on_the_page(step, text):
assert world.browser.is_text_not_present(text)
@step(u'I am on the dashboard page$') @step(u'I am on the dashboard page$')
def i_am_on_the_dashboard_page(step): def i_am_on_the_dashboard_page(step):
assert world.is_css_present('section.courses') assert world.is_css_present('section.courses')
......
...@@ -8,10 +8,7 @@ Scenario: I can navigate to all high - level tabs in a course ...@@ -8,10 +8,7 @@ Scenario: I can navigate to all high - level tabs in a course
And The course "6.002x" has extra tab "Custom Tab" And The course "6.002x" has extra tab "Custom Tab"
And I am logged in And I am logged in
And I click on View Courseware And I click on View Courseware
When I click on the "<TabName>" tab When I click on the tabs then the page title should contain the following titles:
Then the page title should contain "<PageTitle>"
Examples:
| TabName | PageTitle | | TabName | PageTitle |
| Courseware | 6.002x Courseware | | Courseware | 6.002x Courseware |
| Course Info | 6.002x Course Info | | Course Info | 6.002x Course Info |
......
from lettuce import world, step
from nose.tools import assert_equals
@step(u'I click on the tabs then the page title should contain the following titles:')
def i_click_on_the_tab_and_check(step):
for tab_title in step.hashes:
tab_text = tab_title['TabName']
title = tab_title['PageTitle']
world.click_link(tab_text)
assert(title in world.browser.title)
...@@ -13,9 +13,7 @@ Feature: Homepage for web users ...@@ -13,9 +13,7 @@ Feature: Homepage for web users
Scenario Outline: User can see main parts of the page Scenario Outline: User can see main parts of the page
Given I visit the homepage Given I visit the homepage
Then I should see a link with the id "<id>" called "<Link>" Then I should see the following links and ids
Examples:
| id | Link | | id | Link |
| about | About | | about | About |
| jobs | Jobs | | jobs | Jobs |
...@@ -27,9 +25,7 @@ Feature: Homepage for web users ...@@ -27,9 +25,7 @@ Feature: Homepage for web users
# TODO: test according to domain or policy # TODO: test according to domain or policy
Scenario: User can see the partner institutions Scenario: User can see the partner institutions
Given I visit the homepage Given I visit the homepage
Then I should see "<Partner>" in the Partners section Then I should see the following Partners in the Partners section
Examples:
| Partner | | Partner |
| MITx | | MITx |
| HarvardX | | HarvardX |
......
...@@ -2,11 +2,22 @@ ...@@ -2,11 +2,22 @@
#pylint: disable=W0621 #pylint: disable=W0621
from lettuce import world, step from lettuce import world, step
from nose.tools import assert_in from nose.tools import assert_in, assert_equals
@step('I should see "([^"]*)" in the Partners section$') @step(u'I should see the following Partners in the Partners section')
def i_should_see_partner(step, partner): def i_should_see_partner(step):
partners = world.browser.find_by_css(".partner .name span") partners = world.browser.find_by_css(".partner .name span")
names = set(span.text for span in partners) names = set(span.text for span in partners)
assert_in(partner, names) for partner in step.hashes:
assert_in(partner['Partner'], names)
@step(u'I should see the following links and ids')
def should_see_a_link_called(step):
for link_id_pair in step.hashes:
link_id = link_id_pair['id']
text = link_id_pair['Link']
link = world.browser.find_by_id(link_id)
assert len(link) > 0
assert_equals(link.text, text)
...@@ -84,3 +84,38 @@ Feature: Answer problems ...@@ -84,3 +84,38 @@ Feature: Answer problems
| formula | incorrect | | formula | incorrect |
| script | correct | | script | correct |
| script | incorrect | | script | incorrect |
Scenario: I can answer a problem with one attempt correctly and not reset
Given I am viewing a "multiple choice" problem with "1" attempt
When I answer a "multiple choice" problem "correctly"
Then The "Reset" button does not appear
Scenario: I can answer a problem with multiple attempts correctly and still reset the problem
Given I am viewing a "multiple choice" problem with "3" attempts
Then I should see "You have used 0 of 3 submissions" somewhere in the page
When I answer a "multiple choice" problem "correctly"
Then The "Reset" button does appear
Scenario: I can view how many attempts I have left on a problem
Given I am viewing a "multiple choice" problem with "3" attempts
Then I should see "You have used 0 of 3 submissions" somewhere in the page
When I answer a "multiple choice" problem "incorrectly"
And I reset the problem
Then I should see "You have used 1 of 3 submissions" somewhere in the page
When I answer a "multiple choice" problem "incorrectly"
And I reset the problem
Then I should see "You have used 2 of 3 submissions" somewhere in the page
And The "Final Check" button does appear
When I answer a "multiple choice" problem "correctly"
Then The "Reset" button does not appear
Scenario: I can view and hide the answer if the problem has it:
Given I am viewing a "numerical" that shows the answer "always"
When I press the "Show Answer" button
Then The "Hide Answer" button does appear
And The "Show Answer" button does not appear
And I should see "4.14159" somewhere in the page
When I press the "Hide Answer" button
Then The "Show Answer" button does appear
And I should not see "4.14159" anywhere on the page
...@@ -16,5 +16,5 @@ Feature: Register for a course ...@@ -16,5 +16,5 @@ Feature: Register for a course
Then I should see the course numbered "6.002x" in my dashboard Then I should see the course numbered "6.002x" in my dashboard
When I unregister for the course numbered "6.002x" When I unregister for the course numbered "6.002x"
Then I should be on the dashboard page Then I should be on the dashboard page
And I should see "Looks like you haven't registered for any courses yet." somewhere in the page And I should see an empty dashboard message
And I should NOT see the course numbered "6.002x" in my dashboard And I should NOT see the course numbered "6.002x" in my dashboard
...@@ -19,16 +19,19 @@ def i_register_for_the_course(step, course): ...@@ -19,16 +19,19 @@ def i_register_for_the_course(step, course):
assert world.is_css_present('section.container.dashboard') assert world.is_css_present('section.container.dashboard')
@step(u'I should see the course numbered "([^"]*)" in my dashboard$') @step(u'I should see an empty dashboard message')
def i_should_see_that_course_in_my_dashboard(step, course): def i_should_see_empty_dashboard(step):
course_link_css = 'section.my-courses a[href*="%s"]' % course empty_dash_css = 'section.empty-dashboard-message'
assert world.is_css_present(course_link_css) assert world.is_css_present(empty_dash_css)
@step(u'I should NOT see the course numbered "([^"]*)" in my dashboard$') @step(u'I should( NOT)? see the course numbered "([^"]*)" in my dashboard$')
def i_should_not_see_that_course_in_my_dashboard(step, course): def i_should_see_that_course_in_my_dashboard(step, doesnt_appear, course):
course_link_css = 'section.my-courses a[href*="%s"]' % course course_link_css = 'section.my-courses a[href*="%s"]' % course
assert not world.is_css_present(course_link_css) if doesnt_appear:
assert world.is_css_not_present(course_link_css)
else:
assert world.is_css_present(course_link_css)
@step(u'I unregister for the course numbered "([^"]*)"') @step(u'I unregister for the course numbered "([^"]*)"')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment