From 028c78fa8c151f42ea488103a63549002445f341 Mon Sep 17 00:00:00 2001 From: Ilya Zhidkov Date: Wed, 11 Oct 2017 14:01:27 +0500 Subject: [PATCH] feature(eti): product status tests https://jira.railsc.ru/browse/BPC-11225 --- .../company_site/eti/product_creation_spec.rb | 4 +- .../company_site/eti/product_statuses_spec.rb | 173 +++++++++++++++ .../spec/company_site/minieti_spec.rb | 52 ++--- lib/pages/company_site/eti_page.rb | 205 +++++++++++------- lib/pages/company_site/mini_eti_page.rb | 11 + 5 files changed, 336 insertions(+), 109 deletions(-) create mode 100644 lib/apress/selenium_eti/spec/company_site/eti/product_statuses_spec.rb create mode 100644 lib/pages/company_site/mini_eti_page.rb diff --git a/lib/apress/selenium_eti/spec/company_site/eti/product_creation_spec.rb b/lib/apress/selenium_eti/spec/company_site/eti/product_creation_spec.rb index 98a9a15..8bbe536 100644 --- a/lib/apress/selenium_eti/spec/company_site/eti/product_creation_spec.rb +++ b/lib/apress/selenium_eti/spec/company_site/eti/product_creation_spec.rb @@ -15,7 +15,7 @@ before(:all) do @name = Faker::Number.number(5) cs_eti_page.add_product - cs_eti_page.name = @name + cs_eti_page.set_name(@name) cs_eti_page.wait_until { cs_eti_page.save_status == 'Все изменения сохранены' } cs_eti_page.refresh cs_eti_page.wait_until { cs_eti_page.save_status == 'Все изменения сохранены' } @@ -38,7 +38,7 @@ @name = Faker::Number.number(5) cs_eti_page.add_product cs_eti_page.set_rubric(CONFIG['eti']['rubric']) - cs_eti_page.name = @name + cs_eti_page.set_name(@name) cs_eti_page.wait_until { cs_eti_page.first_product_status_element.attribute('title') == 'Опубликованные' } cs_eti_page.refresh cs_eti_page.wait_until { cs_eti_page.save_status == 'Все изменения сохранены' } diff --git a/lib/apress/selenium_eti/spec/company_site/eti/product_statuses_spec.rb b/lib/apress/selenium_eti/spec/company_site/eti/product_statuses_spec.rb new file mode 100644 index 0000000..83f0d8e --- /dev/null +++ b/lib/apress/selenium_eti/spec/company_site/eti/product_statuses_spec.rb @@ -0,0 +1,173 @@ +require 'spec_helper' + +describe 'ЕТИ. Редактирование товара. Статусы' do + cs_eti_page = CompanySite::EtiPage.new + cs_main_page = CompanySite::MainPage.new + admin_menu = Admin::Menu.new + admin_products_page = Admin::ProductsPage.new + + before(:all) do + log_in_as(:user) + navigate_to_eti + cs_main_page.close_banner + + @product_1 = { + name: Faker::Name.title, + rubric: CONFIG['eti']['rubric'] + } + + @product_2 = { + name: Faker::Name.title, + rubric: CONFIG['eti']['rubric'] + } + + @product_3 = { + name: Faker::Name.title, + rubric: CONFIG['eti']['rubric'] + } + + @product_4 = { + name: Faker::Name.title, + rubric: CONFIG['eti']['rubric'] + } + + cs_eti_page.create_and_set_product_fields(@product_1) + cs_eti_page.create_and_set_product_fields(@product_2) + cs_eti_page.create_and_set_product_fields(@product_3) + cs_eti_page.create_and_set_product_fields(@product_4) + + navigate_to_admin_page + admin_menu.products + admin_products_page.accept_product(@product_1[:name]) + admin_products_page.accept_product(@product_2[:name]) + admin_products_page.reject_product(@product_3[:name]) + admin_products_page.reject_product(@product_4[:name]) + + navigate_to_eti + log_in_as(:user) + navigate_to_eti + + cs_eti_page.change_status_to_archived(@product_2[:name]) + cs_eti_page.change_status_to_archived(@product_4[:name]) + end + + after(:all) do + navigate_to_eti + cs_eti_page.delete_product(@product_1[:name]) + cs_eti_page.delete_product(@product_2[:name]) + cs_eti_page.delete_product(@product_3[:name]) + cs_eti_page.delete_product(@product_4[:name]) + end + + context 'когда товары подтверждены' do + before(:all) { navigate_to_eti } + + context 'когда исходный статус "Опубликованный"' do + before(:all) { cs_eti_page.search_product(@product_1[:name]) } + + context 'когда меняем статус на архивный' do + before(:all) do + cs_eti_page.change_status_to_archived(@product_1[:name]) + Page.browser.navigate.refresh + end + + it 'статус изменится на архивный' do + expect(cs_eti_page.product_archived?(@product_1[:name])).to be_truthy + end + end + + context 'когда меняем статус с архивного на опубликованный' do + before(:all) do + cs_eti_page.change_status_to_published(@product_1[:name]) + Page.browser.navigate.refresh + end + + it 'статус изменится на опубликованный' do + expect(cs_eti_page.product_published?(@product_1[:name])).to be_truthy + end + end + end + + context 'когда исходный статус "Архивный"' do + before(:all) { cs_eti_page.search_product(@product_2[:name]) } + + context 'когда меняем статус на опубликованный' do + before(:all) do + cs_eti_page.change_status_to_published(@product_2[:name]) + Page.browser.navigate.refresh + end + + it 'статус изменится на опубликованный' do + expect(cs_eti_page.product_published?(@product_2[:name])).to be_truthy + end + end + + context 'когда меняем статус с опубликованного на архивный' do + before(:all) do + cs_eti_page.change_status_to_archived(@product_2[:name]) + Page.browser.navigate.refresh + end + + it 'статус изменится на архивный' do + expect(cs_eti_page.product_archived?(@product_2[:name])).to be_truthy + end + end + end + end + + context 'когда товары отклонены' do + before(:all) { navigate_to_eti } + + context 'когда исходный статус "Отклоненный"' do + before(:all) { cs_eti_page.search_product(@product_3[:name]) } + + context 'когда меняем статус на архивный' do + before(:all) do + cs_eti_page.change_status_to_archived(@product_3[:name]) + Page.browser.navigate.refresh + end + + it 'статус изменится на архивный' do + expect(cs_eti_page.product_archived?(@product_3[:name])).to be_truthy + end + end + + context 'когда меняем статус с архивного на опубликованный' do + before(:all) do + cs_eti_page.change_status_to_published(@product_3[:name]) + Page.browser.navigate.refresh + end + + it 'статус изменится на отклоненный' do + expect(cs_eti_page.product_declined?(@product_3[:name])).to be_truthy + end + end + end + + context 'когда исходный статус "Архивный"' do + before(:all) { cs_eti_page.search_product(@product_4[:name]) } + + context 'когда меняем статус на опубликованный' do + before(:all) do + cs_eti_page.change_status_to_published(@product_4[:name]) + Page.browser.navigate.refresh + end + + it 'статус изменится на отклоненный' do + expect(cs_eti_page.product_declined?(@product_4[:name])).to be_truthy + end + end + + context 'когда меняем статус с отклоненного на архивный' do + before(:all) do + cs_eti_page.change_status_to_archived(@product_4[:name]) + Page.browser.navigate.refresh + end + + it 'статус изменится на архивный' do + expect(cs_eti_page.product_archived?(@product_4[:name])).to be_truthy + end + end + end + end +end diff --git a/lib/apress/selenium_eti/spec/company_site/minieti_spec.rb b/lib/apress/selenium_eti/spec/company_site/minieti_spec.rb index dafafff..27836ba 100644 --- a/lib/apress/selenium_eti/spec/company_site/minieti_spec.rb +++ b/lib/apress/selenium_eti/spec/company_site/minieti_spec.rb @@ -3,6 +3,7 @@ describe 'Мини-ЕТИ' do cs_eti_page = CompanySite::EtiPage.new cs_main_page = CompanySite::MainPage.new + cs_mini_eti_page = CompanySite::MiniEtiPage.new before(:all) do log_in_as(:user) @@ -16,7 +17,7 @@ context 'когда заполняем имя' do before(:all) do @name = Faker::Number.number(5) - cs_eti_page.name = @name + cs_eti_page.set_name(@name) end it 'введенное имя отображается' do @@ -26,7 +27,7 @@ context 'когда добавляем картинку' do before(:all) do @thermometer_value = cs_eti_page.thermometer_value - cs_eti_page.load_image(IMAGE_PATH) + cs_eti_page.set_image(IMAGE_PATH) end it 'картинка появляется' do @@ -34,13 +35,11 @@ end it 'увеличивается градус на термометре' do - cs_eti_page.wait_until { cs_eti_page.save_status == 'Все изменения сохранены' } + cs_eti_page.wait_saving expect(cs_eti_page.thermometer_value).to be @thermometer_value + CONFIG['battery_percents']['image'] end - after(:all) do - cs_eti_page.close_image_uploader - end + after(:all) { cs_eti_page.close_image_uploader } end end @@ -48,7 +47,8 @@ before(:all) do @thermometer_value = cs_eti_page.thermometer_value @price = Faker::Number.number(3) - cs_eti_page.price = @price + + cs_eti_page.set_price(@price) end it 'введенная цена отображается' do @@ -56,7 +56,6 @@ end it 'увеличивается градус на термометре' do - cs_eti_page.wait_until { cs_eti_page.save_status == 'Все изменения сохранены' } expect(cs_eti_page.thermometer_value.to_i).to be @thermometer_value + CONFIG['battery_percents']['price'] end end @@ -64,30 +63,31 @@ context 'когда заполняем цену от и до' do before(:all) do cs_eti_page.add_product + @thermometer_value = cs_eti_page.thermometer_value - @price_from = Faker::Number.number(2) - @price_to = Faker::Number.number(3) - cs_eti_page.set_price_from_to(@price_from, @price_to) + @price_from_to = {from: Faker::Number.number(2), to: Faker::Number.number(3)} + + cs_eti_page.set_price_from_to(@price_from_to) end it 'введенная цена отображается' do - expect(cs_eti_page.price_value).to include @price_from - expect(cs_eti_page.price_value).to include @price_to + expect(cs_eti_page.price_value).to include @price_from_to[:from], @price_from_to[:to] end end context 'когда заполняем цену со скидкой' do before(:all) do cs_eti_page.add_product + @thermometer_value = cs_eti_page.thermometer_value - @price = Faker::Number.number(3) - @discount_price = Faker::Number.number(2) - cs_eti_page.set_discount_price(@price, @discount_price) + @discount_price = {previous: Faker::Number.number(3), discount: Faker::Number.number(2)} + + cs_eti_page.set_discount_price(@discount_price) end it 'введенные цены и дата окончания скидки отображаются' do - expect(cs_eti_page.discount_price_value).to include @discount_price - expect(cs_eti_page.previous_price_value).to include @price + expect(cs_eti_page.discount_price_value).to include @discount_price[:discount] + expect(cs_eti_page.previous_price_value).to include @discount_price[:previous] expect(cs_eti_page.discount_expires_at_date_value).to include Time.now.strftime("%d.%m.%Y") end end @@ -151,8 +151,8 @@ before do cs_eti_page.add_product @name = Faker::Number.number(5) - cs_eti_page.name = @name - cs_eti_page.delete + cs_eti_page.set_name(@name) + cs_mini_eti_page.delete_first_product end it 'товар удаляется' do @@ -163,13 +163,13 @@ describe 'Копирование товара' do before do cs_eti_page.add_product - - cs_eti_page.name = @name = Faker::Pokemon.name - cs_eti_page.price = @price = Faker::Number.number(5) - cs_eti_page.wait_until(45) { cs_eti_page.save_status == 'Все изменения сохранены' } + @name = Faker::Pokemon.name + cs_eti_page.set_name(@name) + cs_eti_page.set_price(@price = Faker::Number.number(5)) + cs_eti_page.wait_saving cs_eti_page.copy_product - cs_eti_page.wait_until(45) { cs_eti_page.save_status == 'Все изменения сохранены' } + cs_eti_page.wait_saving end it 'товар копируется' do @@ -180,7 +180,7 @@ context 'когда выбираем количество товаров на странице' do before do cs_eti_page.choose_amount_of_products_on_page = '50' - cs_eti_page.wait_until { cs_eti_page.save_status == 'Все изменения сохранены' } + cs_eti_page.wait_saving end it 'количество товаров на странице равно выбранному значению' do diff --git a/lib/pages/company_site/eti_page.rb b/lib/pages/company_site/eti_page.rb index d8a0ada..a99f141 100644 --- a/lib/pages/company_site/eti_page.rb +++ b/lib/pages/company_site/eti_page.rb @@ -57,13 +57,15 @@ class EtiPage < Page button(:operation_undo, css: 'div.operation.undo') button(:operation_redo, css: 'div.operation.redo') + button(:publish_product, css: '.dialog-status .published') + button(:archive_product, css: '.dialog-status .archived') select_list(:choose_amount_of_products_on_page, css: '.ptrfap-choose-amount') divs(:product, css: 'tr.pt-tr') - div(:save_status, css: ".js-status-bar-content") + div(:save_status, css: '.js-status-bar-content') text_area(:product_search, xpath: "//*[@id='product-bindings-search']") button(:search_button, css: '.js-search-submit') - span(:first_product_status, css: ".js-eti-status > div > i") + span(:first_product_status, css: '.js-eti-status > div > i') alias old_confirm confirm def save @@ -71,91 +73,107 @@ def save confirm_not_exists?(30) end - def delete - Page.button(:delete_product_button, css: '.js-delete-product') - confirm(true) { delete_product_button } + def wait_saving(delay = 0.1) + # Задержка, так как иначе в wait_until идет предыдущий статус изменений + sleep delay + wait_until { save_status == 'Все изменения сохранены' } end - def set_rubric(text) - browser - .action - .move_to(rubric_cell_element.element) - .click - .perform - - self.rubric_search = text - rubric_search_submit - first_rubric_search_result + module Fields + def create_and_set_product_fields(options = {}) + add_product + options.each do |field_key, field_value| + send("set_#{field_key}", field_value) + end + end + + def set_name(text) + browser + .action + .move_to(name_cell_element.element) + .click + .send_keys(Selenium::WebDriver::Keys::KEYS[:enter]) + .send_keys(text) + .send_keys(Selenium::WebDriver::Keys::KEYS[:enter]) + .perform + + wait_saving + end + + def set_price_from_to(options = {}) + browser + .action + .move_to(price_cell_element.element) + .click + .perform + + select_from_to + self.price_from = options.fetch(:from, '') + self.price_to = options.fetch(:to, '') + + save_price + wait_saving + end + + def set_discount_price(options = {}) + browser + .action + .move_to(price_cell_element.element) + .click + .perform + + select_discount + + self.previous_price = options.fetch(:previous, '') + self.discount_price = options.fetch(:discount, '') + discount_expires_at_date_element.element.send_keys(Selenium::WebDriver::Keys::KEYS[:enter]) + + save_price + wait_saving + end + + def set_price(text) + browser + .action + .move_to(price_cell_element.element) + .click + .send_keys(price_text_area_element.element, text) + .perform + + try_to(:save_price) + wait_saving + end + + def set_rubric(text) + browser + .action + .move_to(rubric_cell_element.element) + .click + .perform + + self.rubric_search = text + rubric_search_submit + wait_until { first_rubric_search_result? } + first_rubric_search_result + + wait_saving + end + + def set_image(path) + image_cell + upload_file(upload_image_element, path) + wait_until { image_loaded? } + # TODO + # добавить закрытие попапа (close_image_uploader) и изменить кейс в mini_eti_spec + end end - def load_image(path) - wait_until { save_status == 'Все изменения сохранены' } - - browser - .action - .move_to(image_cell_element.element) - .click - .perform - - upload_file(upload_image_element, path) - wait_until { image_loaded? } - end + include Fields def thermometer_value thermometer.tr('%', '').to_i end - def name=(text) - browser - .action - .move_to(name_cell_element.element) - .click - .send_keys(Selenium::WebDriver::Keys::KEYS[:enter]) - .send_keys(text) - .send_keys(Selenium::WebDriver::Keys::KEYS[:enter]) - .perform - end - - def set_price_from_to(from, to) - browser - .action - .move_to(price_cell_element.element) - .click - .perform - - select_from_to - self.price_from = from - self.price_to = to - save_price - end - - def set_discount_price(previous_price, discount_price) - browser - .action - .move_to(price_cell_element.element) - .click - .perform - - select_discount - - self.previous_price = previous_price - self.discount_price = discount_price - discount_expires_at_date_element.element.send_keys(Selenium::WebDriver::Keys::KEYS[:enter]) - - save_price - end - - def price=(text) - browser - .action - .move_to(price_cell_element.element) - .click - .send_keys(price_text_area_element.element, text) - .perform - - try_to(:save_price) - end - def price price_cell_element.text end @@ -167,7 +185,7 @@ def exists=(is_exist) .click .perform - wait_until { save_status == 'Все изменения сохранены' } + wait_saving exists_true if is_exist end @@ -193,6 +211,16 @@ def product_unpublished?(name) unpublish_status_icon? end + def product_archived?(name) + Page.span(:archived_status_icon, xpath: "//td[@data-text='#{name}']/..//i[contains(@class, 'archived')]") + archived_status_icon? + end + + def product_declined?(name) + Page.span(:declined_status_icon, xpath: "//td[@data-text='#{name}']/..//i[contains(@class, 'declined')]") + declined_status_icon? + end + def search_product(name) self.product_search = name search_button @@ -204,8 +232,23 @@ def delete_product(name) "//td[@data-text='#{name}']/..//i[contains(@class, 'js-delete-product')]") confirm(true) { delete_product_icon } - sleep 0.2 - wait_until { save_status == 'Все изменения сохранены' } + wait_saving + end + + def change_status_to_published(name) + Page.button(:product_status, xpath: "//*[@data-text='#{name}']/..//*[contains(@class, 'js-change-status')]") + product_status + publish_product + + wait_saving + end + + def change_status_to_archived(name) + Page.button(:product_status, xpath: "//*[@data-text='#{name}']/..//*[contains(@class, 'js-change-status')]") + product_status + archive_product + + wait_saving end ActiveSupport.run_load_hooks(:'apress/selenium_eti/company_site/eti_page', self) diff --git a/lib/pages/company_site/mini_eti_page.rb b/lib/pages/company_site/mini_eti_page.rb new file mode 100644 index 0000000..7b870ca --- /dev/null +++ b/lib/pages/company_site/mini_eti_page.rb @@ -0,0 +1,11 @@ +module CompanySite + class MiniEtiPage < Page + def delete_first_product + Page.button(:delete_product_button, css: '.js-delete-product') + confirm(true) { delete_product_button } + CompanySite::EtiPage.new.wait_saving + end + + ActiveSupport.run_load_hooks(:'apress/selenium_eti/company_site/mini_eti_page', self) + end +end