20 тестов проходят за 120 секунд, что очень долго, как можно запустить в несколько потоков, допустим, 10. Ну или же сделать одну функцию, с заменой параметра в send_key?
import unittest
#import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
URL = 'https://psy.edu.ru/'
class check_psyedu(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome(r'C:\Users\Алексей\YandexDisk\Job\Python\Test\chromedriver\chromedriver.exe')
#def read_excel():
#list_name = pd.read_excel('./list_name.xlsx')
#list_name.head()
def test_1(self):
self.driver.get(URL)
self.driver.set_window_size(1920, 1080)
self.driver.find_element(By.NAME, "name").send_keys("aleksei")
self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(1) > .err_message").text == "Напишите русскими буквами!"
assert self.driver.find_element(By.CSS_SELECTOR, ".err_message:nth-child(3)").text == "Обязательное поле!"
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(3)").text == "Обязательное поле!"
self.driver.close()
def test_2(self):
self.driver.get(URL)
self.driver.set_window_size(1920, 1080)
self.driver.find_element(By.NAME, "name").send_keys("Алексей")
self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(1) > .err_message").text == "Напишите русскими буквами!"
assert self.driver.find_element(By.CSS_SELECTOR, ".err_message:nth-child(3)").text == "Обязательное поле!"
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(3)").text == "Обязательное поле!"
self.driver.close()
def test_3(self):
self.driver.get(URL)
self.driver.set_window_size(1920, 1080)
self.driver.find_element(By.NAME, "name").send_keys(" Рынденков Алексей")
self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(1) > .err_message").text == "Напишите русскими буквами!"
assert self.driver.find_element(By.CSS_SELECTOR, ".err_message:nth-child(3)").text == "Обязательное поле!"
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(3)").text == "Обязательное поле!"
self.driver.close()
def test_4(self):
self.driver.get(URL)
self.driver.set_window_size(1920, 1080)
self.driver.find_element(By.NAME, "name").send_keys("123123")
self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(1) > .err_message").text == "Напишите русскими буквами!"
assert self.driver.find_element(By.CSS_SELECTOR, ".err_message:nth-child(3)").text == "Обязательное поле!"
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(3)").text == "Обязательное поле!"
self.driver.close()
def test_5(self):
self.driver.get(URL)
self.driver.set_window_size(1920, 1080)
self.driver.find_element(By.NAME, "name").send_keys("@алексей")
self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(1) > .err_message").text == "Напишите русскими буквами!"
assert self.driver.find_element(By.CSS_SELECTOR, ".err_message:nth-child(3)").text == "Обязательное поле!"
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(3)").text == "Обязательное поле!"
self.driver.close()
def test_6(self):
self.driver.get(URL)
self.driver.set_window_size(1920, 1080)
self.driver.find_element(By.NAME, "name").send_keys("sofa")
self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(1) > .err_message").text == "Напишите русскими буквами!"
assert self.driver.find_element(By.CSS_SELECTOR, ".err_message:nth-child(3)").text == "Обязательное поле!"
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(3)").text == "Обязательное поле!"
self.driver.close()
def test_7(self):
self.driver.get(URL)
self.driver.set_window_size(1920, 1080)
self.driver.find_element(By.NAME, "name").send_keys("admin")
self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(1) > .err_message").text == "Напишите русскими буквами!"
assert self.driver.find_element(By.CSS_SELECTOR, ".err_message:nth-child(3)").text == "Обязательное поле!"
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(3)").text == "Обязательное поле!"
self.driver.close()
def test_8(self):
self.driver.get(URL)
self.driver.set_window_size(1920, 1080)
self.driver.find_element(By.NAME, "name").send_keys(" ")
self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(1) > .err_message").text == "Напишите русскими буквами!"
assert self.driver.find_element(By.CSS_SELECTOR, ".err_message:nth-child(3)").text == "Обязательное поле!"
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(3)").text == "Обязательное поле!"
self.driver.close()
def test_9(self):
self.driver.get(URL)
self.driver.set_window_size(1920, 1080)
self.driver.find_element(By.NAME, "name").send_keys("")
self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(1) > .err_message").text == "Напишите русскими буквами!"
assert self.driver.find_element(By.CSS_SELECTOR, ".err_message:nth-child(3)").text == "Обязательное поле!"
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(3)").text == "Обязательное поле!"
self.driver.close()
def test_10(self):
self.driver.get(URL)
self.driver.set_window_size(1920, 1080)
self.driver.find_element(By.NAME, "name").send_keys("Софья")
self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(1) > .err_message").text == "Напишите русскими буквами!"
assert self.driver.find_element(By.CSS_SELECTOR, ".err_message:nth-child(3)").text == "Обязательное поле!"
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(3)").text == "Обязательное поле!"
self.driver.close()
def test_11(self):
self.driver.get(URL)
self.driver.set_window_size(1920, 1080)
self.driver.find_element(By.NAME, "name").send_keys("Иван")
self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(1) > .err_message").text == "Напишите русскими буквами!"
assert self.driver.find_element(By.CSS_SELECTOR, ".err_message:nth-child(3)").text == "Обязательное поле!"
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(3)").text == "Обязательное поле!"
self.driver.close()
def test_12(self):
self.driver.get(URL)
self.driver.set_window_size(1920, 1080)
self.driver.find_element(By.NAME, "name").send_keys(".Алексей")
self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(1) > .err_message").text == "Напишите русскими буквами!"
assert self.driver.find_element(By.CSS_SELECTOR, ".err_message:nth-child(3)").text == "Обязательное поле!"
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(3)").text == "Обязательное поле!"
self.driver.close()
def test_13(self):
self.driver.get(URL)
self.driver.set_window_size(1920, 1080)
self.driver.find_element(By.NAME, "name").send_keys("-Кирилл")
self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(1) > .err_message").text == "Напишите русскими буквами!"
assert self.driver.find_element(By.CSS_SELECTOR, ".err_message:nth-child(3)").text == "Обязательное поле!"
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(3)").text == "Обязательное поле!"
self.driver.close()
def test_14(self):
self.driver.get(URL)
self.driver.set_window_size(1920, 1080)
self.driver.find_element(By.NAME, "name").send_keys("уцкаушатуоатурашгукратиукалукшгарукта")
self.driver.find_element(By.CSS_SELECTOR, ".btn").click()
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(1) > .err_message").text == "Напишите русскими буквами!"
assert self.driver.find_element(By.CSS_SELECTOR, ".err_message:nth-child(3)").text == "Обязательное поле!"
assert self.driver.find_element(By.CSS_SELECTOR, ".still-quest_item:nth-child(3)").text == "Обязательное поле!"
self.driver.close()
def tearDown(self):
self.driver.quit()
if __name__ == "__main__":
unittest.main()