From b220966b3b060348e21d3c05f339830e6789355f Mon Sep 17 00:00:00 2001 From: Angelika Date: Tue, 10 Oct 2023 09:54:34 -0400 Subject: [PATCH 1/4] adding a test_add_to_cart --- .idea/.gitignore | 3 + .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/misc.xml | 4 + .idea/modules.xml | 8 ++ .idea/pytest_course_viktor.iml | 10 +++ .idea/vcs.xml | 6 ++ lesson1/test_add_to_cart.py | 75 +++++++++++++++++++ 7 files changed, 112 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_viktor.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..0e2486c --- /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..2372a69 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/pytest_course_viktor.iml b/.idea/pytest_course_viktor.iml new file mode 100644 index 0000000..f4efaa4 --- /dev/null +++ b/.idea/pytest_course_viktor.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ 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..41270da --- /dev/null +++ b/lesson1/test_add_to_cart.py @@ -0,0 +1,75 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +import time + +driver = webdriver.Chrome() + + +def test_add_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() + + text_before = driver.find_element(By.XPATH, '//*[@id="item_4_title_link"]/div').text + add_to_cart_button = driver.find_element(By.XPATH, '//*[@id="add-to-cart-sauce-labs-backpack"]') + add_to_cart_button.click() + + time.sleep(3) + + cart_button = driver.find_element(By.XPATH, '//*[@id="shopping_cart_container"]/a') + cart_button.click() + + cart_badge = driver.find_element(By.XPATH, '//*[@id="shopping_cart_container"]/a/span') + text_after = driver.find_element(By.XPATH, '//*[@id="item_4_title_link"]/div').text + remove_button = driver.find_element(By.XPATH, '//*[@id="remove-sauce-labs-backpack"]') + + assert cart_badge.text == '1' + assert driver.current_url == "https://www.saucedemo.com/cart.html" + assert text_before == text_after + assert remove_button.text == "Remove" + + driver.quit() +from selenium import webdriver +from selenium.webdriver.common.by import By +import time + +driver = webdriver.Chrome() + +def test_add_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() + + text_before = driver.find_element(By.XPATH, '//*[@id="item_4_title_link"]/div').text + add_to_cart_button = driver.find_element(By.XPATH, '//*[@id="add-to-cart-sauce-labs-backpack"]') + add_to_cart_button.click() + + time.sleep(3) + + cart_button = driver.find_element(By.XPATH, '//*[@id="shopping_cart_container"]/a') + cart_button.click() + + cart_badge = driver.find_element(By.XPATH, '//*[@id="shopping_cart_container"]/a/span') + text_after = driver.find_element(By.XPATH, '//*[@id="item_4_title_link"]/div').text + remove_button = driver.find_element(By.XPATH, '//*[@id="remove-sauce-labs-backpack"]') + + assert cart_badge.text == '1' + assert driver.current_url == "https://www.saucedemo.com/cart.html" + assert text_before == text_after + assert remove_button.text == "Remove" + + driver.quit() From dac4ad61a0067d2fc05d6ae0415635126ea1ff8e Mon Sep 17 00:00:00 2001 From: Angelika Date: Tue, 10 Oct 2023 12:12:43 -0400 Subject: [PATCH 2/4] Adding test_add_to_cart_from_item_card --- lesson1/test_add_to_cart_from_item_card.py | 43 ++++++++++++++++++++++ lesson1/test_remove_from_cart.py | 0 2 files changed, 43 insertions(+) create mode 100644 lesson1/test_add_to_cart_from_item_card.py create mode 100644 lesson1/test_remove_from_cart.py diff --git a/lesson1/test_add_to_cart_from_item_card.py b/lesson1/test_add_to_cart_from_item_card.py new file mode 100644 index 0000000..75baa09 --- /dev/null +++ b/lesson1/test_add_to_cart_from_item_card.py @@ -0,0 +1,43 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +import time + +driver = webdriver.Chrome() + + +def test_add_to_cart_from_item_card(): + 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() + + # text_before = driver.find_element(By.XPATH, '//*[@id="item_4_title_link"]/div').text + + item_button = driver.find_element(By.XPATH, '//*[@id="item_4_title_link"]/div') + item_button.click() + + add_to_cart_button = driver.find_element(By.XPATH, '//*[@id="add-to-cart-sauce-labs-backpack"]') + add_to_cart_button.click() + + + time.sleep(3) + + cart_button = driver.find_element(By.XPATH, '//*[@id="shopping_cart_container"]/a') + cart_button.click() + + cart_badge = driver.find_element(By.XPATH, '//*[@id="shopping_cart_container"]/a/span') + remove_button = driver.find_element(By.XPATH, '//*[@id="remove-sauce-labs-backpack"]') + + + assert cart_badge.text == '1' + assert driver.current_url == "https://www.saucedemo.com/cart.html" + assert remove_button.text == "Remove" + assert driver.find_element(By.XPATH, '//*[@id="cart_contents_container"]/div/div[1]/div[3]/div[2]').is_displayed() + + driver.quit() diff --git a/lesson1/test_remove_from_cart.py b/lesson1/test_remove_from_cart.py new file mode 100644 index 0000000..e69de29 From 780b70cf00fee33e1fcd17ae3f6f07460316753f Mon Sep 17 00:00:00 2001 From: Angelika Date: Tue, 10 Oct 2023 13:53:55 -0400 Subject: [PATCH 3/4] Adding test_remove_from_cart_from_item_card --- .../test_remove_from_cart_from_item_card.py | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 lesson1/test_remove_from_cart_from_item_card.py diff --git a/lesson1/test_remove_from_cart_from_item_card.py b/lesson1/test_remove_from_cart_from_item_card.py new file mode 100644 index 0000000..55c42a9 --- /dev/null +++ b/lesson1/test_remove_from_cart_from_item_card.py @@ -0,0 +1,43 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +import time + +driver = webdriver.Chrome() + + +def test_remove_from_cart_from_item_card(): + 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() + + item_button = driver.find_element(By.XPATH, '//*[@id="item_4_title_link"]/div') + item_button.click() + + # adding item to the cart + add_to_cart_button = driver.find_element(By.XPATH, '//*[@id="add-to-cart-sauce-labs-backpack"]') + add_to_cart_button.click() + time.sleep(3) + + # removing item from the item card + remove_button = driver.find_element(By.XPATH, '//*[@id="remove-sauce-labs-backpack"]') + remove_button.click() + time.sleep(3) + + # assert add_to_cart_button.is_displayed() + assert "Remove" not in driver.page_source + assert "Add to cart" in driver.page_source + + cart_button = driver.find_element(By.XPATH, '//*[@id="shopping_cart_container"]/a') + cart_button.click() + time.sleep(3) + + assert "Sauce Labs Backpack" not in driver.page_source + + driver.quit() From b19b33454f45937f7a247e0cf1cb2edbf3232acf Mon Sep 17 00:00:00 2001 From: Angelika Date: Tue, 10 Oct 2023 14:46:51 -0400 Subject: [PATCH 4/4] Adding test_remove_from_cart_from_item_card --- lesson1/test_item_image_and_title.py | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 lesson1/test_item_image_and_title.py diff --git a/lesson1/test_item_image_and_title.py b/lesson1/test_item_image_and_title.py new file mode 100644 index 0000000..aa5ed3d --- /dev/null +++ b/lesson1/test_item_image_and_title.py @@ -0,0 +1,55 @@ +# Карточка товара +# Успешный переход к карточке товара после клика на картинку товара +# Успешный переход к карточке товара после клика на название товара + + +from selenium import webdriver +from selenium.webdriver.common.by import By +import time + +driver = webdriver.Chrome() + + +def test_item_image(): + 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() + + # clicking on the item image + item_image = driver.find_element(By.XPATH, '//*[@id="item_4_img_link"]/img') + item_image.click() + time.sleep(1) + + assert driver.current_url == "https://www.saucedemo.com/inventory-item.html?id=4" + assert "Sauce Labs Backpack" in driver.page_source + + driver.quit() + +def test_item_title(): + 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() + + + # clicking on the item title + item_title = driver.find_element(By.XPATH, '//*[@id="item_4_title_link"]/div') + item_title.click() + time.sleep(1) + + assert driver.current_url == "https://www.saucedemo.com/inventory-item.html?id=4" + assert "Sauce Labs Backpack" in driver.page_source + driver.quit() \ No newline at end of file