import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager
from time import sleep
from colorama import init
init(autoreset=True)

submission_field = '/html/body/div[2]/section/div[1]/span/a[1]/label'
login_field = '//*[@id="login-form"]/div[2]/input[1]'
pass_field = 'password'
submit_button = '//*[@id="login-form"]/button'
e_mail = 'id_send_email'
address = 'send_to'
subject = '//*[@id="subject"]'
main_text = 'body'
send = '//*[@id="b3_cnt"]/div[2]/div[1]/div[1]/input[2]'
validation = 'https://webmail.meta.ua/?mailbox=INBOX&newsort=0&startMessage=1&mail_sent=yes'

RED = '\033[0;31m'
GREEN = '\033[0;36m'



class Meta_ua_login(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome(ChromeDriverManager().install())

    def test_login(self):
        self.driver.get("https://meta.ua/")
        sleep(2)
        self.driver.find_element_by_xpath(submission_field).click()
        sleep(2)

        login = self.driver.find_element_by_xpath(login_field)
        login.send_keys('avsitidiiskyi12')
        sleep(2)
        password = self.driver.find_element_by_name(pass_field)
        password.send_keys('Domination12')
        sleep(2)

        self.driver.find_element_by_xpath(submit_button).click()

        sleep(2)
        self.driver.find_element_by_id(e_mail).click()

        address_field = self.driver.find_element_by_id(address)
        address_field.send_keys('avsitidiiskyi@gmail.com')
        sleep(2)

        subject_field = self.driver.find_element_by_xpath(subject)
        subject_field.send_keys('Generated by Selenium Webdriver!')
        sleep(2)

        body_field = self.driver.find_element_by_id(main_text)
        body_field.send_keys('FINALLY! This text has been composed and created automatically. \n'
                             ' Powered by Selenium Webdriver + Python v 3.8. '
                             '\nGovnocode belongs to Artem Avsitidiisky(c)')
        sleep(2)
        self.driver.find_element_by_xpath(send).click()

        if 'Ваше повідомлення надiслано' in self.driver.page_source:
            print(GREEN +'PASS')
        else:
            print(RED+'FAIL')

    def tearDown(self):
        self.driver.quit()


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





