Skip to content
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
6 changes: 3 additions & 3 deletions locators/main_page_locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class MainPageLocators:
f"data-action='add-to-wishlist']"),
"add_to_compare": (By.CSS_SELECTOR, f"li[class='product-item']:nth-child({elem}) a["
f"class='action tocompare']")}
ERROR_MESSAGE = (By.CSS_SELECTOR, "div[class='message-error error message']")
SUCCESSFUL_MESSAGE = (By.CSS_SELECTOR, "div[data-ui-id='message-success']")
# ERROR_MESSAGE = (By.CSS_SELECTOR, "div[class='message-error error message']")
ERROR_MESSAGE = (By.CSS_SELECTOR, "div[class='messages']:nth-child(1)")

# Promo Block
PROMO_BLOCK = (By.CSS_SELECTOR, ".blocks-promo")
Expand All @@ -33,4 +33,4 @@ class MainPageLocators:
SECTION_2_BLOCK_1_INFO_BLOCK = (By.CSS_SELECTOR, ".home-pants .content")
SECTION_2_BLOCK_1_INFO_BLOCK_SIGN = (By.CSS_SELECTOR, ".home-pants .content .icon")
SECTION_2_BLOCK_1_INFO_BLOCK_TEXT = (By.CSS_SELECTOR, ".home-pants .content .info")
SECTION_2_BLOCK_1_INFO_BLOCK_TITLE = (By.CSS_SELECTOR, ".home-pants .content .title")
SECTION_2_BLOCK_1_INFO_BLOCK_TITLE = (By.CSS_SELECTOR, ".home-pants .content .title")
258 changes: 46 additions & 212 deletions pages/main_page.py
Original file line number Diff line number Diff line change
@@ -1,236 +1,70 @@
"""This section contains the basic steps for running homepage tests"""
import time

import allure
from selenium.webdriver.common.by import By

from locators.main_page_locators import MainPageLocators
from pages.base_page import BasePage
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
import allure
from selenium.webdriver import ActionChains


class MainPage(BasePage):
locators = MainPageLocators

def check_for_shadow_appearance_when_hovering_over_the_card(self):
"""Checks for shadows to appear when looking at a card"""
card_item = self.element_is_visible(self.locators.PRODUCT_CARD)
shadow_before = card_item.value_of_css_property("box-shadow")
self.action_move_to_element(card_item)
shadow_after = card_item.value_of_css_property("box-shadow")
return shadow_before, shadow_after

def check_product_card_title(self):
"""Checks product card title"""
card_item = self.element_is_visible(self.locators.CARD_TITLE)
text_title = card_item.text
return text_title

def check_the_correct_page_title_after_click_on_the_card(self):
"""
This method gets the title text of the product card,
click on the product card, go to the product page,
get the title of the product and return the titles
"""
text_before = self.get_text(self.locators.CARD_TITLE)
self.element_is_visible(self.locators.CARD_IMG).click()
text_after = self.get_text(self.locators.H1_TITLE)
return text_before, text_after

def check_card_price(self):
"""
This method gets the price of an item
:return: price in USD
"""
text = self.get_text(self.locators.CARD_PRICE)
return text

def hover_by_item(self):
"""This method finds a visible element Product card,
simulates a hover action by moving the cursor to it,"""
card_item = self.element_is_visible(self.locators.PRODUCT_CARD)
self.action_move_to_element(card_item)

def btn_is_visible(self):
"""This method check that button Add to Cart is visible
on the product card when hover by product"""
self.hover_by_item()
btn_status = self.element_is_visible(self.locators.PRODUCT_CARD_BUTTONS["add_to_card"])
return btn_status

@allure.step("Check the color change on hover on the Add to Cart button")
def check_the_color_change_to_add_to_cart_button(self):
"""
This method hovers the mouse cursor over the product card,
hovers the mouse cursor over the add to cart button,
and checks for the button color change
"""
with allure.step("Get button properties before hover"):
add_to_card_button = self.element_is_present(self.locators.PRODUCT_CARD_BUTTONS["add_to_card"])
background_before = add_to_card_button.value_of_css_property("background-color")
with allure.step("Hover mouse cursor on a product card"):
card = self.element_is_visible(self.locators.PRODUCT_CARD)
self.action_move_to_element(card)
with allure.step("Hover mouse cursor over 'add to cart' button"):
background_after = self.check_element_hover_style_using_js(add_to_card_button, "background-color")
return background_before, background_after

