Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
- import unittest
- class TestWork(unittest.TestCase):
- @classmethod
- def setUpClass(cls):
- cls.url = "https://www.youtube.com/"
- cls.driver = webdriver.Chrome()
- cls.driver.implicitly_wait(10)
- cls.username = "222icecream222@gmail.com"
- cls.login_button_xpath = "//*[@id='button']/*[text()='Войти']"
- cls.password = "222111222"
- cls.upload_button = "//*[@id='buttons']//*[@id='button']"
- cls.upload_button_2 = "//input[@type='file']"
- cls.path_to_file = "F:\\hey\\mouse.3gp"
- cls.successful_upload = "//div[@id='upload-page']"
- cls.manager_video = "//input[@type='file']"
- cls.edit_video = "//a[@href='/edit?o=U&video_id=0jHAbyZ-DE8']"
- cls.title_xpath = "//input[@name='title']"
- cls.title = "mouse"
- cls.description = "little mouse"
- cls.description_xpath = "//textarea[@name='description']"
- cls.publish_xpath = "//button[@title='Опубликовать видео сразу после обработки']"
- @classmethod
- def tearDownClass(cls):
- cls.driver.quit()
- def login(self, username, password):
- sign_button = WebDriverWait(self.driver, 20).until(
- EC.element_to_be_clickable((By.XPATH, self.login_button_xpath))
- )
- sign_button.click()
- self.driver.find_element_by_xpath("//input[@type='email']").send_keys(username)
- self.driver.find_element_by_id("identifierNext").click()
- self.driver.find_element_by_xpath("//input[@name='password']").send_keys(password)
- self.driver.find_element_by_id("passwordNext").click()
- def upload_video(self, title, description, path_to_file):
- self.driver.find_element_by_xpath(self.upload_button).click()
- self.driver.implicitly_wait(10)
- self.driver.find_element_by_xpath(self.upload_button_2).send_keys(self.path_to_file)
- upload_message = WebDriverWait(self.driver, 10).until(
- EC.element_to_be_clickable((By.XPATH, self.successful_upload ))
- )
- self.driver.find_element_by_xpath(self.manager_video).click()
- self.driver.find_element_by_xpath(self.edit_video).click()
- self.driver.find_element_by_xpath(self.edit_video).clear()
- self.driver.find_element_by_xpath(self.title_xpath).send_keys(self.title)
- self.driver.find_element_by_xpath(self.description_xpath).send_keys(self.description)
- self.driver.find_element_by_xpath(self.publish_xpath).click()
- def test_work_youtube(self):
- self.driver.get(self.url)
- self.login(self.username, self.password)
- self.driver.implicitly_wait(10)
- self.upload_video(self.title, self.description, self.path_to_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement