diff --git a/common/test/acceptance/pages/studio/textbooks.py b/common/test/acceptance/pages/studio/textbooks.py
index f0c6d03dc8..5f8a06bb19 100644
--- a/common/test/acceptance/pages/studio/textbooks.py
+++ b/common/test/acceptance/pages/studio/textbooks.py
@@ -2,7 +2,10 @@
Course Textbooks page.
"""
+import requests
+from path import path # pylint: disable=no-name-in-module
from .course_page import CoursePage
+from .utils import click_css
class TextbooksPage(CoursePage):
@@ -14,3 +17,64 @@ class TextbooksPage(CoursePage):
def is_browser_on_page(self):
return self.q(css='body.view-textbooks').present
+
+ def open_add_textbook_form(self):
+ """
+ Open new textbook form by clicking on new textbook button.
+ """
+ self.q(css='.nav-item .new-button').click()
+
+ def get_element_text(self, selector):
+ """
+ Return the text of the css selector.
+ """
+ return self.q(css=selector)[0].text
+
+ def set_input_field_value(self, selector, value):
+ """
+ Set the value of input field by selector.
+ """
+ self.q(css=selector)[0].send_keys(value)
+
+ def upload_pdf_file(self, file_name):
+ """
+ Uploads a pdf textbook.
+ """
+ # If the pdf upload section has not yet been toggled on, click on the upload pdf button
+ test_dir = path(__file__).abspath().dirname().dirname().dirname()
+ file_path = test_dir + '/data/uploads/' + file_name
+
+ click_css(self, ".edit-textbook .action-upload", require_notification=False)
+ self.wait_for_element_visibility(".upload-dialog input", "Upload modal opened")
+ file_input = self.q(css=".upload-dialog input").results[0]
+ file_input.send_keys(file_path)
+ click_css(self, ".wrapper-modal-window-assetupload .action-upload", require_notification=False)
+ self.wait_for_element_absence(".upload dialog", "Upload modal closed")
+
+ def click_textbook_submit_button(self):
+ """
+ Submit the new textbook form and check if it is rendered properly.
+ """
+ def click_save():
+ """
+ Continue to click the save button until the form is no longer present. Without this,
+ the test sporadically fails because the click is too early.
+ """
+ save_button = self.q(css='#edit_textbook_form button[type="submit"]').results
+ if len(save_button) > 0:
+ save_button[0].click()
+ return not self.q(css="#edit_textbook_form").present
+
+ self.wait_for(click_save, "Editing form should close.")
+
+ def is_view_live_link_worked(self):
+ """
+ Check if the view live button of textbook is working fine.
+ """
+ try:
+ self.wait_for(lambda: len(self.q(css='.textbook a.view').attrs('href')) > 0, "href value present")
+ response = requests.get(self.q(css='.textbook a.view').attrs('href')[0])
+ except requests.exceptions.ConnectionError:
+ return False
+
+ return response.status_code == 200
diff --git a/common/test/acceptance/tests/studio/test_studio_textbooks.py b/common/test/acceptance/tests/studio/test_studio_textbooks.py
new file mode 100644
index 0000000000..53ce2a6e3a
--- /dev/null
+++ b/common/test/acceptance/tests/studio/test_studio_textbooks.py
@@ -0,0 +1,51 @@
+"""
+Acceptance tests for Studio related to the textbooks.
+"""
+from common.test.acceptance.tests.studio.base_studio_test import StudioCourseTest
+from ...pages.studio.textbooks import TextbooksPage
+from ...tests.helpers import disable_animations
+from nose.plugins.attrib import attr
+
+
+@attr('shard_2')
+class TextbooksTest(StudioCourseTest):
+ """
+ Test that textbook functionality is working properly on studio side
+ """
+ def setUp(self, is_staff=True):
+ """
+ Install a course with no content using a fixture.
+ """
+ super(TextbooksTest, self).setUp(is_staff)
+ self.textbook_page = TextbooksPage(
+ self.browser,
+ self.course_info['org'],
+ self.course_info['number'],
+ self.course_info['run']
+ )
+ self.textbook_page.visit()
+ disable_animations(self)
+
+ def test_create_first_book_message(self):
+ """
+ Scenario: A message is displayed on the textbooks page when there are no uploaded textbooks
+ Given that I am viewing the Textbooks page in Studio
+ And I have not yet uploaded a textbook
+ Then I see a message stating that I have not uploaded any textbooks
+ """
+ message = self.textbook_page.get_element_text('.wrapper-content .no-textbook-content')
+ self.assertIn("You haven't added any textbooks", message)
+
+ def test_new_textbook_upload(self):
+ """
+ Scenario: View Live link for textbook is correctly populated
+ Given that I am viewing the Textbooks page in Studio
+ And I have uploaded a PDF textbook and save the new textbook information
+ Then the "View Live" link contains a link to the textbook in the LMS
+ """
+ self.textbook_page.open_add_textbook_form()
+ self.textbook_page.upload_pdf_file('textbook.pdf')
+ self.textbook_page.set_input_field_value('.edit-textbook #textbook-name-input', 'book_1')
+ self.textbook_page.set_input_field_value('.edit-textbook #chapter1-name', 'chapter_1')
+ self.textbook_page.click_textbook_submit_button()
+ self.assertTrue(self.textbook_page.is_view_live_link_worked())