diff --git a/.gitignore b/.gitignore index f5e96db..230290e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -venv \ No newline at end of file +venv +/bd_creds.py +/bd_data.py +/reports/ diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..a922a42 --- /dev/null +++ b/conftest.py @@ -0,0 +1,13 @@ +from selenium import webdriver +import chromedriver_autoinstaller +import pytest + + +@pytest.fixture(scope='function') +def browser(): + chromedriver_autoinstaller.install() + chrome_browser = webdriver.Chrome() + chrome_browser.maximize_window() + chrome_browser.implicitly_wait(10) + yield chrome_browser + chrome_browser.quit() diff --git a/database.py b/database.py new file mode 100644 index 0000000..a5c510f --- /dev/null +++ b/database.py @@ -0,0 +1,63 @@ +import psycopg2 +from sshtunnel import SSHTunnelForwarder +import bd_data as bd + + +def change_text_in_database_by_front_id(front_id_bd, text_to_change): + try: + with SSHTunnelForwarder( + (f"{bd.bd_ip}", 22), + ssh_username=f"{bd.ssh_username}", + ssh_private_key=f"{bd.ssh_private_key}", + remote_bind_address=(f"{bd.remote_bind_address}", 25060)) as server: + + server.start() + + params = { + 'database': f"{bd.database}", + 'user': f"{bd.user}", + 'password': f"{bd.password}", + 'host': f"{bd.host}", + 'port': server.local_bind_port + } + + conn = psycopg2.connect(**params) + curs = conn.cursor() + curs.execute(f"update frontend_data SET text='{text_to_change}'" + f" WHERE front_id='{front_id_bd}';") + conn.commit() + conn.close() + return True + + except: + print("Connection Failed") + + +def take_text_from_database_by_front_id(front_id_bd): + try: + with SSHTunnelForwarder( + (f"{bd.bd_ip}", 22), + ssh_username=f"{bd.ssh_username}", + ssh_private_key=f"{bd.ssh_private_key}", + remote_bind_address=(f"{bd.remote_bind_address}", 25060)) as server: + + server.start() + + params = { + 'database': f"{bd.database}", + 'user': f"{bd.user}", + 'password': f"{bd.password}", + 'host': f"{bd.host}", + 'port': server.local_bind_port + } + + conn = psycopg2.connect(**params) + curs = conn.cursor() + curs.execute(f"SELECT text FROM frontend_data WHERE front_id='{front_id_bd}';") + text = curs.fetchall() + text_by_id = text[0][0] + conn.close() + return text_by_id + + except: + print("Connection Failed") diff --git a/pages/base_page.py b/pages/base_page.py new file mode 100644 index 0000000..6945120 --- /dev/null +++ b/pages/base_page.py @@ -0,0 +1,20 @@ +from selenium.webdriver.chrome.webdriver import WebDriver +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC + + +class BasePage: + def __init__(self, browser: WebDriver): + self.browser = browser + self.base_url = 'https://front-test-a2ykv.ondigitalocean.app/' + + def find_element(self, args: tuple): + by_name, by_val = args + return self.browser.find_element(by_name, by_val) + + def find_elements(self, args: tuple): + by_name, by_val = args + return self.browser.find_elements(by_name, by_val) + + def wait_element(self, locator): + return WebDriverWait(self.browser, 10).until(EC.visibility_of_element_located(locator)) diff --git a/pages/home_page.py b/pages/home_page.py new file mode 100644 index 0000000..9661bc0 --- /dev/null +++ b/pages/home_page.py @@ -0,0 +1,55 @@ +from pages.locators import home_page_locators as hpl +from pages.base_page import BasePage + + +class HomePage(BasePage): + def __init__(self, browser): + super().__init__(browser) + self.browser = browser + + def open_page(self): + self.browser.get(self.base_url) + + def logo_is_displayed(self): + return self.find_element(hpl.train_lab_logo).is_displayed() + + def about_us_button_is_displayed(self): + return self.find_element(hpl.about_us_btn).is_displayed() + + def o_nas_button_text(self): + return self.find_element(hpl.about_us_btn).text + + def tasks_button_is_displayed(self): + return self.find_element(hpl.tasks_btn).is_displayed() + + def tasks_button_text(self): + return self.find_element(hpl.tasks_btn).text + + def sign_in_button_is_displayed(self): + return self.find_element(hpl.sign_in_btn).is_displayed() + + def sign_in_button_text(self): + return self.find_element(hpl.sign_in_btn).text + + def success_banner_text(self): + self.wait_element(hpl.success_banner_bar) + return self.find_element(hpl.success_banner_bar).text + + def our_simulators_banner_text(self): + self.wait_element(hpl.our_simulators_banner) + return self.find_element(hpl.our_simulators_banner).text + + def start_the_journey_button_is_displayed(self): + return self.find_element(hpl.start_the_journey_btn).is_displayed() + + def start_the_journey_button_text(self): + return self.find_element(hpl.start_the_journey_btn).text + + def sql_banner_is_displayed(self): + return self.find_element(hpl.sql_banner).is_displayed() + + def python_banner_is_displayed(self): + return self.find_element(hpl.python_banner).is_displayed() + + def java_script_banner_is_displayed(self): + return self.find_element(hpl.java_script_banner).is_displayed() diff --git a/pages/locators/home_page_locators.py b/pages/locators/home_page_locators.py new file mode 100644 index 0000000..ab77e65 --- /dev/null +++ b/pages/locators/home_page_locators.py @@ -0,0 +1,13 @@ +from selenium.webdriver.common.by import By + + +train_lab_logo = (By.CSS_SELECTOR, 'img[alt="Logo"]') +about_us_btn = (By.CSS_SELECTOR, 'a[href="#about"] .btn.btn-secondary') +tasks_btn = (By.CSS_SELECTOR, 'a[href="#tasks"] .btn.btn-secondary') +sign_in_btn = (By.XPATH, '//a[@href="/auth"]/button') #CSS нужно использовать +success_banner_bar = (By.CLASS_NAME, 'Banner_h3_banner__BaCln') +our_simulators_banner = (By.CLASS_NAME, 'Banner_text_banner__EfApu') +start_the_journey_btn = (By.CLASS_NAME, 'Banner_btn_banner__ZteJM') +sql_banner = (By.CSS_SELECTOR, 'li[data-index="0"] h3') +python_banner = (By.CSS_SELECTOR, 'li[data-index="1"] h3') +java_script_banner = (By.CSS_SELECTOR, 'li[data-index="2"] h3') diff --git a/requirements.txt b/requirements.txt index 8f4d514..8e9aba3 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/tests/test_home_page.py b/tests/test_home_page.py new file mode 100644 index 0000000..f7898f1 --- /dev/null +++ b/tests/test_home_page.py @@ -0,0 +1,197 @@ +import allure +import database as Database +from pages.home_page import HomePage + + +@allure.feature('Home page') +@allure.story('Trainlab logo') +@allure.title('Testing Trainlab logo') +def test_trainlab_logo_is_displayed(browser): + home_page = HomePage(browser) + with allure.step('Open Home page'): + home_page.open_page() + with allure.step('Check that Trainlab logo is displayed'): + assert home_page.logo_is_displayed() + + +@allure.feature('Home page') +@allure.story('About us button') +@allure.title('Testing about us button') +def test_about_us_button_is_displayed(browser): + home_page = HomePage(browser) + with allure.step('Open Home page'): + home_page.open_page() + with allure.step('Check that about us button is displayed'): + assert home_page.about_us_button_is_displayed() + + +@allure.feature('Home page') +@allure.story('About us button') +@allure.title('Testing about us button') +def test_about_us_button_text_is_ok(browser): + home_page = HomePage(browser) + with allure.step('Open Home page'): + home_page.open_page() + with allure.step('Check that about us button text is displayed'): + assert home_page.o_nas_button_text() == 'О нас' + + +@allure.feature('Home page') +@allure.story('Tasks button') +@allure.title('Testing tasks button') +def test_tasks_button_is_displayed(browser): + home_page = HomePage(browser) + with allure.step('Open Home page'): + home_page.open_page() + with allure.step('Check that tasks button is displayed'): + assert home_page.tasks_button_is_displayed() + + +@allure.feature('Home page') +@allure.story('Tasks button') +@allure.title('Testing tasks button') +def test_tasks_button_text_is_ok(browser): + home_page = HomePage(browser) + with allure.step('Open Home page'): + home_page.open_page() + with allure.step('Check that tasks button text is displayed'): + assert home_page.tasks_button_text() == 'Задания' + + +@allure.feature('Home page') +@allure.story('Sign in button') +@allure.title('Testing sign in button') +def test_sign_in_button_is_displayed(browser): + home_page = HomePage(browser) + with allure.step('Open Home page'): + home_page.open_page() + with allure.step('Check that sign in button is displayed'): + assert home_page.sign_in_button_is_displayed() + + +@allure.feature('Home page') +@allure.story('Sign in button') +@allure.title('Testing sign in button') +def test_sign_in_button_text_is_ok(browser): + home_page = HomePage(browser) + with allure.step('Open Home page'): + home_page.open_page() + with allure.step('Check that sign in button text is displayed'): + assert home_page.sign_in_button_text() == 'Войти' + + +@allure.feature('Home page') +@allure.story('Success banner') +@allure.title('Testing success banner') +def test_success_banner_text_is_ok(browser): + home_page = HomePage(browser) + with allure.step('Open Home page'): + home_page.open_page() + with allure.step('Check that success banner text is displayed'): + assert home_page.success_banner_text() == 'Создай свой успех' + + +@allure.feature('Home page') +@allure.story('Success banner') +@allure.title('Testing success banner') +def test_success_banner_text_takes_from_bd(browser): #надо менять структуру + with allure.step('Take text from database by front id'): + text_from_database = Database.take_text_from_database_by_front_id(1.1) + with allure.step('Change text in database by front id'): + Database.change_text_in_database_by_front_id(1.1, 'Текст изменен') + home_page = HomePage(browser) + with allure.step('Open Home page'): + home_page.open_page() + with allure.step('Take text from element on website'): + new_text_from_website = home_page.success_banner_text() + with allure.step('Return text to database by front id'): + Database.change_text_in_database_by_front_id(1.1, f"{text_from_database}") + with allure.step('Check that text for website element takes from database'): + assert new_text_from_website == 'Текст изменен' + + +@allure.feature('Home page') +@allure.story('Simulators banner') +@allure.title('Testing simulators banner') +def test_our_simulators_banner_text_is_ok(browser): + home_page = HomePage(browser) + with allure.step('Open Home page'): + home_page.open_page() + with allure.step('Check that simulators banner text is displayed'): + assert home_page.our_simulators_banner_text() == 'Наши тренажеры' \ + ' разработаны на основе тестовых заданий работодателей. ' \ + 'выполняя задания и зарабатывая баллы, ты найдешь работу мечты' + + +@allure.feature('Home page') +@allure.story('Simulators banner') +@allure.title('Testing simulators banner') +def test_our_simulators_banner_text_takes_from_bd(browser): #надо менять структуру + with allure.step('Take text from database by front id'): + text_from_database = Database.take_text_from_database_by_front_id(1.2) + with allure.step('Change text in database by front id'): + Database.change_text_in_database_by_front_id(1.2, 'Текст изменен') + home_page = HomePage(browser) + with allure.step('Open Home page'): + home_page.open_page() + with allure.step('Take text from element on website'): + new_text_from_website = home_page.our_simulators_banner_text() + with allure.step('Return text to database by front id'): + Database.change_text_in_database_by_front_id(1.2, f"{text_from_database}") + with allure.step('Check that text for website element takes from database'): + assert new_text_from_website == 'Текст изменен' + + +@allure.feature('Home page') +@allure.story('Start the journey button') +@allure.title('Testing start the journey button') +def test_start_the_journey_button_is_displayed(browser): + home_page = HomePage(browser) + with allure.step('Open Home page'): + home_page.open_page() + with allure.step('Check that start the journey button is displayed'): + assert home_page.start_the_journey_button_is_displayed() + + +@allure.feature('Home page') +@allure.story('Start the journey button') +@allure.title('Testing start the journey button') +def test_start_the_journey_button_text_is_ok(browser): + home_page = HomePage(browser) + with allure.step('Open Home page'): + home_page.open_page() + with allure.step('Check that start the journey button text is displayed'): + assert home_page.start_the_journey_button_text() == 'Начать путь' + + +@allure.feature('Home page') +@allure.story('SQL banner') +@allure.title('Testing SQL banner') +def test_sql_banner_is_displayed(browser): + home_page = HomePage(browser) + with allure.step('Open Home page'): + home_page.open_page() + with allure.step('Check that SQL banner is displayed'): + assert home_page.sql_banner_is_displayed() + + +@allure.feature('Home page') +@allure.story('Python banner') +@allure.title('Testing Python banner') +def test_python_banner_is_displayed(browser): + home_page = HomePage(browser) + with allure.step('Open Home page'): + home_page.open_page() + with allure.step('Check that Python banner is displayed'): + assert home_page.python_banner_is_displayed() + + +@allure.feature('Home page') +@allure.story('JavaScript banner') +@allure.title('Testing JavaScript banner') +def test_java_script_banner_is_displayed(browser): + home_page = HomePage(browser) + with allure.step('Open Home page'): + home_page.open_page() + with allure.step('Check that JavaScript banner is displayed'): + assert home_page.java_script_banner_is_displayed()