Advertisement
Guest User

Untitled

a guest
Nov 28th, 2017
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.87 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.common.by import By
  3. from selenium.webdriver.support.ui import WebDriverWait
  4. from selenium.webdriver.support import expected_conditions as EC
  5. import unittest
  6.  
  7.  
  8. class TestMail(unittest.TestCase):
  9.     @classmethod
  10.     def setUpClass(cls):
  11.         cls.url = "https://mail.google.com/mail/u/1/#inbox/"
  12.         cls.driver = webdriver.Chrome()
  13.         cls.driver.implicitly_wait(10)
  14.         cls.username = "test8814test@gmail.com"
  15.         cls.password = "02031990x"
  16.         cls.username_xpath = "//input[@type='email']"
  17.         cls.password_xpath = "//input[@name='password']"
  18.         cls.next_button = "identifierNext"
  19.         cls.next_button2 = "passwordNext"
  20.         cls.start_message = "//div[@class='T-I J-J5-Ji T-I-KE L3']"
  21.         cls.to_whom_field = "//textarea[@name='to']"
  22.         cls.to_email_name = "test8814test@gmail.com"
  23.         cls.theme_field = "//input[@name='subjectbox']"
  24.         cls.theme_name = "hello world"
  25.         cls.message_field = "//div[@aria-label='Тело письма']"
  26.         cls.message_text = "Привет! это тестовое сообщение."
  27.         cls.send_email_button = "//div[@class='J-J5-Ji btA']"
  28.         cls.message_sended = "link_vsm"
  29.         cls.message_delete = "//div[@aria-label='Ещё']"
  30.         cls.msd = "tm"
  31.         cls.successful_deleted = "//span[@class='bofITb']"
  32.         #link_vsm
  33.  
  34.     @classmethod
  35.     def tearDownClass(cls):
  36.         cls.driver.quit()
  37.  
  38.     def login(self, username, password):
  39.         self.driver.find_element_by_xpath(self.username_xpath).send_keys(username)
  40.         self.driver.find_element_by_id(self.next_button).click()
  41.         self.driver.find_element_by_xpath(self.password_xpath).send_keys(password)
  42.         self.driver.find_element_by_id(self.next_button2).click()
  43.  
  44.     def message(self, to_email_name, theme_name, message_text):
  45.         self.driver.find_element_by_xpath(self.start_message).click()
  46.         self.driver.find_element_by_xpath(self.to_whom_field).send_keys(to_email_name)
  47.         self.driver.find_element_by_xpath(self.theme_field).send_keys(theme_name)
  48.         self.driver.find_element_by_xpath(self.message_field).send_keys(message_text)
  49.         self.driver.find_element_by_xpath(self.send_email_button).click()
  50.         self.driver.find_element_by_id(self.message_sended).click()
  51.         self.driver.find_element_by_xpath(self.message_delete).click()
  52.         self.driver.find_element_by_id(self.msd).click()
  53.  
  54.         deleted_message = WebDriverWait(self.driver, 20).until(
  55.             EC.element_to_be_clickable((By.XPATH, self.successful_deleted))
  56.         )
  57.         deleted_message.click()
  58.         self.driver.refresh()
  59.  
  60.     def test_work_mail(self):
  61.         self.driver.get(self.url)
  62.         self.login(self.username, self.password)
  63.         self.message(self.to_email_name, self.theme_name, self.message_text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement