Advertisement
Guest User

Untitled

a guest
Nov 26th, 2017
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.92 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. class TestWork(unittest.TestCase):
  8.     @classmethod
  9.     def setUpClass(cls):
  10.         cls.url = "https://www.youtube.com/"
  11.         cls.driver = webdriver.Chrome()
  12.         cls.driver.implicitly_wait(10)
  13.         cls.username = "222icecream222@gmail.com"
  14.         cls.login_button_xpath = "//*[@id='button']/*[text()='Войти']"
  15.         cls.password = "222111222"
  16.         cls.upload_button = "//*[@id='buttons']//*[@id='button']"
  17.         cls.upload_button_2 = "//input[@type='file']"
  18.         cls.path_to_file = "F:\\hey\\mouse.3gp"
  19.         cls.successful_upload = "//div[@id='upload-page']"
  20.         cls.manager_video = "//input[@type='file']"
  21.         cls.edit_video = "//a[@href='/edit?o=U&video_id=0jHAbyZ-DE8']"
  22.         cls.title_xpath = "//input[@name='title']"
  23.         cls.title = "mouse"
  24.         cls.description = "little mouse"
  25.         cls.description_xpath = "//textarea[@name='description']"
  26.         cls.publish_xpath = "//button[@title='Опубликовать видео сразу после обработки']"
  27.  
  28.     @classmethod
  29.     def tearDownClass(cls):
  30.         cls.driver.quit()
  31.  
  32.     def login(self, username, password):
  33.         sign_button = WebDriverWait(self.driver, 20).until(
  34.             EC.element_to_be_clickable((By.XPATH, self.login_button_xpath))
  35.         )
  36.         sign_button.click()
  37.         self.driver.find_element_by_xpath("//input[@type='email']").send_keys(username)
  38.         self.driver.find_element_by_id("identifierNext").click()
  39.         self.driver.find_element_by_xpath("//input[@name='password']").send_keys(password)
  40.         self.driver.find_element_by_id("passwordNext").click()
  41.  
  42.     def upload_video(self, title, description, path_to_file):
  43.         self.driver.find_element_by_xpath(self.upload_button).click()
  44.         self.driver.implicitly_wait(10)
  45.         self.driver.find_element_by_xpath(self.upload_button_2).send_keys(self.path_to_file)
  46.         upload_message = WebDriverWait(self.driver, 10).until(
  47.             EC.element_to_be_clickable((By.XPATH, self.successful_upload ))
  48.         )
  49.         self.driver.find_element_by_xpath(self.manager_video).click()
  50.         self.driver.find_element_by_xpath(self.edit_video).click()
  51.         self.driver.find_element_by_xpath(self.edit_video).clear()
  52.         self.driver.find_element_by_xpath(self.title_xpath).send_keys(self.title)
  53.         self.driver.find_element_by_xpath(self.description_xpath).send_keys(self.description)
  54.         self.driver.find_element_by_xpath(self.publish_xpath).click()
  55.  
  56.     def test_work_youtube(self):
  57.         self.driver.get(self.url)
  58.         self.login(self.username, self.password)
  59.         self.driver.implicitly_wait(10)
  60.         self.upload_video(self.title, self.description, self.path_to_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement