From 13d992d0217661d9b5cf57af39ab9553d7593c66 Mon Sep 17 00:00:00 2001 From: ovsyanik-ka Date: Tue, 3 Oct 2017 16:27:19 +0500 Subject: [PATCH] feature(eti): creation product https://jira.railsc.ru/browse/BPC-11223 --- .../company_site/eti/product_creation_spec.rb | 63 +++++++++++++++++++ .../spec/company_site/minieti_spec.rb | 10 +-- .../{mini_eti_page.rb => eti_page.rb} | 51 +++++++++++++-- 3 files changed, 113 insertions(+), 11 deletions(-) create mode 100644 lib/apress/selenium_eti/spec/company_site/eti/product_creation_spec.rb rename lib/pages/company_site/{mini_eti_page.rb => eti_page.rb} (77%) 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 new file mode 100644 index 0000000..98a9a15 --- /dev/null +++ b/lib/apress/selenium_eti/spec/company_site/eti/product_creation_spec.rb @@ -0,0 +1,63 @@ +require 'spec_helper' + +describe 'ЕТИ' do + cs_eti_page = CompanySite::EtiPage.new + cs_main_page = CompanySite::MainPage.new + + before(:all) do + log_in_as(:user) + navigate_to_eti + cs_main_page.close_banner + end + + describe 'Создание товара' do + context 'когда товар без рубрики' do + before(:all) do + @name = Faker::Number.number(5) + cs_eti_page.add_product + cs_eti_page.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 == 'Все изменения сохранены' } + cs_eti_page.search_product(@name) + end + + it 'введенное имя отображается' do + expect(cs_eti_page.product_name?(@name)).to be true + end + + it 'товар не опубликован' do + expect(cs_eti_page.product_unpublished?(@name)).to be true + end + + after(:all) { cs_eti_page.delete_product(@name) } + end + + context 'когда товар с рубрикой' do + before(:all) do + @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.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 == 'Все изменения сохранены' } + cs_eti_page.search_product(@name) + end + + it 'введенное имя отображается' do + expect(cs_eti_page.product_name?(@name)).to be true + end + + it 'рубрика привязана' do + expect(cs_eti_page.product_rubric_tree(@name)).to include CONFIG['eti']['rubric'] + end + + it 'товар опубликован' do + expect(cs_eti_page.product_published?(@name)).to be true + end + + after(:all) { cs_eti_page.delete_product(@name) } + 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 fcc6bcb..dafafff 100644 --- a/lib/apress/selenium_eti/spec/company_site/minieti_spec.rb +++ b/lib/apress/selenium_eti/spec/company_site/minieti_spec.rb @@ -20,7 +20,7 @@ end it 'введенное имя отображается' do - expect(cs_eti_page.product_name).to include @name + expect(cs_eti_page.product_name?(@name)).to be true end context 'когда добавляем картинку' do @@ -101,10 +101,10 @@ end context 'когда заполняем рубрику' do - before(:all) { cs_eti_page.set_rubric(CONFIG['mini_eti']['rubric']) } + before(:all) { cs_eti_page.set_rubric(CONFIG['eti']['rubric']) } it 'привязывается рубрика' do - expect(cs_eti_page.rubric_cell).to include CONFIG['mini_eti']['rubric'] + expect(cs_eti_page.rubric_cell).to include CONFIG['eti']['rubric'] end context 'когда отменяем действие' do @@ -118,7 +118,7 @@ before(:all) { cs_eti_page.operation_redo } it 'привязывается рубрика' do - expect(cs_eti_page.rubric_cell).to include CONFIG['mini_eti']['rubric'] + expect(cs_eti_page.rubric_cell).to include CONFIG['eti']['rubric'] end end end @@ -156,7 +156,7 @@ end it 'товар удаляется' do - expect(cs_eti_page.product_name).not_to eq @name + expect(cs_eti_page.product_name?(@name)).to be false end end diff --git a/lib/pages/company_site/mini_eti_page.rb b/lib/pages/company_site/eti_page.rb similarity index 77% rename from lib/pages/company_site/mini_eti_page.rb rename to lib/pages/company_site/eti_page.rb index 9fdec2e..d8a0ada 100644 --- a/lib/pages/company_site/mini_eti_page.rb +++ b/lib/pages/company_site/eti_page.rb @@ -8,14 +8,13 @@ class EtiPage < Page button(:save, xpath: "//*[contains(text(), 'Подтвердить актуальность')]") span(:progress_bar, css: '#pb') button(:to_catalog, css: '.ml15') - span(:product_name, css: '.js-eti-name > .pt-td-content-wrapper') span(:save_status, css: '.js-status-bar-content') button(:add_products_menu, css: '.sb-label') button(:add_product_manually, css: '.js-add-product') - span(:empty_product_name, xpath: "//*[text()[contains(.,'Указать название')]]") + span(:empty_product_name, xpath: "//*[text()[contains(., 'Указать название')]]") span(:name_cell, xpath: "//*[@data-placeholder='Указать название']") - span(:price_cell, xpath: "//*[contains(text(), 'Указать цену')]") + span(:price_cell, xpath: "//*[contains(text(), 'Указать розничную цену')]") span(:exist_cell, xpath: "//*[contains(text(), 'Указать наличие')]") button(:add_product, css: '.new.js-add-product') text_area(:edit_text_area, css: '.edit-text') @@ -51,7 +50,6 @@ class EtiPage < Page button(:first_rubric_search_result, css: '.src-link') link(:page_2, xpath: "//*[@data-page='2']") link(:page_1, xpath: "//*[@data-page='1']") - button(:delete_product, css: '.js-delete-product') button(:copy_product, css: '.js-copy-product') span(:found_products_count, css: '.js-products-count') radio_button(:from_to, xpath: "(//*[@class = 'va-1 mr5 js-select-type-price'])[2]") @@ -62,6 +60,10 @@ class EtiPage < Page 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") + 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") alias old_confirm confirm def save @@ -70,7 +72,8 @@ def save end def delete - confirm(true) { delete_product } + Page.button(:delete_product_button, css: '.js-delete-product') + confirm(true) { delete_product_button } end def set_rubric(text) @@ -169,6 +172,42 @@ def exists=(is_exist) exists_true if is_exist end - ActiveSupport.run_load_hooks(:'apress/selenium_eti/company_site/mini_eti_page', self) + def product_name?(name) + Page.span(:product_name_span, xpath: "//*[contains(text(), '#{name}')]") + product_name_span? + end + + def product_rubric_tree(name) + Page.span(:rubric_header_span, xpath: + "//td[@data-text='#{name}']/..//span[@class='dashed-span js-rubric-preview-link']") + rubric_header_span_element.text + end + + def product_published?(name) + Page.span(:publish_status_icon, xpath: "//td[@data-text='#{name}']/..//i[contains(@class, 'published')]") + publish_status_icon? + end + + def product_unpublished?(name) + Page.span(:unpublish_status_icon, xpath: "//td[@data-text='#{name}']/..//i[contains(@class, 'unpublished')]") + unpublish_status_icon? + end + + def search_product(name) + self.product_search = name + search_button + end + + def delete_product(name) + search_product(name) + Page.button(:delete_product_icon, xpath: + "//td[@data-text='#{name}']/..//i[contains(@class, 'js-delete-product')]") + + confirm(true) { delete_product_icon } + sleep 0.2 + wait_until { save_status == 'Все изменения сохранены' } + end + + ActiveSupport.run_load_hooks(:'apress/selenium_eti/company_site/eti_page', self) end end