Commit 46176fba by dragonfi

Check submit button state in mcq tests

parent 44199840
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
# Imports ########################################################### # Imports ###########################################################
import time import time
from selenium.webdriver.support.ui import WebDriverWait
from workbench import scenarios from workbench import scenarios
from workbench.test.selenium_test import SeleniumTest from workbench.test.selenium_test import SeleniumTest
...@@ -52,6 +53,11 @@ class MentoringBaseTest(SeleniumTest): ...@@ -52,6 +53,11 @@ class MentoringBaseTest(SeleniumTest):
header1 = self.browser.find_element_by_css_selector('h1') header1 = self.browser.find_element_by_css_selector('h1')
self.assertEqual(header1.text, 'XBlock scenarios') self.assertEqual(header1.text, 'XBlock scenarios')
def wait_until_disabled(self, submit):
wait = WebDriverWait(submit, 10)
wait.until(lambda s: not s.is_enabled(), "{} should be disabled".format(submit.text))
def go_to_page(self, page_name, css_selector='div.mentoring'): def go_to_page(self, page_name, css_selector='div.mentoring'):
""" """
Navigate to the page `page_name`, as listed on the workbench home Navigate to the page `page_name`, as listed on the workbench home
......
...@@ -23,18 +23,12 @@ ...@@ -23,18 +23,12 @@
# Imports ########################################################### # Imports ###########################################################
from selenium.webdriver.support.ui import WebDriverWait
from mentoring.test_base import MentoringBaseTest from mentoring.test_base import MentoringBaseTest
# Classes ########################################################### # Classes ###########################################################
class AnswerBlockTest(MentoringBaseTest): class AnswerBlockTest(MentoringBaseTest):
def wait_until_disabled(self, submit):
wait = WebDriverWait(submit, 10)
wait.until(lambda s: not s.is_enabled(), "{} should be disabled".format(submit.text))
def test_answer_edit(self): def test_answer_edit(self):
""" """
Answers of same name should share value accross blocks Answers of same name should share value accross blocks
......
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
# Imports ########################################################### # Imports ###########################################################
import time
from mentoring.test_base import MentoringBaseTest from mentoring.test_base import MentoringBaseTest
...@@ -48,7 +46,6 @@ class MCQBlockTest(MentoringBaseTest): ...@@ -48,7 +46,6 @@ class MCQBlockTest(MentoringBaseTest):
def _get_inputs(self, choices): def _get_inputs(self, choices):
return [choice.find_element_by_css_selector('input') for choice in choices] return [choice.find_element_by_css_selector('input') for choice in choices]
def test_mcq_choices_rating(self): def test_mcq_choices_rating(self):
""" """
Mentoring MCQ should display tips according to user choice Mentoring MCQ should display tips according to user choice
...@@ -58,13 +55,11 @@ class MCQBlockTest(MentoringBaseTest): ...@@ -58,13 +55,11 @@ class MCQBlockTest(MentoringBaseTest):
mcq1 = mentoring.find_element_by_css_selector('fieldset.choices') mcq1 = mentoring.find_element_by_css_selector('fieldset.choices')
mcq2 = mentoring.find_element_by_css_selector('fieldset.rating') mcq2 = mentoring.find_element_by_css_selector('fieldset.rating')
messages = mentoring.find_element_by_css_selector('.messages') messages = mentoring.find_element_by_css_selector('.messages')
# TODO: progress indicator element not available submit = mentoring.find_element_by_css_selector('.submit input.input-main')
#progress = mentoring.find_element_by_css_selector('.progress > .indicator')
self.assertEqual(messages.text, '') self.assertEqual(messages.text, '')
self.assertFalse(messages.find_elements_by_xpath('./*')) self.assertFalse(messages.find_elements_by_xpath('./*'))
#self.assertEqual(progress.text, '') self.assertFalse(submit.is_enabled())
#self.assertFalse(progress.find_elements_by_xpath('./*'))
mcq1_legend = mcq1.find_element_by_css_selector('legend') mcq1_legend = mcq1.find_element_by_css_selector('legend')
mcq2_legend = mcq2.find_element_by_css_selector('legend') mcq2_legend = mcq2.find_element_by_css_selector('legend')
...@@ -99,73 +94,49 @@ class MCQBlockTest(MentoringBaseTest): ...@@ -99,73 +94,49 @@ class MCQBlockTest(MentoringBaseTest):
self.assertEqual(mcq2_choices_input[4].get_attribute('value'), '5') self.assertEqual(mcq2_choices_input[4].get_attribute('value'), '5')
self.assertEqual(mcq2_choices_input[5].get_attribute('value'), 'notwant') self.assertEqual(mcq2_choices_input[5].get_attribute('value'), 'notwant')
# Submit without selecting anything # Submit button disabled without selecting anything
submit = mentoring.find_element_by_css_selector('.submit input.input-main') self.assertFalse(submit.is_enabled())
submit.click()
time.sleep(1)
# TODO: check that the button is not clickable
#tips = messages.find_elements_by_xpath('./*')
#self.assertEqual(len(tips), 2)
#self.assertEqual(tips[0].text, 'To the question "Do you like this MCQ?", you have not provided an answer.')
#self.assertEqual(tips[1].text, 'To the question "How much do you rate this MCQ?", you have not provided an answer.')
#self.assertEqual(progress.text, '')
#self.assertFalse(progress.find_elements_by_xpath('./*'))
# Select only one option # Submit button stays disabled when there are unfinished mcqs
self._selenium_bug_workaround_scroll_to(mcq1) self._selenium_bug_workaround_scroll_to(mcq1)
mcq1_choices_input[1].click() mcq1_choices_input[1].click()
time.sleep(1) self.assertFalse(submit.is_enabled())
submit.click()
# TODO: check that the button is not clickable
#time.sleep(1)
#tips = messages.find_elements_by_xpath('./*')
#self.assertEqual(len(tips), 2)
#self.assertEqual(tips[0].text, 'To the question "Do you like this MCQ?", you answered "Maybe not".\nAh, damn.')
#self.assertEqual(tips[1].text, 'To the question "How much do you rate this MCQ?", you have not provided an answer.')
#self.assertEqual(progress.text, '')
#self.assertFalse(progress.find_elements_by_xpath('./*'))
# One with only display tip, one with reject tip - should not complete # Should not show full completion message when wrong answers are selected
self._selenium_bug_workaround_scroll_to(mcq1) self._selenium_bug_workaround_scroll_to(mcq1)
mcq1_choices_input[0].click() mcq1_choices_input[0].click()
mcq2_choices_input[2].click() mcq2_choices_input[2].click()
time.sleep(1) self.assertTrue(submit.is_enabled())
submit.click() submit.click()
self.wait_until_disabled(submit)
time.sleep(1)
tips = messages.find_elements_by_xpath('./*')
self.assertEqual(mcq1.find_element_by_css_selector(".feedback").text, 'Great!') self.assertEqual(mcq1.find_element_by_css_selector(".feedback").text, 'Great!')
self.assertEqual(mcq2.find_element_by_css_selector(".feedback").text, 'Will do better next time...') self.assertEqual(mcq2.find_element_by_css_selector(".feedback").text, 'Will do better next time...')
#self.assertEqual(progress.text, '') self.assertEqual(messages.text, '')
#self.assertFalse(progress.find_elements_by_xpath('./*')) self.assertFalse(messages.is_displayed())
# Only display tips, to allow to complete # Should show full completion when the right answers are selected
self._selenium_bug_workaround_scroll_to(mcq1) self._selenium_bug_workaround_scroll_to(mcq1)
mcq1_choices_input[0].click() mcq1_choices_input[0].click()
mcq2_choices_input[3].click() mcq2_choices_input[3].click()
self.assertTrue(submit.is_enabled())
submit.click() submit.click()
self.wait_until_disabled(submit)
time.sleep(1)
tips = messages.find_elements_by_xpath('./*')
self.assertEqual(mcq1.find_element_by_css_selector(".feedback").text, 'Great!') self.assertEqual(mcq1.find_element_by_css_selector(".feedback").text, 'Great!')
self.assertEqual(mcq2.find_element_by_css_selector(".feedback").text, 'I love good grades.') self.assertEqual(mcq2.find_element_by_css_selector(".feedback").text, 'I love good grades.')
self.assertEqual(messages.text, 'FEEDBACK\nAll is good now...\nCongratulations!') self.assertEqual(messages.text, 'FEEDBACK\nAll is good now...\nCongratulations!')
#self.assertEqual(progress.text, '') self.assertTrue(messages.is_displayed())
#self.assertTrue(progress.find_elements_by_css_selector('img'))
def test_mcq_with_comments(self): def test_mcq_with_comments(self):
mentoring = self.go_to_page('Mcq With Comments 1') mentoring = self.go_to_page('Mcq With Comments 1')
mcq = mentoring.find_element_by_css_selector('fieldset.choices') mcq = mentoring.find_element_by_css_selector('fieldset.choices')
messages = mentoring.find_element_by_css_selector('.messages') messages = mentoring.find_element_by_css_selector('.messages')
# TODO: progress indicator element not available submit = mentoring.find_element_by_css_selector('.submit input.input-main')
#progress = mentoring.find_element_by_css_selector('.progress > .indicator')
self.assertEqual(messages.text, '') self.assertEqual(messages.text, '')
self.assertFalse(messages.find_elements_by_xpath('./*')) self.assertFalse(messages.find_elements_by_xpath('./*'))
#self.assertEqual(progress.text, '') self.assertFalse(submit.is_enabled())
#self.assertFalse(progress.find_elements_by_xpath('./*'))
mcq_legend = mcq.find_element_by_css_selector('legend') mcq_legend = mcq.find_element_by_css_selector('legend')
self.assertEqual(mcq_legend.text, 'QUESTION\nWhat do you like in this MRQ?') self.assertEqual(mcq_legend.text, 'QUESTION\nWhat do you like in this MRQ?')
......
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