Commit 3308bb4b by JonahStanley

Fixed pull request comments and refactored the duplicate code

parent a49acc73
...@@ -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)
else:
assert_in(text, world.css_text('body'))
@step('I am logged in$') @step('I am logged in$')
......
...@@ -42,11 +42,11 @@ def css_has_text(css_selector, text): ...@@ -42,11 +42,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 +56,7 @@ def css_click(css_selector): ...@@ -56,6 +56,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()
...@@ -81,6 +82,7 @@ def css_click_at(css, x=10, y=10): ...@@ -81,6 +82,7 @@ def css_click_at(css, x=10, y=10):
@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)
...@@ -101,6 +103,7 @@ def css_text(css_selector): ...@@ -101,6 +103,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
......
...@@ -86,51 +86,32 @@ Feature: Answer problems ...@@ -86,51 +86,32 @@ Feature: Answer problems
| script | incorrect | | script | incorrect |
Scenario: I can answer a problem with one attempt correctly Scenario: I can answer a problem with one attempt correctly and not reset
Given I am viewing a "multiple choice" problem with "1" attempt Given I am viewing a "multiple choice" problem with "1" attempt
Then I should see "You have used 0 of 1 submissions" somewhere in the page
And The "Final Check" button does appear
When I answer a "multiple choice" problem "correctly" When I answer a "multiple choice" problem "correctly"
Then My "multiple choice" answer is marked "correct" Then The "Reset" button does not appear
And The "multiple choice" problem displays a "correct" answer
And The "Reset" button does not appear
Scenario: I can answer a problem with one attempt incorrectly
Given I am viewing a "multiple choice" problem with "1" attempt
When I answer a "multiple choice" problem "incorrectly"
Then My "multiple choice" answer is marked "incorrect"
And The "multiple choice" problem displays a "incorrect" answer
And The "Reset" button does not appear
Scenario: I can answer a problem with multiple attempts correctly 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 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 Then I should see "You have used 0 of 3 submissions" somewhere in the page
When I answer a "multiple choice" problem "correctly" When I answer a "multiple choice" problem "correctly"
Then My "multiple choice" answer is marked "correct" Then The "Reset" button does appear
And The "multiple choice" problem displays a "correct" answer
And The "Reset" button does appear
Scenario: I can answer a problem with multiple attempts correctly on final guess Scenario: I can view how many attempts I have left on a problem
Given I am viewing a "multiple choice" problem with "3" attempts 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 Then I should see "You have used 0 of 3 submissions" somewhere in the page
When I answer a "multiple choice" problem "incorrectly" When I answer a "multiple choice" problem "incorrectly"
Then My "multiple choice" answer is marked "incorrect" And I reset the problem
And The "multiple choice" problem displays a "incorrect" answer
When I reset the problem
Then I should see "You have used 1 of 3 submissions" somewhere in the page Then I should see "You have used 1 of 3 submissions" somewhere in the page
When I answer a "multiple choice" problem "incorrectly" When I answer a "multiple choice" problem "incorrectly"
Then My "multiple choice" answer is marked "incorrect" And I reset the problem
And The "multiple choice" problem displays a "incorrect" answer
When I reset the problem
Then I should see "You have used 2 of 3 submissions" somewhere in the page Then I should see "You have used 2 of 3 submissions" somewhere in the page
And The "Final Check" button does appear And The "Final Check" button does appear
When I answer a "multiple choice" problem "correctly" When I answer a "multiple choice" problem "correctly"
Then My "multiple choice" answer is marked "correct" Then The "Reset" button does not appear
And The "multiple choice" problem displays a "correct" answer
And The "Reset" button does not appear
Scenario: I can view and hide the answer if the problem has it: 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 am viewing a "numerical" that shows the answer "always"
Then The "Show Answer" button does appear Then The "Show Answer" button does appear
When I press the "Show Answer" button When I press the "Show Answer" button
Then The "Hide Answer" button does appear Then The "Hide Answer" button does appear
...@@ -138,4 +119,4 @@ Feature: Answer problems ...@@ -138,4 +119,4 @@ Feature: Answer problems
And I should see "4.14159" somewhere in the page And I should see "4.14159" somewhere in the page
When I press the "Hide Answer" button When I press the "Hide Answer" button
Then The "Show Answer" button does appear Then The "Show Answer" button does appear
And I do not see "4.14159" anywhere on the page And I should not see "4.14159" anywhere on the page
...@@ -8,7 +8,7 @@ Steps for problem.feature lettuce tests ...@@ -8,7 +8,7 @@ Steps for problem.feature lettuce tests
from lettuce import world, step from lettuce import world, step
from lettuce.django import django_url from lettuce.django import django_url
from common import i_am_registered_for_the_course, TEST_SECTION_NAME from common import i_am_registered_for_the_course, TEST_SECTION_NAME
from problems_setup import * from problems_setup import PROBLEM_DICT, answer_problem, problem_has_answer, add_problem_to_course
@step(u'I am viewing a "([^"]*)" problem with "([^"]*)" attempt') @step(u'I am viewing a "([^"]*)" problem with "([^"]*)" attempt')
...@@ -116,21 +116,13 @@ def reset_problem(step): ...@@ -116,21 +116,13 @@ def reset_problem(step):
world.css_click('input.reset') world.css_click('input.reset')
@step(u'The "([^"]*)" button does not appear') @step(u'The "([^"]*)" button does( not)? appear')
def action_button_not_present(step, buttonname): def action_button_present(step, buttonname, doesnt_appear):
button_css = 'section.action input[value*="%s"]' % buttonname button_css = 'section.action input[value*="%s"]' % buttonname
assert not world.is_css_present(button_css) if doesnt_appear:
assert not world.is_css_present(button_css)
else:
@step(u'The "([^"]*)" button does appear') assert world.is_css_present(button_css)
def action_button_present(step, buttonname):
button_css = 'section.action input[value*="%s"]' % buttonname
assert world.is_css_present(button_css)
@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'My "([^"]*)" answer is marked "([^"]*)"') @step(u'My "([^"]*)" answer is marked "([^"]*)"')
......
#pylint: disable=C0111
#pylint: disable=W0621
#EVERY PROBLEM TYPE MUST HAVE THE FOLLOWING: #EVERY PROBLEM TYPE MUST HAVE THE FOLLOWING:
# -Section in Dictionary containing: # -Section in Dictionary containing:
# -factory # -factory
......
...@@ -19,16 +19,13 @@ def i_register_for_the_course(step, course): ...@@ -19,16 +19,13 @@ 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( NOT)? see the course numbered "([^"]*)" in my dashboard$')
def i_should_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 world.is_css_present(course_link_css) if doesnt_appear:
assert not world.is_css_present(course_link_css)
else:
@step(u'I should NOT see the course numbered "([^"]*)" in my dashboard$') assert world.is_css_present(course_link_css)
def i_should_not_see_that_course_in_my_dashboard(step, course):
course_link_css = 'section.my-courses a[href*="%s"]' % course
assert not 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