Ejemplo n.º 1
0
 def setUp(self):
     """Pretest settings."""
     self.user = User('', '', '', driver_type=DRIVER)
     print(self.user.driver.get_window_size())
     self.user.set_window_size(height=700, width=1200)
     print(self.user.driver.get_window_size())
     self.server = ''.join(('https://', os.getenv('SERVER_URL')))
     self.login = os.getenv('TEACHER_USER_MULTI')
     self.password = os.getenv('TEACHER_PASSWORD')
Ejemplo n.º 2
0
 def setUp(self):
     """Pretest settings."""
     self.ps = PastaSauce()
     self.desired_capabilities['name'] = self.id()
     self.user = User(username='',
                      password='',
                      pasta_user=self.ps,
                      capabilities=self.desired_capabilities)
     self.user.get('https://qa.cnx.org/')
Ejemplo n.º 3
0
 def setUp(self):
     """Pretest settings."""
     self.user = User('', '', '')
     self.user.set_window_size(height=700, width=1200)
     self.server = ''.join(('https://', os.getenv('SERVER_URL')))
     self.login = os.getenv('STUDENT_USER_MULTI')
     self.password = os.getenv('STUDENT_PASSWORD')
Ejemplo n.º 4
0
    def setup_user_and_dates(self):
        user = User(username=os.getenv('TEACHER_USER'),
                    password=os.getenv('TEACHER_PASSWORD'),
                    existing_driver=self.driver)
        user.login()
        user.select_course(appearance='biology')

        today = datetime.date.today()
        open_on = (today + datetime.timedelta(days=3)).strftime('%m/%d/%Y')
        due_at = (today + datetime.timedelta(days=6)).strftime('%m/%d/%Y')
        return (user, open_on, due_at)
