Commit d6880218 by Tyler Hallada

Add a11y form bok-choy tests

Address PR comments

Attempt to fix bok-choy tests?
parent 6db93fc7
...@@ -3,6 +3,7 @@ Studio Index, home and dashboard pages. These are the starting pages for users. ...@@ -3,6 +3,7 @@ Studio Index, home and dashboard pages. These are the starting pages for users.
""" """
from bok_choy.page_object import PageObject from bok_choy.page_object import PageObject
from selenium.webdriver import ActionChains from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from common.test.acceptance.pages.studio import BASE_URL from common.test.acceptance.pages.studio import BASE_URL
from common.test.acceptance.pages.studio.login import LoginPage from common.test.acceptance.pages.studio.login import LoginPage
...@@ -287,3 +288,71 @@ class HomePage(DashboardPage): ...@@ -287,3 +288,71 @@ class HomePage(DashboardPage):
Home page for Studio when logged in. Home page for Studio when logged in.
""" """
url = BASE_URL + "/home/" url = BASE_URL + "/home/"
class AccessibilityPage(IndexPage):
"""
Home page for Studio when logged in.
"""
url = BASE_URL + "/accessibility"
def is_browser_on_page(self):
"""
Is the page header visible?
"""
return self.q(css='#root h2').visible
def header_text_on_page(self):
"""
Check that the page header has the right text.
"""
return 'Individualized Accessibility Process for Course Creators' in self.q(css='#root h2').text
def fill_form(self, email, name, message):
"""
Fill the accessibility feedback form out.
"""
email_input = self.q(css='#root input#email')
name_input = self.q(css='#root input#fullName')
message_input = self.q(css='#root textarea#message')
email_input.fill(email)
name_input.fill(name)
message_input.fill(message)
# Tab off the message textarea to trigger any error messages
message_input[0].send_keys(Keys.TAB)
def submit_form(self):
"""
Click the submit button on the accessibiltiy feedback form.
"""
button = self.q(css='#root section button')[0]
button.click()
self.wait_for_element_visibility('#root div.alert-dialog', 'Form submission alert is visible')
def leave_field_blank(self, field_id, field_type='input'):
"""
To simulate leaving a field blank, click on the field, then press TAB to move off focus off the field.
"""
field = self.q(css='#root {}#{}'.format(field_type, field_id))[0]
field.click()
field.send_keys(Keys.TAB)
def alert_has_text(self, text=''):
"""
Check that the alert dialog contains the specified text.
"""
return text in self.q(css='#root div.alert-dialog').text
def error_message_is_shown_with_text(self, field_id, text=''):
"""
Check that at least one error message is shown and at least one contains the specified text.
"""
selector = '#root div#error-{}'.format(field_id)
self.wait_for_element_visibility(selector, 'An error message is visible')
error_messages = self.q(css=selector)
for message in error_messages:
if text in message.text:
return True
return False
"""
Bok-choy tests for the Studio Accessibility Feedback page.
"""
import ddt
from common.test.acceptance.pages.studio.index import AccessibilityPage
from common.test.acceptance.tests.helpers import AcceptanceTest
@ddt.ddt
class AccessibilityPageTest(AcceptanceTest):
"""
Test that a user can access the page and submit studio accessibility feedback.
"""
def setUp(self):
"""
Load the helper for the accessibility page.
"""
super(AccessibilityPageTest, self).setUp()
self.accessibility_page = AccessibilityPage(self.browser)
def test_page_loads(self):
"""
Test if the page loads and that there is a header and input elements.
"""
self.accessibility_page.visit()
self.assertTrue(self.accessibility_page.header_text_on_page())
def test_successful_submit(self):
"""
Test filling out the accessibility feedback form out and submitting.
"""
self.accessibility_page.visit()
self.accessibility_page.fill_form(email='bokchoy@edx.org', name='Bok-choy', message='I\'m testing you.')
self.accessibility_page.submit_form()
@ddt.data(
('email', 'Enter a valid email address', '', 'Bok-choy', 'I\'m testing you.'),
('fullName', 'Enter a name', 'bokchoy@edx.org', '', 'I\'m testing you.'),
('message', 'Enter a message', 'bokchoy@edx.org', 'Bok-choy', ''),
)
@ddt.unpack
def test_error_submit(self, field_missing, error_message_text, email, name, message):
"""
Test filling out the accessibility feedback form out with each field missing and then submitting.
"""
self.accessibility_page.visit()
self.accessibility_page.fill_form(email=email, name=name, message=message)
self.accessibility_page.error_message_is_shown_with_text(field_missing, text=error_message_text)
self.accessibility_page.submit_form()
self.accessibility_page.alert_has_text(error_message_text)
def test_error_messages(self):
self.accessibility_page.visit()
self.check_error_message('email', 'Enter a valid email address')
self.check_error_message('fullName', 'Enter a name')
self.check_error_message('message', 'Enter a message', field_type='textarea')
def check_error_message(self, field_id, error_message_text, field_type='input'):
self.accessibility_page.leave_field_blank(field_id, field_type=field_type)
self.accessibility_page.error_message_is_shown_with_text(field_id, text=error_message_text)
...@@ -10,7 +10,7 @@ from common.test.acceptance.pages.studio.asset_index import AssetIndexPage ...@@ -10,7 +10,7 @@ from common.test.acceptance.pages.studio.asset_index import AssetIndexPage
from common.test.acceptance.pages.studio.course_info import CourseUpdatesPage from common.test.acceptance.pages.studio.course_info import CourseUpdatesPage
from common.test.acceptance.pages.studio.edit_tabs import PagesPage from common.test.acceptance.pages.studio.edit_tabs import PagesPage
from common.test.acceptance.pages.studio.import_export import ExportCoursePage, ImportCoursePage from common.test.acceptance.pages.studio.import_export import ExportCoursePage, ImportCoursePage
from common.test.acceptance.pages.studio.index import DashboardPage, HomePage, IndexPage from common.test.acceptance.pages.studio.index import DashboardPage, HomePage, IndexPage, AccessibilityPage
from common.test.acceptance.pages.studio.login import CourseOutlineSignInRedirectPage, LoginPage from common.test.acceptance.pages.studio.login import CourseOutlineSignInRedirectPage, LoginPage
from common.test.acceptance.pages.studio.overview import CourseOutlinePage from common.test.acceptance.pages.studio.overview import CourseOutlinePage
from common.test.acceptance.pages.studio.settings import SettingsPage from common.test.acceptance.pages.studio.settings import SettingsPage
...@@ -28,7 +28,8 @@ class LoggedOutTest(AcceptanceTest): ...@@ -28,7 +28,8 @@ class LoggedOutTest(AcceptanceTest):
""" """
def setUp(self): def setUp(self):
super(LoggedOutTest, self).setUp() super(LoggedOutTest, self).setUp()
self.pages = [LoginPage(self.browser), IndexPage(self.browser), SignupPage(self.browser)] self.pages = [LoginPage(self.browser), IndexPage(self.browser), SignupPage(self.browser),
AccessibilityPage(self.browser)]
def test_page_existence(self): def test_page_existence(self):
""" """
......
...@@ -14,5 +14,13 @@ ...@@ -14,5 +14,13 @@
"name": "course_experience.enable_course_goals", "name": "course_experience.enable_course_goals",
"everyone": true "everyone": true
} }
},
{
"pk": 1,
"model": "waffle.switch",
"fields": {
"name": "accessibility.enable_policy_page",
"active": true
}
} }
] ]
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