From 109cdd2a9a159a47f8db4948b04c353af58b6b0c Mon Sep 17 00:00:00 2001 From: Taku Nakajima Date: Tue, 28 Nov 2017 17:20:49 +0900 Subject: [PATCH] Fix feature spec --- Gemfile | 2 + Versionfile | 2 + spec/features/paypal_spec.rb | 71 ++++++++++++++++++++++++++++-------- spec/spec_helper.rb | 2 +- 4 files changed, 60 insertions(+), 17 deletions(-) create mode 100644 Versionfile diff --git a/Gemfile b/Gemfile index e3b6cc4d..54d0b9c1 100644 --- a/Gemfile +++ b/Gemfile @@ -6,6 +6,8 @@ gem 'sqlite3' gem 'pg' gem 'database_cleaner', '1.0.1' +gem 'rake', '10.1.0' + group :test do gem 'yarjuf' gem 'require_all' diff --git a/Versionfile b/Versionfile new file mode 100644 index 00000000..68d10823 --- /dev/null +++ b/Versionfile @@ -0,0 +1,2 @@ +# This file is needed to make `rake test_app` generates propper path for Gemfile +# See https://github.com/degica/liquidus/blob/master/core/lib/generators/spree/dummy/dummy_generator.rb#L99 diff --git a/spec/features/paypal_spec.rb b/spec/features/paypal_spec.rb index 78787794..f6c6fc86 100644 --- a/spec/features/paypal_spec.rb +++ b/spec/features/paypal_spec.rb @@ -35,10 +35,54 @@ def fill_in_billing def switch_to_paypal_login # If you go through a payment once in the sandbox, it remembers your preferred setting. # It defaults to the *wrong* setting for the first time, so we need to have this method. - unless page.has_selector?("#login_email") - find("#loadLogin").click + sleep 3 + if page.has_selector?(".baslLoginButtonContainer a") + login_button = find(".baslLoginButtonContainer a") + sleep 3 # wait for click handler ready + login_button.click end end + + def pay_with_paypal_account + if page.has_selector?("#injectedUnifiedLogin iframe") + frame = find("#injectedUnifiedLogin iframe") + sleep 3 # wait for the frame contents ready + within_frame(frame) do + fill_in "login_email", :with => "pp@spreecommerce.com" + fill_in "login_password", :with => "thequickbrownfox" + sleep 5 + click_button "Log In" + end + end + sleep 3 + find('#button.reviewButton', wait: 120) # wait for the next button appears + sleep 5 # wait for click handler ready + click_button "Pay Now" + end + + def confirm_success + find('.flash.notice', wait: 60) + page.should have_content("Your order has been processed successfully", wait: 60) + end + + def check_minicart(&block) + minicart = find('#transactionCart', wait: 60) + sleep 3 # wait for dropdown ready + if minicart.has_selector?('.arrow', wait: 10) + sleep 5 # wait for click handler ready + find('.arrow').click # show the details + sleep 3 # wait for dropdown items shown + find('.detail-items', wait: 60) # wait for the dropdown appears + within(find('.detail-items')) do + block.call + end + else + within(minicart) do + block.call + end + end + end + it "pays for an order successfully" do visit spree.root_path click_link 'iPad' @@ -54,11 +98,8 @@ def switch_to_paypal_login click_button "Save and Continue" find("#paypal_button").click switch_to_paypal_login - fill_in "login_email", :with => "pp@spreecommerce.com" - fill_in "login_password", :with => "thequickbrownfox" - click_button "Log In" - find("#continue_abovefold").click # Because there's TWO continue buttons. - page.should have_content("Your order has been processed successfully") + pay_with_paypal_account + confirm_success Spree::Payment.last.source.transaction_id.should_not be_blank end @@ -86,7 +127,8 @@ def switch_to_paypal_login # Delivery step doesn't require any action click_button "Save and Continue" find("#paypal_button").click - within("#miniCart") do + + check_minicart do page.should have_content("$5 off") page.should have_content("$10 on") end @@ -118,7 +160,7 @@ def switch_to_paypal_login # Delivery step doesn't require any action click_button "Save and Continue" find("#paypal_button").click - within("#miniCart") do + check_minicart do page.should have_content('iPad') page.should_not have_content('iPod') end @@ -150,8 +192,8 @@ def switch_to_paypal_login # Delivery step doesn't require any action click_button "Save and Continue" find("#paypal_button").click - within("#miniCart") do - page.should have_content('Current purchase') + check_minicart do + page.should have_content('$10.00 USD') end end end @@ -199,11 +241,8 @@ def switch_to_paypal_login click_button "Save and Continue" find("#paypal_button").click switch_to_paypal_login - fill_in "login_email", :with => "pp@spreecommerce.com" - fill_in "login_password", :with => "thequickbrownfox" - click_button "Log In" - find("#continue_abovefold").click # Because there's TWO continue buttons. - page.should have_content("Your order has been processed successfully") + pay_with_paypal_account + confirm_success visit '/admin' click_link Spree::Order.last.number diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b37d4cd5..2c4910d8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -32,7 +32,7 @@ # require 'capybara/poltergeist' # Capybara.javascript_driver = :poltergeist -Capybara.default_wait_time = 15 +Capybara.default_max_wait_time = 15 Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }