Advertisement
Guest User

Untitled

a guest
Nov 26th, 2017
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.73 KB | None | 0 0
  1.  
  2. from selenium import webdriver
  3. from selenium.webdriver.common.by import By
  4. from selenium.webdriver.support.ui import WebDriverWait
  5. from selenium.webdriver.support import expected_conditions as EC
  6. import unittest
  7.  
  8. class TestWork(unittest.TestCase):
  9.     @classmethod
  10.     def setUpClass(cls):
  11.         cls.url = "https://www.youtube.com/"
  12.         cls.driver = webdriver.Chrome()
  13.         cls.driver.implicitly_wait(10)
  14.         cls.username = "222icecream222@gmail.com"
  15.         cls.login_button_xpath = "//*[@id='button']/*[text()='Войти']"
  16.         cls.password = "222111222"
  17.         cls.upload_button = "//*[@id='buttons']//*[@id='button']"
  18.         cls.upload_button_2 = "//input[@type='file']"
  19.         cls.path_to_file = "F:\\hey\\mouse.3gp"
  20.         cls.successful_upload = "//button[@class='yt-uix-close yt-close item-close']"
  21.         cls.manager_video = "//a[@href='/my_videos']"
  22.         cls.edit_video = "//a[@href='/edit?o=U&video_id=0jHAbyZ-DE8']"
  23.         cls.title_xpath = "//input[@name='title']"
  24.         cls.title = "mouse"
  25.         cls.description = "little mouse"
  26.         cls.description_xpath = "//textarea[@name='description']"
  27.         cls.publish_xpath = "//ul[@class='vm-video-long-videos-buttons']//button"
  28.  
  29.     @classmethod
  30.     def tearDownClass(cls):
  31.         #cls.driver.quit()
  32.        pass
  33.  
  34.  
  35.     def login(self, username, password):
  36.         sign_button = WebDriverWait(self.driver, 20).until(
  37.             EC.element_to_be_clickable((By.XPATH, self.login_button_xpath))
  38.         )
  39.         sign_button.click()
  40.         self.driver.find_element_by_xpath("//input[@type='email']").send_keys(username)
  41.         self.driver.find_element_by_id("identifierNext").click()
  42.         self.driver.find_element_by_xpath("//input[@name='password']").send_keys(password)
  43.         self.driver.find_element_by_id("passwordNext").click()
  44.  
  45.     def upload_video(self, title, description, path_to_file):
  46.         self.driver.find_element_by_xpath(self.upload_button).click()
  47.         self.driver.find_element_by_xpath(self.upload_button_2).send_keys(path_to_file)
  48.         self.driver.find_element_by_xpath(self.title_xpath).clear()
  49.         self.driver.find_element_by_xpath(self.title_xpath).send_keys(title)
  50.         self.driver.find_element_by_xpath(self.description_xpath).send_keys(description)
  51.  
  52.         upload_message = WebDriverWait(self.driver, 20).until(
  53.             EC.element_to_be_clickable((By.XPATH, self.successful_upload))
  54.         )
  55.         upload_message.click()
  56.         self.driver.find_element_by_xpath(self.manager_video).click()
  57.  
  58.  
  59.     def test_work_youtube(self):
  60.         self.driver.get(self.url)
  61.         self.login(self.username, self.password)
  62.         self.upload_video(self.title, self.description, self.path_to_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement