From d16a4bbec80de0e097d2ab1312db0d6c6bbcfd99 Mon Sep 17 00:00:00 2001 From: Cruz06 Date: Wed, 15 May 2024 21:54:46 +0300 Subject: [PATCH] corr tests 3 and shipping --- pages/locators.py | 3 +- pages/urls.py | 9 +++++ tests/test_performance_sportswear.py | 17 ++++---- tests/test_sale_page.py | 3 +- tests/test_search_terms.py | 58 ++++++++++++---------------- tests/test_shipping.py | 39 +++++++++++++++++++ tests/test_women_sale.py | 11 +++--- tests/test_women_tee.py | 19 ++++----- 8 files changed, 101 insertions(+), 58 deletions(-) create mode 100644 tests/test_shipping.py diff --git a/pages/locators.py b/pages/locators.py index e159a8f9..6e8efc15 100644 --- a/pages/locators.py +++ b/pages/locators.py @@ -5,7 +5,7 @@ class SalePageLocators: GEAR_DEALS_TITLE = "//*[text()='Gear Deals']" BAGS_LINK = "//a[text()='Bags']" FITNESS_EQUIPMENT_LINK = "//a[text()='Fitness Equipment']" - LINK_SALE = "https://magento.softwaretestingboard.com/sale.html" + LINK_WOMEN_SALE = "https://magento.softwaretestingboard.com/promotions/women-sale.html" LINK_TEES_WOMEN = "https://magento.softwaretestingboard.com/women/tops-women/tees-women.html" @@ -81,7 +81,6 @@ class BaseLocators: class SearchTermsLocators: - LINK_SEARCH_TERMS = "https://magento.softwaretestingboard.com/search/term/popular/" TERMS_FOR_SEARCH_LIST_QTY = '[class="item"]' LIST_OF_SEARCH_TERMS = '[class="item"] a' diff --git a/pages/urls.py b/pages/urls.py index fc8ebddb..98d74e4b 100644 --- a/pages/urls.py +++ b/pages/urls.py @@ -1 +1,10 @@ main_page_link = "https://magento.softwaretestingboard.com" +LINK_SPORT = "https://magento.softwaretestingboard.com/collections/performance-new.html" +LINK_LOGIN = 'https://magento.softwaretestingboard.com/customer/account/login' +LINK_ACCOUNT = 'https://magento.softwaretestingboard.com/customer/account/' +LINK_SEARCH_TERMS = "https://magento.softwaretestingboard.com/search/term/popular/" +LINK_SALE = "https://magento.softwaretestingboard.com/sale.html" +LINK_WOMEN_SALE = "https://magento.softwaretestingboard.com/promotions/women-sale.html" +LINK_TEES_WOMEN = "https://magento.softwaretestingboard.com/women/tops-women/tees-women.html" + + diff --git a/tests/test_performance_sportswear.py b/tests/test_performance_sportswear.py index 1d4391f2..b3aaaed6 100644 --- a/tests/test_performance_sportswear.py +++ b/tests/test_performance_sportswear.py @@ -3,7 +3,7 @@ import pytest from selene.support.conditions.have import values_containing, values from selenium.webdriver.common.by import By - +from pages.urls import * from pages.locators import PerformanceSportswear, BaseLocators, LoginLocators, ProductLocators from selene import browser, be, have, query, command from selene.support.shared.jquery_style import s, ss @@ -12,7 +12,7 @@ def test_006_008_001_visibility_of_price_photo_name(): # I can't count elements on the page via selen - browser.open(PerformanceSportswear.LINK_SPORT) + browser.open(LINK_SPORT) ss(BaseLocators.PRODUCT_NAME).should(have.size(5)) ss(BaseLocators.PRODUCT_PRICE).should(have.size(5)) ss(BaseLocators.PRODUCT_IMAGE).should(have.size(5)) @@ -20,8 +20,8 @@ def test_006_008_001_visibility_of_price_photo_name(): def test_006_008_001_visibility_of_price_photo_name_selenium(driver): # I have to find actual nr of elements on the page via python/selenium - browser.open(PerformanceSportswear.LINK_SPORT) - driver.get(PerformanceSportswear.LINK_SPORT) + browser.open(LINK_SPORT) + driver.get(LINK_SPORT) nr_of_items_on_page = len(driver.find_elements(By.CSS_SELECTOR, BaseLocators.PRODUCT_ITEM_IN_CATALOG)) ss(BaseLocators.PRODUCT_NAME).should(have.size(nr_of_items_on_page)) ss(BaseLocators.PRODUCT_PRICE).should(have.size(nr_of_items_on_page)) @@ -29,7 +29,7 @@ def test_006_008_001_visibility_of_price_photo_name_selenium(driver): def test_006_008_002_add_to_cart_from_catalog_without_color_and_size(): - browser.open(LoginLocators.LINK_LOGIN) + browser.open(LINK_LOGIN) s(LoginLocators.FIELD_NAME).type("ahahah1@gmail.com") s(LoginLocators.FIELD_PASSWORD).type("jk$34_tor") s(LoginLocators.BUTTON_SUBMIT).click() @@ -38,8 +38,9 @@ def test_006_008_002_add_to_cart_from_catalog_without_color_and_size(): s(PerformanceSportswear.BUTTON_ADD_ITEM2).perform(command.js.click) s(PerformanceSportswear.SUCCESS_MESSAGE).should(have.no.text(PerformanceSportswear.TEXT_SUCCESS_MESSAGE)) + def test_006_008_002_add_to_cart_from_catalog_without_color_and_size_with_hover(): - browser.open(LoginLocators.LINK_LOGIN) + browser.open(LINK_LOGIN) s(LoginLocators.FIELD_NAME).type("ahahah1@gmail.com") s(LoginLocators.FIELD_PASSWORD).type("jk$34_tor") s(LoginLocators.BUTTON_SUBMIT).click() @@ -51,7 +52,7 @@ def test_006_008_002_add_to_cart_from_catalog_without_color_and_size_with_hover( def test_006_008_003_color_and_size_can_be_checked(): - browser.open(LoginLocators.LINK_LOGIN) + browser.open(LINK_LOGIN) s(LoginLocators.FIELD_NAME).type("ahahah1@gmail.com") s(LoginLocators.FIELD_PASSWORD).type("jk$34_tor") s(LoginLocators.BUTTON_SUBMIT).click() @@ -64,7 +65,7 @@ def test_006_008_003_color_and_size_can_be_checked(): def test_006_008_004_add_to_cart_from_product_page_without_color_and_size(): - browser.open(LoginLocators.LINK_LOGIN) + browser.open(LINK_LOGIN) s(LoginLocators.FIELD_NAME).type("ahahah1@gmail.com") s(LoginLocators.FIELD_PASSWORD).type("jk$34_tor") s(LoginLocators.BUTTON_SUBMIT).click() diff --git a/tests/test_sale_page.py b/tests/test_sale_page.py index 027f08f8..df3305c4 100644 --- a/tests/test_sale_page.py +++ b/tests/test_sale_page.py @@ -1,6 +1,7 @@ from selene import browser, be, have from selene.support.shared.jquery_style import s, ss from pages.locators import SalePageLocators, BaseLocators +from pages.urls import * import allure @@ -63,7 +64,7 @@ def test_fitness_link_correct_redirection(): def test_011_001_001_sale_breadcrumbs_is_correct(): - browser.open(SalePageLocators.LINK_SALE) + browser.open(LINK_SALE) ss(BaseLocators.BREADCRUMBS_LIST).should(have.texts('Home', 'Sale')) diff --git a/tests/test_search_terms.py b/tests/test_search_terms.py index 1fdda222..26e52892 100644 --- a/tests/test_search_terms.py +++ b/tests/test_search_terms.py @@ -1,5 +1,5 @@ from selenium.webdriver.common.by import By - +from pages.urls import * from pages.locators import SearchTermsLocators as ST from pages.locators import BaseLocators as Base from selene import browser, be, have, query @@ -7,31 +7,31 @@ def test_015_001_001_search_terms_title_is_visible(): - browser.open(ST.LINK_SEARCH_TERMS) + browser.open(LINK_SEARCH_TERMS) s(Base.PAGE_TITLE).should(have.text("Popular Search Terms")) # def test_015_001_001_selenium(driver): -# driver.get(ST.LINK_SEARCH_TERMS) +# driver.get(LINK_SEARCH_TERMS) # expected_title = "Popular Search Terms" # actual_title = driver.find_element(*Base.PAGE_TITLE).text # assert expected_title == actual_title, "Page title is not correct" def test_015_001_002_count_search_terms(): - browser.open(ST.LINK_SEARCH_TERMS) + browser.open(LINK_SEARCH_TERMS) ss(ST.TERMS_FOR_SEARCH_LIST_QTY).should(have.size(100)) # def test_015_001_002_selenium(driver): -# driver.get(ST.LINK_SEARCH_TERMS) +# driver.get(LINK_SEARCH_TERMS) # q_of_goods = len(driver.find_elements(*ST.TERMS_FOR_SEARCH_LIST_QTY)) # assert q_of_goods == 100, "Nr of search terms is not equal to 100" def test_015_001_003_check_if_search_terms_has_size_from_76_till_136(): # assert from selenium - how to check sizes - browser.open(ST.LINK_SEARCH_TERMS) + browser.open(LINK_SEARCH_TERMS) list_font_sizes = [] terms = ss(ST.LIST_OF_SEARCH_TERMS) for g in terms: @@ -42,7 +42,7 @@ def test_015_001_003_check_if_search_terms_has_size_from_76_till_136(): def test_015_001_003_check_if_search_terms_has_size_from_76_till_136_selenium(driver): - driver.get(ST.LINK_SEARCH_TERMS) + driver.get(LINK_SEARCH_TERMS) list_font_sizes = [] terms = driver.find_elements(By.CSS_SELECTOR, ST.LIST_OF_SEARCH_TERMS) for g in terms: @@ -57,7 +57,7 @@ def test_015_001_003_check_if_search_terms_has_size_from_76_till_136_selenium(dr def test_015_001_004_check_if_5_search_terms_is_bigger(driver): - driver.get(ST.LINK_SEARCH_TERMS) + driver.get(LINK_SEARCH_TERMS) list_font_sizes = [] terms = driver.find_elements(By.CSS_SELECTOR, ST.LIST_OF_SEARCH_TERMS) for g in terms: @@ -70,9 +70,9 @@ def test_015_001_004_check_if_5_search_terms_is_bigger(driver): assert False, "List of search terms has not 5 elements which size is bigger than 88%" -def test_015_001_005_check_if_specified_words_is_bigger_than_88(driver): +def test_015_001_005_check_if_specified_words_is_bigger_than_88_selenium(driver): words = ["HOODIE", "jacket", "pants", "shirt"] - driver.get(ST.LINK_SEARCH_TERMS) + driver.get(LINK_SEARCH_TERMS) list_of_goods = [] list_font_sizes = [] terms = driver.find_elements(By.CSS_SELECTOR, ST.LIST_OF_SEARCH_TERMS) @@ -89,49 +89,41 @@ def test_015_001_005_check_if_specified_words_is_bigger_than_88(driver): [size > 88 for size in list_font_sizes]), "Selected words have font size bigger thjan 88%" -def test_015_001_005_check_if_specified_words_is_bigger_than_88_selenium(driver): - words = ["HOODIE", "jacket", "pants", "shirt"] - driver.get(ST.LINK_SEARCH_TERMS) +def test_015_001_005_check_if_specified_words_is_bigger_than_88(): + words = ["hoodie", "jacket", "pants", "shirt"] + browser.open(LINK_SEARCH_TERMS) list_of_goods = [] list_font_sizes = [] - terms = driver.find_elements(By.CSS_SELECTOR, ST.LIST_OF_SEARCH_TERMS) - for g in terms: - if g.text in words: - list_of_goods.append(g.text) - g_font, g_size = g.get_attribute("style").split(": ") - g_size = g_size.replace("%;", "") - g_size = float(g_size) + terms = ss(ST.LIST_OF_SEARCH_TERMS) + for keyword in terms: + word = keyword.get(query.attribute("text")).strip().replace(" ", "").lower() + if word in words: + list_of_goods.append(word) + g_font, g_size = keyword.get(query.attribute("style")).split(": ") + g_size = float(g_size.replace("%;", "")) list_font_sizes.append(g_size) # print(list_of_goods) # print(list_font_sizes) assert set(list_of_goods) == set(words) and all( - [size > 88 for size in list_font_sizes]), "Selected words have font size bigger thjan 88%" + [size > 88 for size in list_font_sizes]), "Selected words have font size bigger than 88%" def test_015_001_006_check_if_search_terms_are_sorted(): # список ключевых,вытаскиваемых с помощью selene, выглядит не так, как при selenium. # Теперь есть лишние пробелы, перевод строки, слова с малой буквы неправильно сортируются. # С selenium тест = ОК - browser.open(ST.LINK_SEARCH_TERMS) + browser.open(LINK_SEARCH_TERMS) list_of_goods = [] # good : strip, lower, no spaces - list_of_goods0 = [] # words from terms applied lower() + list_of_goods_from_terms = [] # words from terms applied lower() terms = ss(ST.LIST_OF_SEARCH_TERMS) for keyword in terms: keyword = keyword.get(query.attribute("text")).strip().replace(" ","").lower() - list_of_goods0.append(keyword.lower()) + list_of_goods_from_terms.append(keyword.lower()) list_of_goods.append(keyword) # print(list_of_goods0) # print(list_of_goods) # print(sorted(list_of_goods)) list_of_goods_sorted = sorted(list_of_goods) - assert list_of_goods0 == list_of_goods_sorted + assert list_of_goods_from_terms == list_of_goods_sorted -# def test_015_001_006_check_if_search_terms_are_sorted_selenium(driver): -# driver.get(ST.LINK_SEARCH_TERMS) -# list_of_goods = [] -# terms = ss(ST.LIST_OF_SEARCH_TERMS) -# for g in terms: -# list_of_goods.append(g.text) -# sorted_list = sorted(list_of_goods) -# assert list_of_goods == sorted_list, "Goods are not sorted from A to Z" \ No newline at end of file diff --git a/tests/test_shipping.py b/tests/test_shipping.py new file mode 100644 index 00000000..e44cc049 --- /dev/null +++ b/tests/test_shipping.py @@ -0,0 +1,39 @@ +import time +from pages.urls import * +from pages.locators import WomenLocators, Shipping, Order +from selene import browser, be, have +from selene.support.shared.jquery_style import s, ss +from selene.support.conditions import be, have + + +def test_004_001_002_guest_user_checkout_from_minicart(): + browser.open(LINK_WOMEN) + # choose item + s(WomenLocators.TANK_SIZE).click() + s(WomenLocators.TANK_COLOR).click() + s(WomenLocators.TANK_BUTTON_ADD).click() + time.sleep(2) + s(WomenLocators.MESSAGE_SUCCESS_ADD).should(have.text("You added")) + # open minicart + s(WomenLocators.SHOW_BASKET).should(be.clickable).click() # CHECK HERE + s(WomenLocators.CHECKOUT_BUTTON).should(be.visible) + s(WomenLocators.CHECKOUT_BUTTON).should(be.clickable).click() + # fill address + browser.should(have.url(LINK_SHIPPING)) + s(Shipping.FIELD_EMAIL).type("email@mail.aaa") + s(Shipping.FIELD_FIRST_NAME).type("f_name") + s(Shipping.FIELD_LAST_NAME).type("l_name") + s(Shipping.FIELD_STREET).type("street") + s(Shipping.FIELD_CITY).type("city") + s(Shipping.FIELD_REGION).press("Alabama") + s(Shipping.FIELD_ZIPCODE).type("MD2060") + s(Shipping.FIELD_COUNTRY).press("Tanzania") + s(Shipping.FIELD_PHONE).type("1234567890") + s(Shipping.SHIPPING_METHOD).should(be.clickable).click() + s(Shipping.CONTINUE_BUTTON).should(be.clickable).click() + browser.should(have.url(LINK_PAYMENT)) + # check data and place order + s(Order.BUTTON_PLACE_ORDER).click() + s(Order.MESSAGE_SUCCEES).should(have.text("Your order # is")) + s(Order.ORDER_PAGE_TITLE).should(have.text("Thank you for your purchase!")) + diff --git a/tests/test_women_sale.py b/tests/test_women_sale.py index 622c2aba..c0e70b25 100644 --- a/tests/test_women_sale.py +++ b/tests/test_women_sale.py @@ -2,12 +2,13 @@ from pages.locators import SalePageLocators, BaseLocators from selene import browser, be, have from selene.support.shared.jquery_style import s, ss +from pages.urls import * # @pytest.mark.xfail # def test_011_011_001_selenium(driver): # # assert error !!! 'Sale' is missing -# driver.get(SalePageLocators.LINK_WOMEN_SALE) +# driver.get(LINK_WOMEN_SALE) # list_br = driver.find_elements(*BaseLocators.BREADCRUMBS_LIST) # expected_list_breadcrumbs = ['Home', 'Sale', 'Women Sale'] # actual_list_breadcrumbs = [] @@ -18,12 +19,12 @@ @pytest.mark.skip def test_011_011_001_women_sale_breadcrumbs_is_correct(): # assert error !!! 'Sale' is missing - browser.open(SalePageLocators.LINK_WOMEN_SALE) + browser.open(LINK_WOMEN_SALE) ss(BaseLocators.BREADCRUMBS_LIST).should(have.texts('Home', 'Sale', 'Women Sale')) # def test_011_011_002_selenium(driver): -# driver.get(SalePageLocators.LINK_WOMEN_SALE) +# driver.get(LINK_WOMEN_SALE) # breadcrumbs_links = driver.find_elements(*BaseLocators.BREADCRUMBS_LINKS) # links = [elem.get_attribute('href') for elem in breadcrumbs_links] # for elem in links: @@ -32,7 +33,7 @@ def test_011_011_001_women_sale_breadcrumbs_is_correct(): # def test_011_011_002_breadcrumbs_redirection_from_women_sale(): - browser.open(SalePageLocators.LINK_WOMEN_SALE) + browser.open(LINK_WOMEN_SALE) elements = ss(BaseLocators.BREADCRUMBS_LINKS).by(have.attribute('href')) expected_links = ['https://magento.softwaretestingboard.com/', 'https://magento.softwaretestingboard.com/sale.html'] @@ -41,7 +42,7 @@ def test_011_011_002_breadcrumbs_redirection_from_women_sale(): # def test_011_011_002_breadcrumbs_redirection_from_women_sale(): -# browser.open(SalePageLocators.LINK_WOMEN_SALE) +# browser.open(LINK_WOMEN_SALE) # # breadcrumbs_links = ss(BaseLocators.BREADCRUMBS_LINKS) # links = ss(BaseLocators.BREADCRUMBS_LINKS).filtered_by(have.attribute('href')) # diff --git a/tests/test_women_tee.py b/tests/test_women_tee.py index 6797f6e2..7e77a0ae 100644 --- a/tests/test_women_tee.py +++ b/tests/test_women_tee.py @@ -1,7 +1,7 @@ import pytest from selene.support.conditions.have import values_containing, values from selenium.webdriver.support.expected_conditions import any_of - +from pages.urls import * from pages.locators import SalePageLocators, BaseLocators import pytest from selene import browser, be, have, query @@ -14,12 +14,12 @@ def test_011_016_001_women_tees_breadcrumbs_is_correct(): - browser.open(SalePageLocators.LINK_TEES_WOMEN) + browser.open(LINK_TEES_WOMEN) ss(BaseLocators.BREADCRUMBS_LIST).should(have.texts('Home', 'Women', 'Tops', 'Tees')) # def test_011_016_001_selenium(driver): -# driver.get(SalePageLocators.LINK_TEES_WOMEN) +# driver.get(LINK_TEES_WOMEN) # list_br = driver.find_elements(*BaseLocators.BREADCRUMBS_LIST) # expected_list_breadcrumbs = ['Home', 'Women', 'Tops', 'Tees'] # actual_list_breadcrumbs = [] @@ -30,7 +30,7 @@ def test_011_016_001_women_tees_breadcrumbs_is_correct(): # def test_011_016_002_breadcrumbs_redirection_from_women_tees(driver): # # check if all link are there -# driver.get(SalePageLocators.LINK_TEES_WOMEN) +# driver.get(LINK_TEES_WOMEN) # breadcrumb_links = driver.find_elements(*BaseLocators.BREADCRUMBS_LINKS) # links = [elem.get_attribute('href') for elem in breadcrumb_links] # assert links == SalePageLocators.BREADCRUMBS_LINKS_ON_PAGE_TEES @@ -38,7 +38,7 @@ def test_011_016_001_women_tees_breadcrumbs_is_correct(): def test_011_016_002_breadcrumbs_redirection_from_women_tees(): # correct, already in school git - browser.open(SalePageLocators.LINK_TEES_WOMEN) + browser.open(LINK_TEES_WOMEN) elements = ss(BaseLocators.BREADCRUMBS_LINKS).by(have.attribute('href')) expected_links = ['https://magento.softwaretestingboard.com/', 'https://magento.softwaretestingboard.com/women.html', @@ -52,14 +52,14 @@ def test_011_016_002_check_links_in_breadcrumps(): expected_links = ['https://magento.softwaretestingboard.com/', 'https://magento.softwaretestingboard.com/women.html', 'https://magento.softwaretestingboard.com/women/tops-women.html'] - browser.open(SalePageLocators.LINK_TEES_WOMEN) + browser.open(LINK_TEES_WOMEN) for i, item in enumerate(ss(BaseLocators.BREADCRUMBS_LINKS).by(have.attribute('href'))): print(item.get(query.attribute('href'))) assert expected_links[i] == item.get(query.attribute('href')) def test_011_016_002_breadcrumbs_redirection_from_women_tees_new4(): - browser.open(SalePageLocators.LINK_TEES_WOMEN) + browser.open(LINK_TEES_WOMEN) elements = ss(BaseLocators.BREADCRUMBS_LINKS).by(have.attribute('href')) expected_links = ['https://magento.softwaretestingboard.com/', @@ -73,14 +73,15 @@ def test_011_016_002_breadcrumbs_redirection_from_women_tees_new4(): .or_(have.attribute('href').value(expected_links[1])) .or_(have.attribute('href').value(expected_links[2]))) + def test_011_016_002_breadcrumbs_redirection_from_women_tees_new3(): - browser.open(SalePageLocators.LINK_TEES_WOMEN) + browser.open(LINK_TEES_WOMEN) ss(BaseLocators.BREADCRUMBS_LINKS).by(have.attribute('href')).should( have.texts('Home', 'Women', 'Tops')) def test_011_016_002_breadcrumbs_redirection_from_women_tees_new321(): - browser.open(SalePageLocators.LINK_TEES_WOMEN) + browser.open(LINK_TEES_WOMEN) elements = ss('.breadcrumbs > ul > li > a').by(have.attribute('href')) expected_links = ['https://magento.softwaretestingboard.com/',