from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
import unittest, time

browser = webdriver.Firefox()

class TestContent(unittest.TestCase):

    def test_login_no_email_no_password(self):
        browser.get("http://127.0.0.1:2368/ghost/")
        browser.find_element_by_css_selector("button.btn.btn-blue").click()
        no_email = browser.find_element_by_css_selector("span.notification-message")
        browser.find_element_by_css_selector("button.close").click()
        no_password = browser.find_element_by_css_selector("span.notification-message")
        if no_email.text == "Invalid Email":
            success = True
        if no_password.text == "Please enter a password":
            success = True
        browser.find_element_by_css_selector("button.close").click()
        if success != True:
            assert fail();

    def test_login_no_email(self):
        browser.get("http://127.0.0.1:2368/ghost/")
        browser.find_element_by_xpath("//input[@placeholder='Password']").send_keys("12345")
        browser.find_element_by_css_selector("button.btn.btn-blue").click()
        no_email = browser.find_element_by_css_selector("span.notification-message")
        assert "Invalid Email" in no_email.text
        browser.find_element_by_css_selector("button.close").click()

    def test_login_no_password(self):
        browser.get("http://127.0.0.1:2368/ghost/")
        browser.find_element_by_xpath("//input[@placeholder='Email Address']").send_keys("vitor@vitor.com.br")
        browser.find_element_by_css_selector("button.btn.btn-blue").click()
        no_password = browser.find_element_by_css_selector("span.notification-message")
        assert "Please enter a password" in no_password.text
        browser.find_element_by_css_selector("button.close").click()

    def test_login_invalid_email(self):
        browser.get("http://127.0.0.1:2368/ghost/")
        browser.find_element_by_xpath("//input[@placeholder='Email Address']").send_keys("vitor")
        browser.find_element_by_xpath("//input[@placeholder='Password']").send_keys("1234")
        browser.find_element_by_css_selector("button.btn.btn-blue").click()
        invalid_email = browser.find_element_by_css_selector("span.notification-message")
        assert "Invalid Email" in invalid_email.text
        browser.find_element_by_css_selector("button.close").click()

    def test_login_invalid_password(self):
        browser.get("http://127.0.0.1:2368/ghost/")
        browser.find_element_by_xpath("//input[@placeholder='Email Address']").send_keys("vitormff@gmail.com")
        browser.find_element_by_xpath("//input[@placeholder='Password']").send_keys("1234")
        browser.find_element_by_css_selector("button.btn.btn-blue").click()
        invalid_password = browser.find_element_by_css_selector("span.notification-message")
        assert "Your password is incorrect." in invalid_password.text
        browser.find_element_by_css_selector("button.close").click()

    def test_login_user_inactive(self):
        browser.get("http://127.0.0.1:2368/ghost/")
        browser.find_element_by_xpath("//input[@placeholder='Email Address']").send_keys("vitormff@gmail.com")
        browser.find_element_by_xpath("//input[@placeholder='Password']").send_keys("12345678")
        browser.find_element_by_css_selector("button.btn.btn-blue").click()
        user_inactive = browser.find_element_by_css_selector("span.notification-message")
        assert "The user with that email address is inactive." in user_inactive.text

   # def test_login_user_blocked(self):

   # def test_login_forgotten_password(self):

    def test_login_success(self):
        browser.get("http://127.0.0.1:2368/ghost/")
        browser.find_element_by_xpath("//input[@placeholder='Email Address']").send_keys("vitor@fragoso.me")
        browser.find_element_by_xpath("//input[@placeholder='Password']").send_keys("12345678")
        browser.find_element_by_css_selector("button.btn.btn-blue").click()
        #menu = browser.find_element_by_css_selector("button.menu-button.js-menu-button")
        wait = WebDriverWait(browser,10)
        element = wait.until(EC.element_to_be_clickable((By.css_selector,"button.menu-button.js-menu-button")))
        browser.find_element_by_css_selector("button.menu-button.js-menu-button").click()
        #assert "Visit blog" in verifyText.text


    def test_title(self):
        browser.get("http://127.0.0.1:2368/ghost/")
       # assert "Content - " in  browser.title

    @classmethod
    def tearDownClass(cls):
        browser.quit()

if __name__ == "__main__":
    unittest.main()
