From d5ab2a5f1e3b5aa737ea927a4d1cd6742abacb48 Mon Sep 17 00:00:00 2001 From: AlexandrTimo Date: Sat, 2 Nov 2024 10:12:14 -0700 Subject: [PATCH 1/3] added autotests for app lesson1: endpoint, selectorts --- lesson1/api_tests/tests/test_auto_tests.py | 92 ++++++++++++++++++++++ lesson1/pytest.ini | 2 +- 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 lesson1/api_tests/tests/test_auto_tests.py diff --git a/lesson1/api_tests/tests/test_auto_tests.py b/lesson1/api_tests/tests/test_auto_tests.py new file mode 100644 index 0000000..c928295 --- /dev/null +++ b/lesson1/api_tests/tests/test_auto_tests.py @@ -0,0 +1,92 @@ +import pytest +import requests +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys + +import time + +url = "http://localhost:5173/" + +def test_get_by_endpoint(): + response = requests.get(url) + assert response.status_code == 200 +def test_get_by_selector(): + browser = webdriver.Chrome() + browser.get(url) + # time.sleep(5) + assert url == "http://localhost:5173/", "URLs do not match" + + +@pytest.fixture +def setup(): + browser = webdriver.Chrome() + browser.get(url) + yield browser + browser.quit() + +def test_add_test_case(setup): + driver = setup + + # Fill in the "Name" field + name_field = driver.find_element(By.ID, "name") + name_field.clear() + name_field.send_keys("Test Case 1") + + # Fill in the "Description" field + description_field = driver.find_element(By.ID, 'description') + description_field.clear() + description_field.send_keys("Test Case 99 Description") + + # Fill in the steps + steps_field = driver.find_element(By.ID, 'steps') + steps_field.clear() + steps_field.send_keys("Open home page, check navigation bar, check header, check content body, check footer") + + # Fill in the "Expected Result" field + expected_result_field = driver.find_element(By.ID, "expected_result") + expected_result_field.clear() + expected_result_field.send_keys("UI should be visible and clickable") + + # Select priority + priority_dropdown = driver.find_element(By.ID, "priority") + priority_dropdown.click() + priority_options = driver.find_element(By.XPATH, "//option[text()='высокий']") + priority_options.click() + + # Click the "Add Test Case" button + add_button = driver.find_element(By.XPATH, "//button[@class='btn btn-primary']") + add_button.click() + + # Validation Table Data + # TODO : example 1 >> + # table_row_name = driver.find_element(By.XPATH, "//td[text()='Test Case 1']") + # assert table_row_name is not None, "Row not found" and table_row_name.text == "Test Case 1" + # TODO : example 2 >> + table = driver.find_element(By.XPATH, "//td") + assert table is not None, "Row not found" and "Test Case 1" in table.text + assert table is not None, "Row not found" and "Test Case 1 Description" in table.text + assert table is not None, "Row not found" and "UI should be visible and clickable" in table.text + assert table is not None, "Row not found" and "средний" in table.text + + time.sleep(5) + +def test_delete_test_case(setup): + driver = setup + id_str = '1' + + # rows = driver.find_elements(By.XPATH, "//table/tbody") + # for i, row in enumerate(rows): + # print(f"Row {i}: {row.text}") + # table_id = driver.find_element(By.XPATH, f"//td[text()={id_str}]") + # assert table_id is not None, "The specified ID was not found in the table." + + # TODO : Click the "Delete" button + # delete_button = driver.find_element(By.XPATH, f"//table/tbody/tr/td[text()='{id_str}']//td/button[@class='btn btn-danger']") + delete_button = driver.find_element(By.XPATH, "//button[text()='Удалить']") + # delete_button = driver.find_element(By.XPATH, "//button[@class='btn btn-primary']") + delete_button.click() + time.sleep(2) + + + assert id_str not in driver.find_element(By.XPATH, f"//td[text()='{id_str}']").text diff --git a/lesson1/pytest.ini b/lesson1/pytest.ini index a06f653..10b254f 100644 --- a/lesson1/pytest.ini +++ b/lesson1/pytest.ini @@ -1,3 +1,3 @@ [pytest] -addopts = -s -vv --alluredir=allure-results --clean-alluredir \ No newline at end of file +addopts = -s -vv --alluredir=allure-results --clean- \ No newline at end of file From 57711d538f8cbdd881f43271344771a1e6325e5e Mon Sep 17 00:00:00 2001 From: AlexandrTimo Date: Mon, 4 Nov 2024 20:03:54 -0800 Subject: [PATCH 2/3] modified autotests lesson1 --- lesson1/api_tests/tests/conftest.py | 13 +++++++++++++ lesson1/api_tests/tests/test_auto_tests.py | 15 +++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lesson1/api_tests/tests/conftest.py b/lesson1/api_tests/tests/conftest.py index e69de29..f86f96e 100644 --- a/lesson1/api_tests/tests/conftest.py +++ b/lesson1/api_tests/tests/conftest.py @@ -0,0 +1,13 @@ +import pytest +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys + +url = "http://localhost:5173/" + +@pytest.fixture +def setup(): + browser = webdriver.Chrome() + browser.get(url) + yield browser + browser.quit() \ No newline at end of file diff --git a/lesson1/api_tests/tests/test_auto_tests.py b/lesson1/api_tests/tests/test_auto_tests.py index c928295..167d734 100644 --- a/lesson1/api_tests/tests/test_auto_tests.py +++ b/lesson1/api_tests/tests/test_auto_tests.py @@ -5,8 +5,7 @@ from selenium.webdriver.common.keys import Keys import time - -url = "http://localhost:5173/" +from conftest import url def test_get_by_endpoint(): response = requests.get(url) @@ -18,12 +17,12 @@ def test_get_by_selector(): assert url == "http://localhost:5173/", "URLs do not match" -@pytest.fixture -def setup(): - browser = webdriver.Chrome() - browser.get(url) - yield browser - browser.quit() +# @pytest.fixture +# def setup(): +# browser = webdriver.Chrome() +# browser.get(url) +# yield browser +# browser.quit() def test_add_test_case(setup): driver = setup From 0fe0f9817b34707e1bc5124ea8d574faa2454fa0 Mon Sep 17 00:00:00 2001 From: AlexandrTimo Date: Sat, 9 Nov 2024 15:55:56 -0800 Subject: [PATCH 3/3] added timo_tests waits --- lesson3/waits/tests_timo/test_expl.py | 69 +++++++++++++++++++++++++++ lesson3/waits/tests_timo/test_impl.py | 59 +++++++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 lesson3/waits/tests_timo/test_expl.py create mode 100644 lesson3/waits/tests_timo/test_impl.py diff --git a/lesson3/waits/tests_timo/test_expl.py b/lesson3/waits/tests_timo/test_expl.py new file mode 100644 index 0000000..e6f1ee3 --- /dev/null +++ b/lesson3/waits/tests_timo/test_expl.py @@ -0,0 +1,69 @@ +from selenium import webdriver +from selenium.webdriver.chrome.options import Options +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +import pytest +import time + + +# ! : EXPLICIT waits + +@pytest.fixture +def chrome_options(): + options = Options() + options.add_argument('--start-maximized') + return options + +@pytest.fixture +def driver(chrome_options): + driver = webdriver.Chrome(options=chrome_options) + return driver + +@pytest.fixture +def wait(driver): + wait = WebDriverWait(driver, timeout=5) + return wait + +class TestExample: + selector_start_test = "//button[@id='startTest']" + selector_login = "//input[@id='login']" + selector_password = "//input[@id='password']" + selector_check_box_agree = "//input[@id='agree']" + selector_reg_button = "//button[@id='register']" + selector_loader = "//div[@id='loader']" + selector_success = "//p[@id='successMessage']" + +data = TestExample + + +def test_hw_expl(driver, wait): + + # Check title + driver.get('https://victoretc.github.io/selenium_waits/') + assert driver.title == "Практика Selenium" + # Check start test button + start_test_button = wait.until(EC.element_to_be_clickable((By.XPATH, data.selector_start_test))) + assert start_test_button.text == "Начать тестирование" + start_test_button.click() + # Fill form + driver.find_element(By.XPATH, data.selector_login).send_keys("login") + driver.find_element(By.XPATH, data.selector_password).send_keys("password") + # Check agree checkbox + check_box = driver.find_element(By.XPATH, data.selector_check_box_agree) + if not check_box.is_selected(): + check_box.click() + driver.find_element(By.XPATH, data.selector_reg_button).click() + # Check loader + load_check = driver.find_element(By.XPATH, data.selector_loader) + assert load_check.is_displayed() + # Check success message + success_check = wait.until(EC.element_to_be_clickable((By.XPATH, data.selector_success))) + assert success_check.text == "Вы успешно зарегистрированы!" + + time.sleep(5) + + + + + diff --git a/lesson3/waits/tests_timo/test_impl.py b/lesson3/waits/tests_timo/test_impl.py new file mode 100644 index 0000000..f7b77ed --- /dev/null +++ b/lesson3/waits/tests_timo/test_impl.py @@ -0,0 +1,59 @@ +from selenium import webdriver +from selenium.webdriver.chrome.options import Options +from selenium.webdriver.common.by import By +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +import pytest +import time + + +# ! : IMPLICIT waits + +@pytest.fixture +def chrome_options(): + options = Options() + options.add_argument('--start-maximized') + return options + +@pytest.fixture +def driver(chrome_options): + driver = webdriver.Chrome(options=chrome_options) + driver.implicitly_wait(10) + yield driver + driver.quit() + +class TestExample: + selector_start_test = "//button[@id='startTest']" + selector_login = "//input[@id='login']" + selector_password = "//input[@id='password']" + selector_check_box_agree = "//input[@id='agree']" + selector_reg_button = "//button[@id='register']" + selector_loader = "//div[@id='loader']" + selector_success = "//p[@id='successMessage']" + +data = TestExample + +def test_hw_impl(driver): + # Check title + driver.get('https://victoretc.github.io/selenium_waits/') + assert driver.title == "Практика Selenium" + # Check start test button + start_test_button = driver.find_element(By.XPATH, data.selector_start_test) + assert start_test_button.is_displayed + start_test_button.click() + # Fill form + driver.find_element(By.XPATH, data.selector_login).send_keys("login") + driver.find_element(By.XPATH, data.selector_password).send_keys("password") + # Check agree checkbox + check_box = driver.find_element(By.XPATH, data.selector_check_box_agree) + if not check_box.is_selected(): + check_box.click() + driver.find_element(By.XPATH, data.selector_reg_button).click() + # Check loader + check_loader = driver.find_element(By.XPATH, data.selector_loader) + assert check_loader.is_displayed + # Check success message + check_sucess_msg = driver.find_element(By.XPATH, data.selector_success) + assert check_sucess_msg.is_displayed + time.sleep(5) +