Ejemplo n.º 5
0
class TestStaxingUser(unittest.TestCase):
    """Staxing case tests for User."""

    def setUp(self):
        """Pretest settings."""
        self.user = User('', '', '')
        self.user.set_window_size(height=700, width=1200)
        self.server = ''.join(('https://', os.getenv('SERVER_URL')))
        self.login = os.getenv('STUDENT_USER_MULTI')
        self.password = os.getenv('STUDENT_PASSWORD')

    def tearDown(self):
        """Test destructor."""
        try:
            self.user.driver.quit()
        except:
            pass

    @pytest.mark.skipif(str(201) not in TESTS, reason='Excluded')
    def test_user_tutor_login(self):
        """Log into Tutor."""
        self.user.login(self.server, self.login, self.password)
        was_successful = 'dashboard' in self.user.driver.current_url or \
            'list' in self.user.driver.current_url or \
            'calendar' in self.user.driver.current_url
        assert(was_successful), 'Failed to log into %s' % self.server

    @pytest.mark.skipif(str(202) not in TESTS, reason='Excluded')
    def test_user_tutor_logout(self):
        """Log out of Tutor"""
        self.user.login(self.server, self.login, self.password)
        self.user.logout()
        was_successful = \
            'http://cc.openstax.org/' in self.user.driver.current_url or \
            'https://tutor-qa.openstax.org/?' in self.user.driver.current_url
        assert(was_successful), 'Failed to log out of %s' % self.server

    @pytest.mark.skipif(str(203) not in TESTS, reason='Excluded')
    def test_user_accounts_login(self):
        """Log into Accounts."""
        accounts = self.server.replace('tutor', 'accounts')
        self.user.login(accounts, self.login, self.password)
        assert('profile' in self.user.driver.current_url), \
            'Failed to log into %s' % accounts

    @pytest.mark.skipif(str(204) not in TESTS, reason='Excluded')
    def test_user_accounts_logout(self):
        """Log out of Accounts."""
        accounts = self.server.replace('tutor', 'accounts')
        self.user.login(accounts, self.login, self.password)
        self.user.logout()
        assert('signin' in self.user.driver.current_url), \
            'Failed to log out of %s' % accounts

    @pytest.mark.skipif(str(205) not in TESTS, reason='Excluded')
    def test_user_select_course_by_title(self):
        """Select a course by its title."""
        self.user.login(self.server, self.login, self.password)
        print(self.user.current_url())
        courses = self.user.driver.find_elements(
            By.CLASS_NAME,
            'tutor-course-item'
        )
        course_number = 0 if len(courses) <= 1 \
            else randint(1, len(courses)) - 1
        title = courses[course_number].text
        Assignment.scroll_to(self.user.driver, courses[course_number])
        self.user.select_course(title=title)
        was_successful = 'courses' in self.user.driver.current_url or \
            'list' in self.user.driver.current_url or \
            'calendar' in self.user.driver.current_url or \
            'contents' in self.user.driver.current_url
        assert(was_successful), \
            'Failed to select course in URL: %s' % self.user.driver.current_url
        if 'contents' in self.user.driver.current_url:
            return
        course_name = self.user.driver.find_element(
            By.CLASS_NAME,
            'course-name'
        ).text
        assert(title == course_name), 'Failed to select course "%s"' % title

    @pytest.mark.skipif(str(206) not in TESTS, reason='Excluded')
    def test_user_select_course_by_appearance(self):
        """Select a course by its appearance."""
        self.user.login(self.server, self.login, self.password)
        courses = self.user.driver.find_elements(
            By.CLASS_NAME,
            'tutor-booksplash-course-item'
        )
        course_number = 0 if len(courses) <= 1 \
            else randint(1, len(courses)) - 1
        appearance = courses[course_number].get_attribute('data-appearance')
        appearance_courses = self.user.driver.find_elements(
                By.XPATH,
                '//div[contains(@data-appearance,"%s")]' % appearance
            )
        title = ''
        if isinstance(appearance_courses, list):
            for course in appearance_courses:
                title = title.join((' ', course.text))
        else:
            title = courses[course_number].text
        Assignment.scroll_to(self.user.driver, courses[course_number])
        self.user.select_course(appearance=appearance)
        was_successful = 'courses' in self.user.driver.current_url or \
            'list' in self.user.driver.current_url or \
            'calendar' in self.user.driver.current_url or \
            'contents' in self.user.driver.current_url
        assert(was_successful), \
            'Failed to select course in URL: %s' % self.user.driver.current_url
        if 'contents' in self.user.driver.current_url:
            return
        course_name = self.user.driver.find_element(
            By.CLASS_NAME,
            'course-name'
        ).text
        assert(course_name in title), \
            'Failed to select course "%s"' % course_name

    @pytest.mark.skipif(str(207) not in TESTS, reason='Excluded')
    def test_user_go_to_course_list(self):
        """No test placeholder."""
        self.user.login(self.server, self.login, self.password)
        courses = self.user.driver.find_elements(
            By.CLASS_NAME,
            'tutor-course-item'
        )
        course_number = 0 if len(courses) <= 1 \
            else randint(1, len(courses)) - 1
        Assignment.scroll_to(self.user.driver, courses[course_number])
        self.user.select_course(title=courses[course_number].text)
        was_successful = 'courses' in self.user.driver.current_url or \
            'list' in self.user.driver.current_url or \
            'calendar' in self.user.driver.current_url
        assert(was_successful), 'Failed to select course'
        self.user.goto_course_list()
        course_picker = self.server + '/dashboard/'
        assert(self.user.driver.current_url == course_picker), \
            'Failed to return to the course picker'

    @pytest.mark.skipif(str(208) not in TESTS, reason='Excluded')
    def test_user_open_the_reference_book(self):
        """No test placeholder."""
        self.user.login(self.server, self.login, self.password)
        main_window = self.user.driver.current_window_handle
        courses = self.user.driver.find_elements(
            By.CLASS_NAME,
            'tutor-course-item'
        )
        course_number = 0 if len(courses) <= 1 \
            else randint(1, len(courses)) - 1
        Assignment.scroll_to(self.user.driver, courses[course_number])
        self.user.select_course(title=courses[course_number].text)
        was_successful = 'courses' in self.user.driver.current_url or \
            'list' in self.user.driver.current_url or \
            'calendar' in self.user.driver.current_url
        assert(was_successful), 'Failed to select course'
        self.user.view_reference_book()
        self.user.driver.switch_to_window(self.user.driver.window_handles[1])
        WebDriverWait(self.user.driver, 60).until(
            expect.presence_of_element_located(
                (By.CLASS_NAME, 'center-panel')
            )
        )
        assert('contents' in self.user.driver.current_url or
               'books' in self.user.driver.current_url), \
            'Failed to open the reference or WebView book.'
        self.user.driver.close()
        self.user.driver.switch_to_window(main_window)
        was_successful = 'courses' in self.user.driver.current_url or \
            'list' in self.user.driver.current_url or \
            'calendar' in self.user.driver.current_url
        assert(was_successful), 'Failed to return to the primary browser tab'