@allure.step("Check the cursor change on hover on the card buttons")
def check_the_cursor_change_to_cart_buttons(self, item):
"""
This method hovers the mouse cursor over the product card,
hovers the mouse cursor over the add to cart button,
and checks for the button cursor change
"""
with allure.step("Get button properties before hover"):
cursor_before = self.driver.execute_script("""return window.getComputedStyle(document.body).cursor;""")
with allure.step("Hover mouse cursor on a product card"):
card = self.element_is_visible(self.locators.PRODUCT_CARD)
self.action_move_to_element(card)
with allure.step("Hover mouse cursor over button"):
cursor = self.element_is_present(self.locators.PRODUCT_CARD_BUTTONS[item])
cursor_after = self.check_element_hover_style_using_js(cursor, "cursor")
return cursor_before, cursor_after

@allure.step("Check the color change on hover on the wishlist button and add to compare button")
def check_the_color_change_my_wish_and_add_to_compare_button(self, item):
"""
This method hovers the mouse cursor over the product card,
hovers the mouse cursor over the wishlist button and add to compare button,
and checks for the button color change
"""
with allure.step("Get button properties before hover"):
add_to_card_button = self.element_is_present(self.locators.PRODUCT_CARD_BUTTONS[item])
color_before = add_to_card_button.value_of_css_property("color")
with allure.step("Hover mouse cursor on a product card"):
card = self.element_is_visible(self.locators.PRODUCT_CARD)
self.action_move_to_element(card)
with allure.step(f"Hover mouse cursor over '{item}' button"):
color_after = self.check_element_hover_style_using_js(add_to_card_button, "color")
return color_before, color_after

@allure.step("Checking the display of an element on the screen")
def check_element_display(self, item):
"""
This method checks that the element is displayed on the screen.
:return: True or False
"""
product_card = self.element_is_visible(self.locators.PRODUCT_CARD)
self.action_move_to_element(product_card)
element = self.element_is_visible(self.locators.PRODUCT_CARD_BUTTONS[item])
return element.is_displayed()

@allure.step("Check the transition to the page my desires when clicking on the button. User is not authorized")
@allure.step("Check the transition to the page my desires when clicking on the button")
def check_the_transition_to_the_page_my_wish_after_click_on_the_button(self):
"""
This method hovers the mouse over the product card,
clicks the add to favorites button
and checks that the correct page has been navigated to
User is not authorized
and checks that the correct page has been navigated to.
:return:
"""
action = ActionChains(self.driver)
product_card = self.element_is_visible(self.locators.PRODUCT_CARD)
self.action_move_to_element(product_card)
button = self.element_is_visible(self.locators.PRODUCT_CARD_BUTTONS["add_to_wish_list"])
print('card')
button = self.element_is_present(self.locators.PRODUCT_CARD_BUTTONS["add_to_wish_list"])
print(button.text)
self.action_move_to_element(button)
# action.click(button).perform()
button.click()
# self.driver.execute_script("arguments[0].click();", button)
print("button")
time.sleep(5)
# action.pause(10).perform()
error_message = self.get_error_message()
return error_message.text

@allure.step("Check the error message")
def get_error_message(self):
"""
This method check error message
"""
error_message = self.element_is_visible(self.locators.ERROR_MESSAGE, 15)
return error_message

@allure.step("Check the transition to the page my desires when clicking on the button. User is not authorized")
def check_the_transition_to_the_page_my_wish_after_click_on_the_button_user_authorized(self):
"""
This method hovers the mouse over the product card,
clicks the add to favorites button
and checks that the correct page has been navigated to
User is not authorized
"""
card_title = self.element_is_visible(self.locators.CARD_TITLE).text
product_card = self.element_is_visible(self.locators.PRODUCT_CARD)
self.action_move_to_element(product_card)
button = self.element_is_present(self.locators.PRODUCT_CARD_BUTTONS["add_to_wish_list"])
# self.action_move_to_element(button)
self.driver.execute_script("arguments[0].click();", button)
# button.click()
text = self.get_successful_message()
# self.delete_my_wish_list()
return text, card_title

