# Path: testapp/app/app/tests/utils.py
# class element_has_css_class(object):
#     """An expectation for checking that an element has a particular css class.
#     locator - used to find the element
#     returns the WebElement once it has the particular css class
#     """
# 
#     def __init__(self, locator, css_class):
#         self.locator = locator
#         self.css_class = css_class
# 
#     def __call__(self, driver):
#         element = driver.find_element(*self.locator)   # Finding the referenced element
#         if self.css_class in element.get_attribute("class"):
#             return element
#         else:
#             return False


import time
import os
from django.test import TestCase
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
from .utils import element_has_css_class

        # site title
        site_name = self.driver.find_element_by_css_selector("#site-name a")
        self.assertEqual(
            site_name.get_attribute('innerHTML'), 'Baton Test App')

    def test_content(self):
        # Wait until baton is ready
        wait = WebDriverWait(self.driver, 10)
        wait.until(element_has_css_class((By.TAG_NAME, 'body'), "baton-ready"))

        time.sleep(1)

        # page title
        page_title = self.driver.find_element_by_css_selector(
            "#content h1")
        self.assertEqual(page_title.get_attribute('innerHTML'), 'Baton administration')
        self.assertEqual(page_title.is_displayed(), True)

        # recent actions
        recent_actions = self.driver.find_element_by_id('recent-actions-module')
        self.assertEqual(recent_actions.is_displayed(), True)

        modules = self.driver.find_elements_by_css_selector(
            "#content-main .module")
        self.assertEqual(len(modules), 3)

    def test_footer(self):
        # Wait until baton is ready
        wait = WebDriverWait(self.driver, 10)

# Path: testapp/app/app/tests/utils.py
# class element_has_css_class(object):
#     """An expectation for checking that an element has a particular css class.
#     locator - used to find the element
#     returns the WebElement once it has the particular css class
#     """
# 
#     def __init__(self, locator, css_class):
#         self.locator = locator
#         self.css_class = css_class
# 
#     def __call__(self, driver):
#         element = driver.find_element(*self.locator)   # Finding the referenced element
#         if self.css_class in element.get_attribute("class"):
#             return element
#         else:
#             return False


# Path: testapp/app/app/tests/test_e2e_index.py
import time
import os
from django.test import TestCase
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
from .utils import element_has_css_class


        # site title
        site_name = self.driver.find_element_by_css_selector("#site-name a")
        self.assertEqual(
            site_name.get_attribute('innerHTML'), 'Baton Test App')

    def test_content(self):
        # Wait until baton is ready
        wait = WebDriverWait(self.driver, 10)
        wait.until(element_has_css_class((By.TAG_NAME, 'body'), "baton-ready"))

        time.sleep(1)

        # page title
        page_title = self.driver.find_element_by_css_selector(
            "#content h1")
        self.assertEqual(page_title.get_attribute('innerHTML'), 'Baton administration')
        self.assertEqual(page_title.is_displayed(), True)

        # recent actions
        recent_actions = self.driver.find_element_by_id('recent-actions-module')
        self.assertEqual(recent_actions.is_displayed(), True)

        modules = self.driver.find_elements_by_css_selector(
            "#content-main .module")
        self.assertEqual(len(modules), 3)

    def test_footer(self):
        # Wait until baton is ready
        wait = WebDriverWait(self.driver, 10)

        wait.until(element_has_css_class((By.TAG_NAME, 'body'), "baton-ready"))