From 3898ada28c39c5773edd22f9a34cc9da3738fcd3 Mon Sep 17 00:00:00 2001 From: Lenawawer Date: Fri, 20 Oct 2023 20:41:13 +0200 Subject: [PATCH 1/4] Add test_add_to_cart --- .idea/.gitignore | 3 ++ .../inspectionProfiles/profiles_settings.xml | 6 +++ .idea/misc.xml | 4 ++ .idea/modules.xml | 8 ++++ .idea/pytest_course.git.iml | 13 +++++++ .idea/vcs.xml | 6 +++ lesson1/test_add_to_cart.py | 38 +++++++++++++++++++ 7 files changed, 78 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/pytest_course.git.iml create mode 100644 .idea/vcs.xml create mode 100644 lesson1/test_add_to_cart.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..3ca9f9f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0e2525e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/pytest_course.git.iml b/.idea/pytest_course.git.iml new file mode 100644 index 0000000..cb28baa --- /dev/null +++ b/.idea/pytest_course.git.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lesson1/test_add_to_cart.py b/lesson1/test_add_to_cart.py new file mode 100644 index 0000000..36845b8 --- /dev/null +++ b/lesson1/test_add_to_cart.py @@ -0,0 +1,38 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +import time + +driver = webdriver.Chrome() + +def test_add_item_to_cart(): + driver.get("https://www.saucedemo.com/") + + username_field = driver.find_element(By.XPATH, '//input[@data-test="username"]') + username_field.send_keys("standard_user") + + password_field = driver.find_element(By.XPATH, '//input[@data-test="password"]') + password_field.send_keys("secret_sauce") + + login_button = driver.find_element(By.XPATH, '//input[@data-test="login-button"]') + login_button.click() + + + button_add_to_card = driver.find_element(By.XPATH, '//button[@data-test="add-to-cart-sauce-labs-bolt-t-shirt"]') + button_add_to_card.click() + + + assert driver.current_url == "https://www.saucedemo.com/inventory.html" + + text_before = driver.find_element(By.CSS_SELECTOR, 'a[id="item_4_title_link"] > div[class="inventory_item_name "]').text + + text_after = driver.find_element(By.CSS_SELECTOR, 'a[id="item_4_title_link"] > div[class="inventory_item_name "]').text + + assert text_before == text_after + + + cart = driver.find_element(By.CSS_SELECTOR, 'a[class="shopping_cart_link"]') + cart.click() + + + + From 8759a44ae20c170013d3822377caa38322194c10 Mon Sep 17 00:00:00 2001 From: Lenawawer Date: Tue, 24 Oct 2023 21:00:54 +0200 Subject: [PATCH 2/4] Add test_logout --- lesson1/test_logout.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lesson1/test_logout.py diff --git a/lesson1/test_logout.py b/lesson1/test_logout.py new file mode 100644 index 0000000..a85c832 --- /dev/null +++ b/lesson1/test_logout.py @@ -0,0 +1,33 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +import time + +driver = webdriver.Chrome() + + + +def test_logout(): + driver.get("https://www.saucedemo.com/") + + url_before = driver.current_url + + username_field = driver.find_element(By.XPATH, '//input[@data-test="username"]') + username_field.send_keys("standard_user") + + password_field = driver.find_element(By.XPATH, '//input[@data-test="password"]') + password_field.send_keys("secret_sauce") + + login_button = driver.find_element(By.XPATH, '//input[@data-test="login-button"]') + login_button.click() + + burger_menu = driver.find_element(By.ID, 'react-burger-menu-btn') + burger_menu.click() + + time.sleep(2) + + logout_button = driver.find_element(By.ID, 'logout_sidebar_link') + logout_button.click() + + url_after = driver.current_url + assert url_before == url_after + From 4801fd8c22fb5c1c3db1056d739c3452807619fc Mon Sep 17 00:00:00 2001 From: Lenawawer <106933467+Lenawawer@users.noreply.github.com> Date: Tue, 24 Oct 2023 21:22:35 +0200 Subject: [PATCH 3/4] Testproject (#1) * add test_logout * Add test_logout --- lesson1/test_logout.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lesson1/test_logout.py b/lesson1/test_logout.py index a85c832..9dd8599 100644 --- a/lesson1/test_logout.py +++ b/lesson1/test_logout.py @@ -23,6 +23,10 @@ def test_logout(): burger_menu = driver.find_element(By.ID, 'react-burger-menu-btn') burger_menu.click() + + + + time.sleep(2) logout_button = driver.find_element(By.ID, 'logout_sidebar_link') From 35f280633fb6c4c46b43b480a897261b818f3362 Mon Sep 17 00:00:00 2001 From: Lenawawer <106933467+Lenawawer@users.noreply.github.com> Date: Wed, 25 Oct 2023 23:16:31 +0200 Subject: [PATCH 4/4] added lesson3 --- lesson3/readme.md | 54 ++++++++++++++++++++++++++++++++++++++++ lesson3/requirements.txt | 19 ++++++++++++++ lesson3/test_expl.py | 32 ++++++++++++++++++++++++ lesson3/test_impl.py | 27 ++++++++++++++++++++ lesson3/test_options.py | 22 ++++++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 lesson3/readme.md create mode 100644 lesson3/requirements.txt create mode 100644 lesson3/test_expl.py create mode 100644 lesson3/test_impl.py create mode 100644 lesson3/test_options.py diff --git a/lesson3/readme.md b/lesson3/readme.md new file mode 100644 index 0000000..ea2f568 --- /dev/null +++ b/lesson3/readme.md @@ -0,0 +1,54 @@ +# Ссылка на конспект урока + +https://docs.google.com/document/d/135k7XjCfjTddtmmHSL9p4q-S71FFYBodkSMqhlg2pAM/edit?usp=sharing + +# Домашнее задание +Суть данного домашнего задания - тренировка использования ожиданий в Selenium, повторение пройденных тем перед написанием полноценного тестового фреймворка. + +Для практики я попросил ChatGPT написть небольшой сайт с формой регистрации. +Ссылка на сайт: https://victoretc.github.io/selenium_waits/ + +Вам необходимо автоматизировать данный тест кейс используя ранее пройденные темы, включая ожидания. +# Название Теста: Проверка функционала регистрации на сайте +*Предусловия: Браузер открыт, интернет-соединение стабильно.* +Шаги: +* Перейти по URL: Открыть в браузере указанный URL сайта https://victoretc.github.io/selenium_waits/ +* Проверить заголовок: Убедиться, что текст в теге

на странице соответствует "Практика с ожиданиями в Selenium". +* Дождаться появления кнопки "Начать тестирование" +* Найти кнопку: Найти на странице кнопку с текстом "Начать тестирование". +* Начать тестирование: Кликнуть по кнопке "Начать тестирование". +* Ввод логина: Ввести "login" в поле для логина. +* Ввод пароля: Ввести "password" в поле для пароля. +* Согласие с правилами: Установить флажок в чекбокс "Согласен со всеми правилами". +* Подтвердить регистрацию: Нажать кнопку "Зарегистрироваться". +* Проверка загрузки: Удостовериться, что появился индикатор загрузки. +* Проверка сообщения: Убедиться, что после завершения загрузки появилось сообщение "Вы успешно зарегистрированы". + +**Ожидаемый результат:** Пользователь успешно проходит процесс регистрации, видит индикатор загрузки и получает сообщение об успешной регистрации. +**Критерии успешности:** Сообщение "Вы успешно зарегистрированы" отображается на экране. + +## Важно! +Необходимо написать 3 автотеста для данной страницы +1. С использованием Explicit waits и Expected Conditions +2. С использованием Implicit waits +3. С использованием time.sleep() + +Так же делюсь несколькими дополнительными сайтами для практики ожиданий: +1. https://www.selenium.dev/selenium/web/dynamic.html +2. https://demoqa.com/dynamic-properties +3. https://the-internet.herokuapp.com/dynamic_loading + +Все сайты достаточно примитивные, но надеюсь у всех получится уловить основную суть использования ожиданий и попрактиковаться в их написании. + +Так же необходимо написать несколько автотестов для сайта https://the-internet.herokuapp.com/ опираясь на полученные знания и поиск в интернете новой информации. + +Ссылки на упражнения: +1. https://the-internet.herokuapp.com/add_remove_elements/ (Необходимо создать и удалить элемент) +2. https://the-internet.herokuapp.com/basic_auth (Необходимо пройти базовую авторизацию) +3. https://the-internet.herokuapp.com/broken_images (Необходимо найти сломанные изображения) +4. https://the-internet.herokuapp.com/checkboxes (Практика с чек боксами) + +Так же важно помнить что мы должны получать информацию об вебэлементах и сравнивать ее с ожидаемым результатом. +Например: текст, цвет, расположение, отображение, выбор чекбокса и так далее. +Ссылка на страницу с документацией: https://www.selenium.dev/documentation/webdriver/elements/information/ + diff --git a/lesson3/requirements.txt b/lesson3/requirements.txt new file mode 100644 index 0000000..51316fe --- /dev/null +++ b/lesson3/requirements.txt @@ -0,0 +1,19 @@ +attrs==23.1.0 +certifi==2023.7.22 +exceptiongroup==1.1.3 +h11==0.14.0 +idna==3.4 +iniconfig==2.0.0 +outcome==1.3.0 +packaging==23.2 +pluggy==1.3.0 +PySocks==1.7.1 +pytest==7.4.2 +selenium==4.14.0 +sniffio==1.3.0 +sortedcontainers==2.4.0 +tomli==2.0.1 +trio==0.22.2 +trio-websocket==0.11.1 +urllib3==2.0.7 +wsproto==1.2.0 diff --git a/lesson3/test_expl.py b/lesson3/test_expl.py new file mode 100644 index 0000000..2ca066a --- /dev/null +++ b/lesson3/test_expl.py @@ -0,0 +1,32 @@ +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 + +@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=10) + return wait + +def test_visible_after_with_explicit_waits(driver, wait): + driver.get('https://demoqa.com/dynamic-properties') + visible_after_button = wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Visible After 5 Seconds']"))) + assert visible_after_button.text == 'Visible After 5 Seconds' + + + + + diff --git a/lesson3/test_impl.py b/lesson3/test_impl.py new file mode 100644 index 0000000..2db0c4a --- /dev/null +++ b/lesson3/test_impl.py @@ -0,0 +1,27 @@ +from selenium import webdriver +from selenium.webdriver.chrome.options import Options +from selenium.webdriver.common.by import By +import pytest + +@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() + +def test_visible_after_with_implicit_wait(driver): + driver.get('https://demoqa.com/dynamic-properties') + vissible_after_button = driver.find_element(By.XPATH, "//button[text()='Visible After 5 Seconds']") + assert vissible_after_button.is_displayed() + + + + + diff --git a/lesson3/test_options.py b/lesson3/test_options.py new file mode 100644 index 0000000..5ee9cf3 --- /dev/null +++ b/lesson3/test_options.py @@ -0,0 +1,22 @@ +from selenium import webdriver +from selenium.webdriver.chrome.options import Options +import pytest + +@pytest.fixture +def chrome_options(): + options = Options() + # options.add_argument('--window-size=100,100') + options.add_argument('--incognito') + options.add_argument('--headless') + return options + +@pytest.fixture +def driver(chrome_options): + driver = webdriver.Chrome(options=chrome_options) + yield driver + driver.quit() + +def test_example(driver): + driver.get('https://www.saucedemo.com/') + assert driver.current_url == 'https://www.saucedemo.com/' +