@allure.step("Check the error message")
def get_successful_message(self):
"""
This method check successful message
"""
text = self.element_is_visible(self.locators.SUCCESSFUL_MESSAGE)
return text.text


class PromoBlock(BasePage):
locators = MainPageLocators

def check_promo_block_display(self):
"""Checks promo block display"""
promo_block = self.element_is_visible(self.locators.PROMO_BLOCK)
return promo_block.is_displayed()

def check_image_in_section1(self):
"""Checks the image in section 1 'home-main'"""
element = self.element_is_visible(self.locators.SECTION_1_IMAGE)
section1_image = element.get_attribute("src")
return section1_image

def check_info_block_text_in_section1(self):
"""Checks the text of info-block in section 1 'home-main'"""
element = self.element_is_visible(self.locators.SECTION_1_INFO_BLOCK_TEXT)
info_block_text = element.text
return info_block_text

def check_info_block_title_in_section1(self):
"""Checks the title of info-block in section 1 'home-main'"""
element = self.element_is_visible(self.locators.SECTION_1_INFO_BLOCK_TITLE)
info_block_title = element.text
return info_block_title

def check_section2_display(self):
"""Checks section 2 display"""
section2 = self.element_is_visible(self.locators.SECTION_2)
return section2.is_displayed()

def check_section2_block1_display(self):
"""Checks section 2 block 1 'home-pants' display"""
section2_block1 = self.element_is_visible(self.locators.SECTION_2_BLOCK_1)
return section2_block1.is_displayed()

def check_block_image_in_section2_block1(self):
"""Checks the image in block 1 'home-pants'"""
element = self.element_is_visible(self.locators.SECTION_2_BLOCK_1_IMAGE)
info_block_image = element.get_attribute("src")
return info_block_image

def check_info_block_display_in_section2_block1(self):
"""Checks the info block 1 display in section 2 of promo block under header"""
info_block = self.element_is_visible(self.locators.SECTION_2_BLOCK_1_INFO_BLOCK)
return info_block.is_displayed()

def check_info_block_title_in_section2_block1(self):
"""Checks the title of info-block in block 1 'home-pants'"""
element = self.element_is_visible(self.locators.SECTION_2_BLOCK_1_INFO_BLOCK_TITLE)
info_block_title = element.text
return info_block_title

def check_info_block_text_in_section2_block1(self):
"""Checks the text of info-block in block 1 'home-pants'"""
element = self.element_is_visible(self.locators.SECTION_2_BLOCK_1_INFO_BLOCK_TEXT)
info_block_text = element.text
return info_block_text
def get_error_message(self):

def check_info_block_sign_in_section2_block1(self):
"""Checks the sign in info-block in block 1 'home-pants'"""
element = self.element_is_visible(self.locators.SECTION_2_BLOCK_1_INFO_BLOCK_SIGN)
info_block_sign = element.text
return info_block_sign
error_message_locator = (By.XPATH, "//div[@data-bind='html: $parent.prepareMessageForHtml(message.text)']")
window_handles = self.driver.window_handles
print(f"""window_handles : {len(window_handles)}""")
print(self.driver.current_url)
print(self.driver.title)
# script = """
# var element = document.querySelector('.message.error div');
# var computedStyle = window.getComputedStyle(element, '::before');
# var content = computedStyle.content;
#
# return content;
# """
# script = """
# var element = document.querySelector('.message.error');
# var pseudoElement = window.getComputedStyle(element, ':before').getPropertyValue('content');
# var temp = document.createElement('div');
# temp.innerHTML = pseudoElement;
# var content = temp.textContent || temp.innerText;
# return content.replace(/['"]+/g, '');
# """
# result = self.driver.execute_script(script)
# print(result)
error_message_element = wait(self.driver, 30).until(EC.visibility_of_element_located(error_message_locator))
print(error_message_element.text)
# print("element")
# error_message = self.driver.execute_script("return arguments[0].textContent;", error_message_element)
# print(error_message)
return error_message_element
Loading