class CheckingParams: def __init__(self, man): self.man = man self.button = ButtonsHelper(man) def check_filters(self, query, count): wd = self.man.wd self.button.search_goods(wd, query) self.button.click_magnifier(wd) return self.click_checkboxes(wd, count) def click_checkboxes(self, wd, count): filter_block = wd.find_elements_by_xpath( ".//div[@class='cell medium-8 large-6 left_cont col-xs-12 col-md-3 categ']//ul[1]/li[1]//input" ) for fb in filter_block[0:count]: time.sleep(0.5) fb.click() time.sleep(1) wd.find_element_by_id("facet_popup").click() elements = wd.find_elements_by_xpath( ".//div[@class='filterRightTop hidden-xs visible-md visible-lg']/span/strong" ) get_text = [g.text for g in elements] return get_text
def __init__(self, man): self.man = man self.button = ButtonsHelper(man) self.function = CommonFunctions() self.action = ActionChains self.locator = Locators(man) self.__wait = Wait(man)
def __init__(self, man): self.man = man self.button = ButtonsHelper(man) self.forms = FormsHelper(man) self.function = CommonFunctions() self.action = ActionChains self.__wait = Wait(man) self.__locator_xxlarge = "//*[@class='text-size-xxlarge']"
class FunctionMemorized: def __init__(self, man): self.man = man self.button = ButtonsHelper(man) self.function = CommonFunctions() self.locator = Locators(man) self.__wait = Wait(man) # Проверка функции "Запомнено" def check_remember_goods(self, query): wd = self.man.wd self.button.search_goods(wd, query) self.button.click_magnifier(wd) self.button.go_to_list(wd) with allure.step("Кликаю на любую пиктограмму 'Запомнено'"): self.select_random_element(wd) header = self.locator.click_header_button() header[0].click() self.locator.open_left_panel() h1 = "//*[@class='cell']/h1" self.__wait.until_visible_by_xpath_locator(h1) get_h1 = wd.find_element_by_xpath(h1).text link_left = "//*[@id='wishlist_link_left']//span[@class='badge']" self.__wait.until_visible_by_xpath_locator(link_left) badge_left_wishlist = wd.find_element_by_xpath(link_left).text wishlist_link = "//*[@id='wishlist_link']//span" self.__wait.until_visible_by_xpath_locator(wishlist_link) badge_header_wishlist = wd.find_element_by_xpath(wishlist_link).text count = len(wd.find_elements_by_xpath(self.locator.in_table_wishlist)) return get_h1, int(badge_left_wishlist), int(badge_header_wishlist), int(count) # Проверка функции "Запомнено" снять товар def check_remember_disable_item(self, query): wd = self.man.wd self.button.search_goods(wd, query) self.button.click_magnifier(wd) with allure.step("Кликаю на любую пиктограмму 'Запомнено'"): self.select_random_element(wd) header = self.locator.click_header_button() header[0].click() with allure.step("Отключаю все запомненные товары"): all_buttons = wd.find_elements_by_xpath("//*[@class='product-line__link wish_button has-tip']/i") len(all_buttons) for button in all_buttons: button.click() time.sleep(0.3) with allure.step("Кликаю на вкладку 'Товары', чтобы обновить страницу"): wd.find_element_by_xpath("//*[@class='tabs-title desc-tabs__title active']").click() count = len(wd.find_elements_by_xpath(self.locator.in_table_wishlist)) return int(count) def select_random_element(self, wd): try: self.function.click_random_element(wd, "//*[@class='prod__img-buttons']/li[1]") except Exception: self.function.click_random_element(wd, "//*[@class='margin-bottom-6']/a[1]")
class SearchGoods: def __init__(self, man): self.man = man self.button = ButtonsHelper(man) self.function = CommonFunctions() self.__wait = Wait(man) # Поиск товаров/услуг и автокомплит def search_goods_autocomplit_to_rubrics(self, query): wd = self.man.wd self.button.search_goods(wd, query) id3 = "//*[@id='ui-id-3']" self.__wait.until_visible_by_xpath_locator(id3) wd.find_element_by_xpath(id3).click() count = self.function.count_in_result(wd) return int(count) # Поиск товаров/услуг с негативным сценарием - запросы с разными лишнеми символами def search_goods_click_to_button(self, query): wd = self.man.wd self.button.search_goods(wd, query) self.button.click_magnifier(wd) count = self.function.count_in_result(wd) return int(count) def check_tabs_in_main_result(self, query): ''' TODO: загатовка для нового теста, чтобы кликать по табам в карточке компании получать и сверять количество товаров в табах ''' wd = self.man.wd self.button.search_goods(wd, query) self.button.click_magnifier(wd) tabs = wd.find_elements_by_xpath(".//div[@id='ui-tabs-1']/ul//li") for tab in tabs: tab.click() count = self.function.count_in_result(wd) return count
class ShowData: def __init__(self, man): self.man = man self.button = ButtonsHelper(man) self.function = CommonFunctions() # WS-d-016 Проверка телефонов на сайте и в БД в карточке товара # проверка раскрытия телефонов при клике # передаёт id товара, номер телефона для проверки в тест кейс def check_phone_in_goods(self, query_order): wd = self.man.wd self.button.search_goods(wd, query_order) self.button.click_magnifier(wd) time.sleep(2) id_goods = self.click_random_goods(wd) phone = wd.find_element_by_xpath( "//*[@class='seller__info']/a[2]").text return self.function.req_phone(phone), id_goods # клик на любой товар в товарной выдаче не зависимо от позицианирования - списоком или галереей # передаёт id товара def click_random_goods(self, wd): try: elements = wd.find_elements_by_xpath("//*[@id='goods']//h5/a") id_goods = self.random_click(elements) except: elements = wd.find_elements_by_xpath( "//*[@class='prod-container']/div[1]/a[1]") id_goods = self.random_click(elements) return id_goods def random_click(self, elements): random_element = random.choice(elements) href = random_element.get_attribute("href") spl = href.split('/')[-1] random_element.click() return spl
class FunctionComparison: def __init__(self, man): self.man = man self.button = ButtonsHelper(man) self.function = CommonFunctions() self.locator = Locators(man) # Проверка функции "Сравнение" добавить товар def check_comparison_enable_item(self, query): wd = self.man.wd self.button.search_goods(wd, query) self.button.click_enter_keys(wd) time.sleep(2) with allure.step("Кликаю на любую пиктограмму 'Сравнение'"): self.select_random_element(wd) header = self.locator.click_header_button() header[1].click() self.locator.open_left_panel() time.sleep(1) get_h1 = wd.find_element_by_xpath(self.locator.get_h1).text badge_left = wd.find_element_by_xpath("//*[@id='comparelist_link_left']//span[@class='badge']").text return get_h1, int(badge_left) # Проверка функции "Сравнение" снять товары def check_comparison_disable_item(self, query): wd = self.man.wd self.button.search_goods(wd, query) self.button.click_enter_keys(wd) with allure.step("Кликаю на любую пиктограмму 'Сравнение'"): self.select_random_element(wd) header = self.locator.click_header_button() header[1].click() with allure.step("Полностью очищаю список товаров"): wd.find_element_by_id("compare_delete_all").click() is_numeral = self.function.is_element_present(wd, By.XPATH, "//*[@id='comparelist_link']//span[@class='badge']") if is_numeral: return True else: return False def select_random_element(self, wd): try: self.function.click_random_element(wd, "//*[@class='prod__img-buttons']/li[2]") except Exception: self.function.click_random_element(wd, "//*[@class='product-line__link compare_button has-tip']")
def __init__(self, man): self.man = man self.button = ButtonsHelper(man) self.function = CommonFunctions() self.locator = Locators(man)
class FunctonCart: def __init__(self, man): self.man = man self.button = ButtonsHelper(man) self.function = CommonFunctions() self.action = ActionChains self.locator = Locators(man) self.__wait = Wait(man) # Проверка функции "Корзина" def check_goods_cart(self, query): wd = self.man.wd self.button.search_goods(wd, query) self.button.click_magnifier(wd) self.button.go_to_list(wd) with allure.step("Кликаю на любую кнопку 'В корзину'"): self.function.select_card_or_book(wd) self.button.go_to_cart(wd) self.locator.open_left_panel() self.__wait.until_visible_by_xpath_locator(self.locator.get_h1) get_h1 = wd.find_element_by_xpath(self.locator.get_h1).text badge = "//*[@class='off-canvas__user-link cart-icon']//span[@class='badge']" self.__wait.until_visible_by_xpath_locator(badge) badge_left_cart = wd.find_element_by_xpath(badge).text has_tip = "//*[@class='header__buttons-link has-tip']//span" self.__wait.until_visible_by_xpath_locator(has_tip) badge_header_cart = wd.find_element_by_xpath(has_tip).text div_cart = "//*[@class='div_cart']" count = len(wd.find_elements_by_xpath(div_cart)) return get_h1, int(badge_left_cart), int(badge_header_cart), int(count) # Проверка функции "Корзина" снять товар def check_cart_disable_item(self, query): wd = self.man.wd self.button.search_goods(wd, query) self.button.click_magnifier(wd) self.button.go_to_list(wd) with allure.step("Кликаю на любую кнопку 'В корзину'"): self.function.select_card_or_book(wd) try: self.button.go_to_cart(wd) except ElementNotInteractableException: wd.find_element_by_xpath("//*[@id='one-click-order']//span[@aria-hidden='true']").click() all_buttons = wd.find_elements_by_xpath("//*[@class='cart_del_button']") len(all_buttons) for button in all_buttons: button.click() time.sleep(0.3) count = len(wd.find_elements_by_xpath("//*[@class='div_cart']")) return int(count) def check_send_order_from_cart(self, query, data): wd = self.man.wd self.button.search_goods(wd, query) self.button.click_magnifier(wd) title = "//*[@title='Косметика для лица и тела']" self.__wait.until_visible_by_xpath_locator(title) wd.find_element_by_xpath(title).click() self.button.go_to_list(wd) with allure.step("Кликаю на любую кнопку 'В корзину'"): self.function.select_card_or_book(wd) self.button.go_to_cart(wd) margin = "//*[@class='button text-size-default margin-bottom-8']" self.__wait.until_visible_by_xpath_locator(margin) wd.find_element_by_xpath(margin).click() self.fill_form(data, wd) lead = "//*[@class='grid-container']//p[@class='lead']" self.__wait.until_visible_by_xpath_locator(lead) text_message = wd.find_element_by_xpath(lead).text return text_message def fill_order(self, query_order, data): wd = self.man.wd self.button.search_goods(wd, query_order) self.button.click_magnifier(wd) self.button.go_to_list(wd) self.function.select_card_or_book(wd) with allure.step("Заполняю форму тестовыми данными"): self.fill_form(data, wd) # Проверка функции "Оформление заказа" def check_send_order(self, query_order, data): wd = self.man.wd self.fill_order(query_order, data) confirmation = "//*[@id='order-confirmation']//p" self.__wait.until_visible_by_xpath_locator(confirmation) return wd.find_element_by_xpath(confirmation).text def check_send_order_negative(self, query_order, data): wd = self.man.wd self.fill_order(query_order, data) red_error = "//*[@class='red red_error']" self.__wait.until_visible_by_xpath_locator(red_error) return wd.find_element_by_xpath(red_error).text def fill_form(self, data, wd): try: wd.find_element_by_id("one_click_name").send_keys(data.order_name) except ElementNotInteractableException: wd.find_element_by_id("order_name").send_keys(data.order_name) try: wd.find_element_by_id("one_click_email").send_keys(data.order_email) except ElementNotInteractableException: wd.find_element_by_id("order_email").send_keys(data.order_email) try: wd.find_element_by_id("one_click_phone").send_keys(data.order_phone) except ElementNotInteractableException: wd.find_element_by_id("order_phone").send_keys(data.order_phone) try: wd.find_element_by_id("one_click_comment").send_keys(data.commit_window) except ElementNotInteractableException: wd.find_element_by_id("order_comment").send_keys(data.order_comment) try: wd.find_element_by_id("one_click_send").click() except (ElementNotInteractableException, NoSuchElementException): wd.find_element_by_id("order_send").click()
def __init__(self, man): self.man = man self.button = ButtonsHelper(man)
def __init__(self, man): self.man = man self.button = ButtonsHelper(man) self.function = CommonFunctions() self.__wait = Wait(man)
class HelperCompanies: def __init__(self, man): self.man = man self.button = ButtonsHelper(man) self.forms = FormsHelper(man) self.function = CommonFunctions() self.action = ActionChains self.__wait = Wait(man) self.__locator_xxlarge = "//*[@class='text-size-xxlarge']" # WS-d-014 Проверка карточки компании def check_company_card(self, query): wd = self.man.wd self.button.search_goods(wd, query) self.button.click_magnifier(wd) prods = len( wd.find_elements_by_xpath( "//*[@class='grid-x grid-margin-x small-up-1 medium-up-2 large-up-4']/div" )) return int(prods) def check_form_error(self): wd = self.man.wd self.forms.form_error_main() report_error = "//*[@id='report-error']//h2" self.__wait.until_visible_by_xpath_locator(report_error) return wd.find_element_by_xpath(report_error).text def check_form_error_goods(self, query): wd = self.man.wd self.button.search_goods(wd, query) self.button.click_magnifier(wd) self.click_tab_goods(wd) self.forms.form_error_goods() wd.find_element_by_xpath("//*[@class='content']//button").click() invalid = ".is-invalid-label" self.__wait.until_visible_by_css_selector(invalid) label = wd.find_element_by_css_selector(invalid).text return label def check_company_price(self, query): wd = self.man.wd self.button.search_goods(wd, query) self.button.click_magnifier(wd) self.click_tab_goods(wd) self.button.go_to_list(wd) with allure.step('Кликаю Запомнить'): wish_button = "//*[@class='product-line__link wish_button has-tip']" self.__wait.until_visible_by_xpath_locator(wish_button) self.function.click_random_element(wd, wish_button) with allure.step('Кликаю Сравнить'): compare_button = "//*[@class='product-line__link compare_button has-tip']" self.__wait.until_visible_by_xpath_locator(compare_button) self.function.click_random_element(wd, compare_button) numeral_wishlist = "//*[@id='wishlist_link']//span" self.__wait.until_visible_by_xpath_locator(numeral_wishlist) count_wishlist = wd.find_element_by_xpath(numeral_wishlist).text numeral_cart = "//*[@id='comparelist_link']/span" self.__wait.until_visible_by_xpath_locator(numeral_cart) count_cart = wd.find_element_by_xpath(numeral_cart).text return int(count_wishlist), int(count_cart) def click_tab_goods(self, wd): with allure.step('Перехожу по вкладке "Товары и услуги"'): tabs = "//*[@class='desc-tabs tabs']/li[2]" self.__wait.until_visible_by_xpath_locator(tabs) wd.find_element_by_xpath( "//*[@class='desc-tabs tabs']/li[2]").click() def check_search_price(self, query, query_goods): wd = self.man.wd self.button.search_goods(wd, query) self.button.click_magnifier(wd) self.click_tab_goods(wd) wd.find_element_by_xpath( "//*[@class='border-none main-search__input ui-autocomplete-input']" ).send_keys(query_goods) self.button.click_magnifier(wd) margin = wd.find_elements_by_xpath( "//*[@class='margin-vertical-0']//span[@class='ellip']") goods = [g.text[:18] for g in margin] return goods def check_address(self, query): wd = self.man.wd self.button.search_goods(wd, query) self.button.click_magnifier(wd) with allure.step('Кликаю на карте Яндекс, на балун и получаю адрес'): ymaps = "//*[@id='map1']//ymaps[@class='ymaps-2-1-75-svg-icon-content']" element = wd.find_element_by_xpath(ymaps) self.__wait.until_visible_by_xpath_locator(ymaps) self.action(wd).move_to_element(element).click(element).perform() map1 = "//*[@id='map1']//ymaps/h3" self.__wait.until_visible_by_xpath_locator(map1) get_address_in_maps = wd.find_element_by_xpath(map1).text info = "//*[@class='margin-bottom-2 font-info']//tr[1]/td[2]" self.__wait.until_visible_by_xpath_locator(info) get_addess_in_card = wd.find_element_by_xpath(info).text with allure.step( f'Получил адреса и отправил на сверку \'{get_address_in_maps}\' и \'{get_addess_in_card}\'' ): return get_address_in_maps, get_addess_in_card def get_prices_ascending(self, query): wd = self.man.wd self.button.search_goods(wd, query) self.button.click_magnifier(wd) self.click_tab_goods(wd) self.button.go_to_list(wd) with allure.step('Сортирую По возрастанию'): wd.find_element_by_xpath( "//*[@class='padding-2 sort_price_asc']").click() self.__wait.until_visible_by_xpath_locator(self.__locator_xxlarge) elements = wd.find_elements_by_xpath(self.__locator_xxlarge) prices_ascending = [price.text.strip() for price in elements] with allure.step('Передал на проверку отсортированные цены'): return prices_ascending def get_prices_descending(self, query): wd = self.man.wd self.button.search_goods(wd, query) self.button.click_magnifier(wd) self.click_tab_goods(wd) self.button.go_to_list(wd) with allure.step('Сортирую По убыванию'): wd.find_element_by_xpath( "//*[@class='padding-2 sort_price_desc']").click() self.__wait.until_visible_by_xpath_locator(self.__locator_xxlarge) elements = wd.find_elements_by_xpath(self.__locator_xxlarge) prices_descending = [price.text.strip() for price in elements] with allure.step('Передал на проверку отсортированные цены'): return prices_descending