Ejemplo n.º 6
0
class TestFrontPage(unittest.TestCase):
    """CX1.01 - Front Page."""
    def setUp(self):
        """Pretest settings."""
        self.ps = PastaSauce()
        self.desired_capabilities['name'] = self.id()
        self.user = User(username='',
                         password='',
                         pasta_user=self.ps,
                         capabilities=self.desired_capabilities)
        self.user.get('https://qa.cnx.org/')

    def tearDown(self):
        """Test destructor."""
        self.ps.update_job(job_id=str(self.user.driver.session_id),
                           **self.ps.test_updates)
        try:
            self.user.delete()
        except:
            pass

    # Case C96869 - 001 - User | Support link visible
    @pytest.mark.skipif(str(96869) not in TESTS, reason='Excluded')
    def test_user_support_link_visible_96869(self):
        """See the support link.

        Steps:

        Expected Result:
        The user sees the support link.
        """
        self.ps.test_updates['name'] = 'cx1.01.001' + \
            inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['cx1', 'cx1.01', 'cx1.01.001', '96869']
        self.ps.test_updates['passed'] = False

        support = self.user.find(By.LINK_TEXT, 'Support')
        assert('openstax.force.com' in support.get_attribute('href')), \
            'Support link not seen'

        self.ps.test_updates['passed'] = True

    # Case C96870 - 002 - User | Salesforce support is available
    @pytest.mark.skipif(str(96870) not in TESTS, reason='Excluded')
    def test_user_salesforce_support_available_96870(self):
        """Open Salesforce support.

        Steps:
        Click on Support

        Expected Result:
        The user sees the support page.
        """
        self.ps.test_updates['name'] = 'cx1.01.002' + \
            inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['cx1', 'cx1.01', 'cx1.01.002', '96870']
        self.ps.test_updates['passed'] = False

        # primary_window = self.user.driver.window_handles[0]
        self.user.find(By.LINK_TEXT, 'Support').click()
        secondary_window = self.user.driver.window_handles[1]
        self.user.driver.switch_to_window(secondary_window)
        assert('CNX Help Center' in self.user.find(
                By.CSS_SELECTOR, 'center.landingHeader').text), \
            'Salesforce CNX support page not open'

        self.ps.test_updates['passed'] = True

    # Case C96871 - 003 - User | Heading links are visible
    @pytest.mark.skipif(str(96871) not in TESTS, reason='Excluded')
    def test_user_header_links_seen_96871(self):
        """See the support link.

        Steps:

        Expected Result:
        Header links are available (CNX, Search, About Us, Give, RICE)
        """
        self.ps.test_updates['name'] = 'cx1.01.003' + \
            inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['cx1', 'cx1.01', 'cx1.01.003', '96871']
        self.ps.test_updates['passed'] = False

        expected_links = ['Search', 'About Us', 'Give']

        nav_bar_brand = self.user.find(By.CSS_SELECTOR, 'a.navbar-brand')
        assert ('OpenStax CNX' in nav_bar_brand.text), 'Brand image not seen'

        found_links = []
        nav_bar = self.user.find_all(By.CSS_SELECTOR, 'div#page-nav ul li a')
        for link in nav_bar[:-1]:
            found_links.append(link.text)
            assert(link.text in expected_links), \
                '"' + link.text + '" not expected'
        for link_name in expected_links:
            assert (link_name in found_links), '"' + link_name + '" not found'

        nav_bar_rice = nav_bar[-1].find_element(By.XPATH,
                                                './img[@class="rice"]')
        assert('Rice University' in nav_bar_rice.get_attribute('alt')), \
            'Rice brand not found'

        self.ps.test_updates['passed'] = True

    # Case C96872 - 004 - User | Legacy CNX link is visible
    @pytest.mark.skipif(str(96872) not in TESTS, reason='Excluded')
    def test_user_legacy_cnx_visible_96872(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates['name'] = 'cx1.01.001' + \
            inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['cx1', 'cx1.01', 'cx1.01.001', '96872']
        self.ps.test_updates['passed'] = False

        # Test steps

        self.ps.test_updates['passed'] = True

    # Case C96873 - 005 - User | Legacy CNX available
    @pytest.mark.skipif(str(96873) not in TESTS, reason='Excluded')
    def test_user_legacy_cnx_available_96873(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates['name'] = 'cx1.01.005' + \
            inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['cx1', 'cx1.01', 'cx1.01.005', '96873']
        self.ps.test_updates['passed'] = False

        # Test steps

        self.ps.test_updates['passed'] = True

    # Case C96874 - 006 - User | All OS books are shown in the College section
    @pytest.mark.skipif(str(96874) not in TESTS, reason='Excluded')
    def test_user_all_os_books_in_college_section_96874(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates['name'] = 'cx1.01.006' + \
            inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['cx1', 'cx1.01', 'cx1.01.006', '96874']
        self.ps.test_updates['passed'] = False

        # Test steps

        self.ps.test_updates['passed'] = True

    # Case C96875 - 007 - User | Non-active books are shown in the CNX section
    @pytest.mark.skipif(str(96875) not in TESTS, reason='Excluded')
    def test_user_non_os_books_in_cnx_section_96875(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates['name'] = 'cx1.01.007' + \
            inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['cx1', 'cx1.01', 'cx1.01.007', '96875']
        self.ps.test_updates['passed'] = False

        # Test steps

        self.ps.test_updates['passed'] = True

    # Case C96876 - 008 - User | Books show part of the introduction
    @pytest.mark.skipif(str(96876) not in TESTS, reason='Excluded')
    def test_user_books_show_part_of_intro_96876(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates['name'] = 'cx1.01.008' + \
            inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['cx1', 'cx1.01', 'cx1.01.008', '96876']
        self.ps.test_updates['passed'] = False

        # Test steps

        self.ps.test_updates['passed'] = True

    # Case C96877 - 009 - User | Read More links to the book's Webview
    @pytest.mark.skipif(str(96877) not in TESTS, reason='Excluded')
    def test_user_read_more_links_to_books_webview_96877(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates['name'] = 'cx1.01.009' + \
            inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['cx1', 'cx1.01', 'cx1.01.009', '96877']
        self.ps.test_updates['passed'] = False

        # Test steps

        self.ps.test_updates['passed'] = True

    # Case C96878 - 010 - User | Book cover links to the book's Webview
    @pytest.mark.skipif(str(96878) not in TESTS, reason='Excluded')
    def test_user_book_cover_links_to_books_webview_96878(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates['name'] = 'cx1.01.010' + \
            inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['cx1', 'cx1.01', 'cx1.01.010', '96878']
        self.ps.test_updates['passed'] = False

        # Test steps

        self.ps.test_updates['passed'] = True

    # Case C96879 - 011 - User | Book title links to the book's Webview
    @pytest.mark.skipif(str(96879) not in TESTS, reason='Excluded')
    def test_user_book_title_links_to_books_webview_96879(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates['name'] = 'cx1.01.011' + \
            inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['cx1', 'cx1.01', 'cx1.01.011', '96879']
        self.ps.test_updates['passed'] = False

        # Test steps

        self.ps.test_updates['passed'] = True

    # Case C96880 - 012 - User | OpenStax CNX logo redirects to the front page
    @pytest.mark.skipif(str(96880) not in TESTS, reason='Excluded')
    def test_user_oscnx_logo_redirects_to_front_page_96880(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates['name'] = 'cx1.01.012' + \
            inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['cx1', 'cx1.01', 'cx1.01.012', '96880']
        self.ps.test_updates['passed'] = False

        # Test steps

        self.ps.test_updates['passed'] = True
Ejemplo n.º 7
0
class TestStaxingUser(unittest.TestCase):
    """Staxing case tests for User."""
    def setUp(self):
        """Pretest settings."""
        self.user = User('', '', '', driver_type=DRIVER)
        print(self.user.driver.get_window_size())
        self.user.set_window_size(height=700, width=1200)
        print(self.user.driver.get_window_size())
        self.server = ''.join(('https://', os.getenv('SERVER_URL')))
        self.login = os.getenv('TEACHER_USER_MULTI')
        self.password = os.getenv('TEACHER_PASSWORD')

    def tearDown(self):
        """Test destructor."""
        try:
            self.user.delete()
        except Exception:
            pass

    @pytest.mark.skipif(str(201) not in TESTS, reason='Excluded')
    def test_user_tutor_login_201(self):
        """Log into Tutor."""
        self.user.login(self.server, self.login, self.password)
        was_successful = 'course' in self.user.current_url() or \
                         'dashboard' in self.user.current_url() or \
                         'calendar' in self.user.current_url()
        assert (was_successful), 'Failed to log into %s' % self.server

    @pytest.mark.skipif(str(202) not in TESTS, reason='Excluded')
    def test_user_tutor_logout_202(self):
        """Log out of Tutor"""
        self.user.login(self.server, self.login, self.password)
        self.user.logout()
        was_successful = 'tutor' in self.user.current_url() and \
                         '.openstax.org' in self.user.current_url()
        assert (was_successful), 'Failed to log out of %s' % self.server

    @pytest.mark.skipif(str(203) not in TESTS, reason='Excluded')
    def test_user_accounts_login_203(self):
        """Log into Accounts."""
        accounts = self.server.replace('tutor', 'accounts')
        self.user.login(accounts, self.login, self.password)
        assert('profile' in self.user.current_url()), \
            'Failed to log into %s' % accounts

    @pytest.mark.skipif(str(204) not in TESTS, reason='Excluded')
    def test_user_accounts_logout_204(self):
        """Log out of Accounts."""
        accounts = self.server.replace('tutor', 'accounts')
        self.user.login(accounts, self.login, self.password)
        self.user.logout()
        assert('login' in self.user.current_url()), \
            'Failed to log out of %s' % accounts

    @pytest.mark.skipif(str(205) not in TESTS, reason='Excluded')
    def test_user_select_course_by_title_205(self):
        """Select a course by its title."""
        self.user.login(self.server, self.login, self.password)
        print(self.user.current_url())
        courses = self.user.get_course_list()
        course_number = 0 if len(courses) <= 1 \
            else randint(1, len(courses)) - 1
        title = courses[course_number].get_attribute('data-title')
        self.user.scroll_to(courses[course_number])
        self.user.select_course(title=title)
        position = self.user.current_url()
        was_successful = 'course' in position or \
                         'list' in position or \
                         'calendar' in position or \
                         'contents' in position
        assert(was_successful), \
            'Failed to select course in URL: %s' % position
        if 'contents' in position:
            return
        course_name = self.user.find(By.CLASS_NAME, 'title').text
        assert (title == course_name), 'Failed to select course "%s"' % title

    @pytest.mark.skipif(str(206) not in TESTS, reason='Excluded')
    def test_user_select_course_by_appearance_206(self):
        """Select a course by its appearance."""
        self.user.login(self.server, self.login, self.password)
        courses = self.user.get_course_list()
        course_number = 0 if len(courses) == 1 \
            else randint(1, len(courses)) - 1
        assert (course_number >= 0), 'No courses found.'

        appearance = courses[course_number].get_attribute('data-appearance')
        appearance_courses = self.user.find_all(
            By.XPATH, '//div[contains(@data-appearance,"%s")]' % appearance)
        title = ''
        if isinstance(appearance_courses, list):
            for course in appearance_courses:
                title = title.join((' ', course.text))
        else:
            title = courses[course_number].text
        self.user.scroll_to(courses[course_number])
        self.user.select_course(appearance=appearance)
        position = self.user.current_url()
        was_successful = 'course' in position or \
                         'list' in position or \
                         'calendar' in position or \
                         'contents' in position
        assert(was_successful), \
            'Failed to select course in URL: %s' % position
        if 'contents' in position:
            return

        course_name = self.user.find(By.CLASS_NAME, 'title').text
        assert(course_name in title.replace('\n', ' ')), \
            'Failed to select course "%s"' % course_name

    @pytest.mark.skipif(str(207) not in TESTS, reason='Excluded')
    def test_user_go_to_course_list_207(self):
        """Go to the course list."""
        self.user.login(self.server, self.login, self.password)
        courses = self.user.get_course_list()
        course_number = 0 if len(courses) <= 1 \
            else randint(1, len(courses)) - 1
        self.user.scroll_to(courses[course_number])
        self.user.select_course(
            title=courses[course_number].get_attribute('data-title'))
        url = self.user.current_url()
        was_successful = 'course' in url or \
            'list' in url or \
            'calendar' in url
        print('%s in %s == %s' %
              ('(course,list,calendar)', url, was_successful))
        assert (was_successful), 'Failed to select course'
        self.user.goto_course_list()
        course_picker = self.server + '/dashboard'
        url = self.user.current_url()
        print('%s ?= %s' % (url, course_picker))
        assert(url == course_picker), \
            'Failed to return to the course picker'

    @pytest.mark.skipif(str(208) not in TESTS, reason='Excluded')
    def test_user_open_the_reference_book_208(self):
        """Open the reference view of the textbook."""
        self.user.login(self.server, self.login, self.password)
        main_window = self.user.driver.current_window_handle
        courses = self.user.get_course_list()
        course_number = 0 if len(courses) <= 1 \
            else randint(1, len(courses)) - 1
        Assignment.scroll_to(self.user.driver, courses[course_number])
        self.user.select_course(
            title=courses[course_number].get_attribute('data-title'))
        url = self.user.current_url()
        was_successful = 'course' in url or \
            'list' in url or \
            'calendar' in url
        print('%s in %s == %s' %
              ('(course,list,calendar)', url, was_successful))
        assert (was_successful), 'Failed to select course'
        self.user.view_reference_book()
        self.user.sleep(1)
        self.user.driver.switch_to_window(self.user.driver.window_handles[1])
        WebDriverWait(self.user.driver, 60).until(
            expect.presence_of_element_located(
                (By.CLASS_NAME, 'center-panel')))
        assert('contents' in self.user.current_url() or
               'books' in self.user.current_url()), \
            'Failed to open the reference or WebView book.'
        self.user.driver.close()
        self.user.driver.switch_to_window(main_window)
        was_successful = 'course' in self.user.current_url() or \
            'list' in self.user.current_url() or \
            'calendar' in self.user.current_url()
        assert (was_successful), 'Failed to return to the primary browser tab'
Ejemplo n.º 8
0
 def setUp(self):
     """Pretest settings."""
     self.ps = PastaSauce()
     self.desired_capabilities["name"] = self.id()
     self.user = User(username="", password="", pasta_user=self.ps, capabilities=self.desired_capabilities)
     self.user.get("https://qa.cnx.org/")
Ejemplo n.º 9
0
class TestFrontPage(unittest.TestCase):
    """CX1.01 - Front Page."""

    def setUp(self):
        """Pretest settings."""
        self.ps = PastaSauce()
        self.desired_capabilities["name"] = self.id()
        self.user = User(username="", password="", pasta_user=self.ps, capabilities=self.desired_capabilities)
        self.user.get("https://qa.cnx.org/")

    def tearDown(self):
        """Test destructor."""
        self.ps.update_job(job_id=str(self.user.driver.session_id), **self.ps.test_updates)
        try:
            self.user.delete()
        except:
            pass

    # Case C96869 - 001 - User | Support link visible
    @pytest.mark.skipif(str(96869) not in TESTS, reason="Excluded")
    def test_user_support_link_visible_96869(self):
        """See the support link.

        Steps:

        Expected Result:
        The user sees the support link.
        """
        self.ps.test_updates["name"] = "cx1.01.001" + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates["tags"] = ["cx1", "cx1.01", "cx1.01.001", "96869"]
        self.ps.test_updates["passed"] = False

        support = self.user.find(By.LINK_TEXT, "Support")
        assert "openstax.force.com" in support.get_attribute("href"), "Support link not seen"

        self.ps.test_updates["passed"] = True

    # Case C96870 - 002 - User | Salesforce support is available
    @pytest.mark.skipif(str(96870) not in TESTS, reason="Excluded")
    def test_user_salesforce_support_available_96870(self):
        """Open Salesforce support.

        Steps:
        Click on Support

        Expected Result:
        The user sees the support page.
        """
        self.ps.test_updates["name"] = "cx1.01.002" + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates["tags"] = ["cx1", "cx1.01", "cx1.01.002", "96870"]
        self.ps.test_updates["passed"] = False

        # primary_window = self.user.driver.window_handles[0]
        self.user.find(By.LINK_TEXT, "Support").click()
        secondary_window = self.user.driver.window_handles[1]
        self.user.driver.switch_to_window(secondary_window)
        assert (
            "CNX Help Center" in self.user.find(By.CSS_SELECTOR, "center.landingHeader").text
        ), "Salesforce CNX support page not open"

        self.ps.test_updates["passed"] = True

    # Case C96871 - 003 - User | Heading links are visible
    @pytest.mark.skipif(str(96871) not in TESTS, reason="Excluded")
    def test_user_header_links_seen_96871(self):
        """See the support link.

        Steps:

        Expected Result:
        Header links are available (CNX, Search, About Us, Give, RICE)
        """
        self.ps.test_updates["name"] = "cx1.01.003" + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates["tags"] = ["cx1", "cx1.01", "cx1.01.003", "96871"]
        self.ps.test_updates["passed"] = False

        expected_links = ["Search", "About Us", "Give"]

        nav_bar_brand = self.user.find(By.CSS_SELECTOR, "a.navbar-brand")
        assert "OpenStax CNX" in nav_bar_brand.text, "Brand image not seen"

        found_links = []
        nav_bar = self.user.find_all(By.CSS_SELECTOR, "div#page-nav ul li a")
        for link in nav_bar[:-1]:
            found_links.append(link.text)
            assert link.text in expected_links, '"' + link.text + '" not expected'
        for link_name in expected_links:
            assert link_name in found_links, '"' + link_name + '" not found'

        nav_bar_rice = nav_bar[-1].find_element(By.XPATH, './img[@class="rice"]')
        assert "Rice University" in nav_bar_rice.get_attribute("alt"), "Rice brand not found"

        self.ps.test_updates["passed"] = True

    # Case C96872 - 004 - User | Legacy CNX link is visible
    @pytest.mark.skipif(str(96872) not in TESTS, reason="Excluded")
    def test_user_legacy_cnx_visible_96872(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates["name"] = "cx1.01.001" + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates["tags"] = ["cx1", "cx1.01", "cx1.01.001", "96872"]
        self.ps.test_updates["passed"] = False

        # Test steps

        self.ps.test_updates["passed"] = True

    # Case C96873 - 005 - User | Legacy CNX available
    @pytest.mark.skipif(str(96873) not in TESTS, reason="Excluded")
    def test_user_legacy_cnx_available_96873(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates["name"] = "cx1.01.005" + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates["tags"] = ["cx1", "cx1.01", "cx1.01.005", "96873"]
        self.ps.test_updates["passed"] = False

        # Test steps

        self.ps.test_updates["passed"] = True

    # Case C96874 - 006 - User | All OS books are shown in the College section
    @pytest.mark.skipif(str(96874) not in TESTS, reason="Excluded")
    def test_user_all_os_books_in_college_section_96874(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates["name"] = "cx1.01.006" + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates["tags"] = ["cx1", "cx1.01", "cx1.01.006", "96874"]
        self.ps.test_updates["passed"] = False

        # Test steps

        self.ps.test_updates["passed"] = True

    # Case C96875 - 007 - User | Non-active books are shown in the CNX section
    @pytest.mark.skipif(str(96875) not in TESTS, reason="Excluded")
    def test_user_non_os_books_in_cnx_section_96875(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates["name"] = "cx1.01.007" + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates["tags"] = ["cx1", "cx1.01", "cx1.01.007", "96875"]
        self.ps.test_updates["passed"] = False

        # Test steps

        self.ps.test_updates["passed"] = True

    # Case C96876 - 008 - User | Books show part of the introduction
    @pytest.mark.skipif(str(96876) not in TESTS, reason="Excluded")
    def test_user_books_show_part_of_intro_96876(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates["name"] = "cx1.01.008" + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates["tags"] = ["cx1", "cx1.01", "cx1.01.008", "96876"]
        self.ps.test_updates["passed"] = False

        # Test steps

        self.ps.test_updates["passed"] = True

    # Case C96877 - 009 - User | Read More links to the book's Webview
    @pytest.mark.skipif(str(96877) not in TESTS, reason="Excluded")
    def test_user_read_more_links_to_books_webview_96877(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates["name"] = "cx1.01.009" + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates["tags"] = ["cx1", "cx1.01", "cx1.01.009", "96877"]
        self.ps.test_updates["passed"] = False

        # Test steps

        self.ps.test_updates["passed"] = True

    # Case C96878 - 010 - User | Book cover links to the book's Webview
    @pytest.mark.skipif(str(96878) not in TESTS, reason="Excluded")
    def test_user_book_cover_links_to_books_webview_96878(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates["name"] = "cx1.01.010" + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates["tags"] = ["cx1", "cx1.01", "cx1.01.010", "96878"]
        self.ps.test_updates["passed"] = False

        # Test steps

        self.ps.test_updates["passed"] = True

    # Case C96879 - 011 - User | Book title links to the book's Webview
    @pytest.mark.skipif(str(96879) not in TESTS, reason="Excluded")
    def test_user_book_title_links_to_books_webview_96879(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates["name"] = "cx1.01.011" + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates["tags"] = ["cx1", "cx1.01", "cx1.01.011", "96879"]
        self.ps.test_updates["passed"] = False

        # Test steps

        self.ps.test_updates["passed"] = True

    # Case C96880 - 012 - User | OpenStax CNX logo redirects to the front page
    @pytest.mark.skipif(str(96880) not in TESTS, reason="Excluded")
    def test_user_oscnx_logo_redirects_to_front_page_96880(self):
        """See the support link.

        Steps:

        Expected Result:

        """
        self.ps.test_updates["name"] = "cx1.01.012" + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates["tags"] = ["cx1", "cx1.01", "cx1.01.012", "96880"]
        self.ps.test_updates["passed"] = False

        # Test steps

        self.ps.test_updates["passed"] = True