Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aleksander Voschilo UI test bd allure #10

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
venv
venv
/bd_creds.py
/bd_data.py
/reports/
13 changes: 13 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -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()
63 changes: 63 additions & 0 deletions database.py
Original file line number Diff line number Diff line change
@@ -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")
20 changes: 20 additions & 0 deletions pages/base_page.py
Original file line number Diff line number Diff line change
@@ -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))
55 changes: 55 additions & 0 deletions pages/home_page.py
Original file line number Diff line number Diff line change
@@ -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()
13 changes: 13 additions & 0 deletions pages/locators/home_page_locators.py
Original file line number Diff line number Diff line change
@@ -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')
Binary file modified requirements.txt
Binary file not shown.
197 changes: 197 additions & 0 deletions tests/test_home_page.py
Original file line number Diff line number Diff line change
@@ -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()
Loading