From e350e2065b22b409a573601fe6ff24c3533817d6 Mon Sep 17 00:00:00 2001 From: Fernando Valverde Arredondo Date: Sat, 9 Jun 2018 00:21:08 -0600 Subject: [PATCH 1/3] Cart Checkout cleanup & poltergeist debug [skip ci] --- spec/features/paypal_spec.rb | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/spec/features/paypal_spec.rb b/spec/features/paypal_spec.rb index cccbd2f5..f0fbeafd 100644 --- a/spec/features/paypal_spec.rb +++ b/spec/features/paypal_spec.rb @@ -28,7 +28,9 @@ 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 + within("#loginSection") do + click_button 'Log In' + end end end @@ -54,21 +56,30 @@ def add_to_cart(product) end def fill_in_guest - within("#guest_checkout") do - fill_in "Email", with: "test@example.com" - click_button 'Continue' - end + fill_in :order_email, with: 'test@example.com' end - xit "pays for an order successfully" do + it "pays for an order successfully" do add_to_cart(product) click_button 'Checkout' fill_in_guest fill_in_billing + + # Filled the Address Forms + save_and_open_screenshot + binding.pry click_button "Save and Continue" + # Delivery step doesn't require any action click_button "Save and Continue" + + # Reached the Payment step in the Checkout flow + save_and_open_screenshot + binding.pry find("#paypal_button").click + + save_and_open_screenshot + binding.pry # Stuck in the previous step. The click didn't redirect properly switch_to_paypal_login login_to_paypal click_button "Pay Now" From 1774fcf2ff55179ded8b49db2e17aaa305e11df8 Mon Sep 17 00:00:00 2001 From: Fernando Valverde Arredondo Date: Sun, 10 Jun 2018 22:43:20 -0600 Subject: [PATCH 2/3] Force PhantomJS to use TLSv1.2 & adds max wait times --- spec/features/paypal_spec.rb | 29 +++++++++-------------------- spec/support/capybara.rb | 2 +- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/spec/features/paypal_spec.rb b/spec/features/paypal_spec.rb index f0fbeafd..8f0ac693 100644 --- a/spec/features/paypal_spec.rb +++ b/spec/features/paypal_spec.rb @@ -28,17 +28,17 @@ 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") - within("#loginSection") do - click_button 'Log In' + within("#loginSection", wait: 10) do + click_link 'Log In' end end end def login_to_paypal - within("#loginForm") do - fill_in "Email", with: "pp@spreecommerce.com" - fill_in "Password", with: "thequickbrownfox" - click_button "Log in to PayPal" + within("#login form", wait: 10) do + fill_in "Email", with: "pp@spreecommerce.com" + fill_in "Password", with: "thequickbrownfox" + click_button "Log In" end end @@ -64,26 +64,15 @@ def fill_in_guest click_button 'Checkout' fill_in_guest fill_in_billing - - # Filled the Address Forms - save_and_open_screenshot - binding.pry click_button "Save and Continue" - # Delivery step doesn't require any action click_button "Save and Continue" - - # Reached the Payment step in the Checkout flow - save_and_open_screenshot - binding.pry find("#paypal_button").click - - save_and_open_screenshot - binding.pry # Stuck in the previous step. The click didn't redirect properly switch_to_paypal_login login_to_paypal - click_button "Pay Now" - page.should have_content("Your order has been processed successfully") + + click_button "Pay Now", wait: 15 # allow longer max wait because of PayPal sandbox speed + page.should have_content("Your order has been processed successfully", wait: 15) Spree::Payment.last.source.transaction_id.should_not be_blank end diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 146a5607..56965137 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -7,6 +7,6 @@ Capybara.javascript_driver = :poltergeist Capybara.register_driver(:poltergeist) do |app| - Capybara::Poltergeist::Driver.new app, js_errors: true, timeout: 60 + Capybara::Poltergeist::Driver.new app, js_errors: true, timeout: 60, phantomjs_options: ['--ssl-protocol=TLSv1.2'] end end From ef31ca82ffbc30b85dc685be92e944d76f6ce8ca Mon Sep 17 00:00:00 2001 From: Fernando Valverde Arredondo Date: Fri, 15 Jun 2018 10:51:15 -0600 Subject: [PATCH 3/3] travis.yml revamp and passing tests --- .travis.yml | 31 ++++-- Appraisals | 17 ++++ gemfiles/spree_3_1.gemfile | 2 + gemfiles/spree_3_4.gemfile | 8 ++ gemfiles/spree_3_5.gemfile | 8 ++ gemfiles/spree_3_6.gemfile | 8 ++ spec/features/paypal_spec.rb | 180 +++++++++++++++++++---------------- spec/support/capybara.rb | 2 +- 8 files changed, 168 insertions(+), 88 deletions(-) create mode 100644 gemfiles/spree_3_4.gemfile create mode 100644 gemfiles/spree_3_5.gemfile create mode 100644 gemfiles/spree_3_6.gemfile diff --git a/.travis.yml b/.travis.yml index 3fdd8d04..7346d4f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,26 +1,45 @@ sudo: required dist: trusty -before_script: "bundle install" +language: ruby + script: - bundle exec rake test_app - - bundle exec rake spec + - travis_retry bundle exec rake spec env: - DB=mysql - DB=postgres -language: ruby - rvm: - - 2.3.1 - - 2.2.7 + - 2.2.10 + - 2.3.7 + - 2.4.4 + - 2.5.1 gemfile: - gemfiles/spree_3_1.gemfile - gemfiles/spree_3_2.gemfile - gemfiles/spree_3_3.gemfile + - gemfiles/spree_3_4.gemfile + - gemfiles/spree_3_5.gemfile + - gemfiles/spree_3_6.gemfile - gemfiles/spree_master.gemfile before_install: - mysql -u root -e "GRANT ALL ON *.* TO 'travis'@'%';" + +matrix: + exclude: + - rvm: 2.5.1 + gemfile: gemfiles/spree_3_1.gemfile + - rvm: 2.5.1 + gemfile: gemfiles/spree_3_2.gemfile + - rvm: 2.5.1 + gemfile: gemfiles/spree_3_3.gemfile + - rvm: 2.5.1 + gemfile: gemfiles/spree_3_4.gemfile + - rvm: 2.5.1 + gemfile: gemfiles/spree_3_5.gemfile + allow_failures: + - gemfile: gemfiles/spree_master.gemfile diff --git a/Appraisals b/Appraisals index d5e500aa..127f5141 100644 --- a/Appraisals +++ b/Appraisals @@ -1,5 +1,7 @@ appraise 'spree-3-1' do gem 'spree', '~> 3.1.0' + gem 'activerecord', '~> 4.2.10' + gem 'mysql2', '~> 0.4.10' gem 'rails_test_params_backport', group: :test end @@ -13,6 +15,21 @@ appraise 'spree-3-3' do gem 'rails-controller-testing' end +appraise 'spree-3-4' do + gem 'spree', '~> 3.4.0' + gem 'rails-controller-testing' +end + +appraise 'spree-3-5' do + gem 'spree', '~> 3.5.0' + gem 'rails-controller-testing' +end + +appraise 'spree-3-6' do + gem 'spree', '~> 3.6.0' + gem 'rails-controller-testing' +end + appraise 'spree-master' do gem 'spree', github: 'spree/spree', branch: 'master' gem 'rails-controller-testing' diff --git a/gemfiles/spree_3_1.gemfile b/gemfiles/spree_3_1.gemfile index b9481858..630c6790 100644 --- a/gemfiles/spree_3_1.gemfile +++ b/gemfiles/spree_3_1.gemfile @@ -3,6 +3,8 @@ source "https://rubygems.org" gem "spree", "~> 3.1.0" +gem "activerecord", "~> 4.2.10" +gem "mysql2", "~> 0.4.10" gem "rails_test_params_backport", group: :test gemspec path: "../" diff --git a/gemfiles/spree_3_4.gemfile b/gemfiles/spree_3_4.gemfile new file mode 100644 index 00000000..a20714b8 --- /dev/null +++ b/gemfiles/spree_3_4.gemfile @@ -0,0 +1,8 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "spree", "~> 3.4.0" +gem "rails-controller-testing" + +gemspec path: "../" diff --git a/gemfiles/spree_3_5.gemfile b/gemfiles/spree_3_5.gemfile new file mode 100644 index 00000000..823705d5 --- /dev/null +++ b/gemfiles/spree_3_5.gemfile @@ -0,0 +1,8 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "spree", "~> 3.5.0" +gem "rails-controller-testing" + +gemspec path: "../" diff --git a/gemfiles/spree_3_6.gemfile b/gemfiles/spree_3_6.gemfile new file mode 100644 index 00000000..727196c7 --- /dev/null +++ b/gemfiles/spree_3_6.gemfile @@ -0,0 +1,8 @@ +# This file was generated by Appraisal + +source "https://rubygems.org" + +gem "spree", "~> 3.6.0" +gem "rails-controller-testing" + +gemspec path: "../" diff --git a/spec/features/paypal_spec.rb b/spec/features/paypal_spec.rb index 8f0ac693..7461b789 100644 --- a/spec/features/paypal_spec.rb +++ b/spec/features/paypal_spec.rb @@ -1,5 +1,8 @@ describe "PayPal", js: true do let!(:product) { FactoryBot.create(:product, name: 'iPad') } + let!(:long_max_wait) { 180 } + let!(:medium_max_wait) { 30 } + let!(:forced_sleep) { 15 } before do @gateway = Spree::Gateway::PayPalExpress.create!({ @@ -28,14 +31,14 @@ 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") - within("#loginSection", wait: 10) do + within("#loginSection", wait: medium_max_wait) do click_link 'Log In' end end end def login_to_paypal - within("#login form", wait: 10) do + within("#login form", wait: medium_max_wait) do fill_in "Email", with: "pp@spreecommerce.com" fill_in "Password", with: "thequickbrownfox" click_button "Log In" @@ -43,8 +46,8 @@ def login_to_paypal end def within_transaction_cart(&block) - find(".transactionDetails").click - within(".transctionCartDetails") { block.call } + find(".transactionDetails").trigger('click') + within(".transctionCartDetails", wait: medium_max_wait) { block.call } end def add_to_cart(product) @@ -59,6 +62,13 @@ def fill_in_guest fill_in :order_email, with: 'test@example.com' end + def click_pay_button + # The pay button in the PayPal sandbox is troublesome: Wrap it around sleeps + sleep(forced_sleep) + click_button "Pay Now", wait: long_max_wait + sleep(forced_sleep) + end + it "pays for an order successfully" do add_to_cart(product) click_button 'Checkout' @@ -67,13 +77,12 @@ def fill_in_guest click_button "Save and Continue" # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + find("#paypal_button", wait: medium_max_wait).click + switch_to_paypal_login login_to_paypal - - click_button "Pay Now", wait: 15 # allow longer max wait because of PayPal sandbox speed - page.should have_content("Your order has been processed successfully", wait: 15) - + click_pay_button + page.should have_content("Your order has been processed successfully", wait: long_max_wait) Spree::Payment.last.source.transaction_id.should_not be_blank end @@ -82,64 +91,67 @@ def fill_in_guest @gateway.preferred_solution = 'Sole' end - xit "passes user details to PayPal" do + it "passes user details to PayPal" do add_to_cart(product) click_button 'Checkout' - within("#guest_checkout") do - fill_in "Email", with: "test@example.com" - click_button 'Continue' - end + fill_in_guest fill_in_billing click_button "Save and Continue" # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + find("#paypal_button", wait: medium_max_wait).click + switch_to_paypal_login login_to_paypal - click_button "Pay Now" - - page.should have_selector '[data-hook=order-bill-address] .fn', text: 'Test User' - page.should have_selector '[data-hook=order-bill-address] .adr', text: '1 User Lane' - page.should have_selector '[data-hook=order-bill-address] .adr', text: 'Adamsville AL 35005' - page.should have_selector '[data-hook=order-bill-address] .adr', text: 'United States' - page.should have_selector '[data-hook=order-bill-address] .tel', text: '555-123-4567' + click_pay_button + within("#order_summary", wait: long_max_wait) do + page.should have_selector '[data-hook=order-bill-address] .fn', text: 'Test User' + page.should have_selector '[data-hook=order-bill-address] .adr', text: '1 User Lane' + page.should have_selector '[data-hook=order-bill-address] .adr .local .locality', text: 'Adamsville' + page.should have_selector '[data-hook=order-bill-address] .adr .local .postal-code', text: '35005' + page.should have_selector '[data-hook=order-bill-address] .tel', text: '555-123-4567' + end end end - xit "includes adjustments in PayPal summary" do + it "includes adjustments in PayPal summary" do add_to_cart(product) # TODO: Is there a better way to find this current order? order = Spree::Order.last - order.adjustments.create!(amount: -5, label: "$5 off") - order.adjustments.create!(amount: 10, label: "$10 on") + Spree::Adjustment.create!(label: "$5 off", adjustable: order, order: order, amount: -5) + Spree::Adjustment.create!(label: "$10 on", adjustable: order, order: order, amount: 10) visit '/cart' within("#cart_adjustments") do page.should have_content("$5 off") page.should have_content("$10 on") end + click_button 'Checkout' fill_in_guest fill_in_billing click_button "Save and Continue" # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click - - within_transaction_cart do - page.should have_content("$5 off") - page.should have_content("$10 on") + find("#paypal_button", wait: medium_max_wait).click + within('.cartContainer', wait: long_max_wait) do + within_transaction_cart do + page.should have_content("$5 off") + page.should have_content("$10 on") + end end + find('#closeCart').trigger('click') # Hide cart overlay so the click isn't blocked by it + switch_to_paypal_login login_to_paypal - - within_transaction_cart do - page.should have_content("$5 off") - page.should have_content("$10 on") + within('.cartContainer', wait: long_max_wait) do + within_transaction_cart do + page.should have_content("$5 off") + page.should have_content("$10 on") + end end - click_button "Pay Now" - - within("[data-hook=order_details_adjustments]") do + click_pay_button + within("[data-hook=order_details_adjustments]", wait: long_max_wait) do page.should have_content("$5 off") page.should have_content("$10 on") end @@ -153,7 +165,7 @@ def fill_in_guest promotion.actions << action end - xit "includes line item adjustments in PayPal summary" do + it "includes line item adjustments in PayPal summary" do add_to_cart(product) # TODO: Is there a better way to find this current order? order = Spree::Order.last @@ -163,25 +175,26 @@ def fill_in_guest within("#cart_adjustments") do page.should have_content("10% off") end + click_button 'Checkout' - within("#guest_checkout") do - fill_in "Email", with: "test@example.com" - click_button 'Continue' - end + fill_in_guest fill_in_billing click_button "Save and Continue" # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click - - within_transaction_cart do - page.should have_content("10% off") + find("#paypal_button", wait: medium_max_wait).click + within('.cartContainer', wait: long_max_wait) do + within_transaction_cart do + page.should have_content("10% off") + end end + find('#closeCart').trigger('click') # Hide cart overlay so the click isn't blocked by it + switch_to_paypal_login login_to_paypal - click_button "Pay Now" - within("[data-hook=order_details_price_adjustments]") do + click_pay_button + within("[data-hook=order_details_price_adjustments]", wait: long_max_wait) do page.should have_content("10% off") end end @@ -194,36 +207,35 @@ def fill_in_guest xit do add_to_cart(product) add_to_cart(product2) - # TODO: Is there a better way to find this current order? - order = Spree::Order.last + script_content = page.all('body script', visible: false).last['innerHTML'] + order_id = script_content.strip.split("\"")[1] + order = Spree::Order.find_by(number: order_id) order.line_items.last.update_attribute(:price, 0) click_button 'Checkout' - within("#guest_checkout") do - fill_in "Email", with: "test@example.com" - click_button 'Continue' - end + fill_in_guest fill_in_billing click_button "Save and Continue" # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click - - within_transaction_cart do - page.should have_content('iPad') - page.should_not have_content('iPod') + find("#paypal_button", wait: medium_max_wait).click + within('.cartContainer', wait: long_max_wait) do + within_transaction_cart do + page.should have_content('iPad') + page.should_not have_content('iPod') + end end + find('#closeCart').trigger('click') # Hide cart overlay so the click isn't blocked by it + switch_to_paypal_login login_to_paypal - within_transaction_cart do page.should have_content('iPad') page.should_not have_content('iPod') end - click_button "Pay Now" - - within("#line-items") do + click_pay_button + within("#line-items", wait: long_max_wait) do page.should have_content('iPad') page.should have_content('iPod') end @@ -242,23 +254,21 @@ def fill_in_guest add_to_cart(product) # TODO: Is there a better way to find this current order? order = Spree::Order.last - order.adjustments.create!(amount: -order.line_items.last.price, label: "FREE iPad ZOMG!") + Spree::Adjustment.create!(label: "FREE iPad ZOMG!", adjustable: order, order: order, amount: -order.line_items.last.price) click_button 'Checkout' - within("#guest_checkout") do - fill_in "Email", with: "test@example.com" - click_button 'Continue' - end + fill_in_guest fill_in_billing click_button "Save and Continue" # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + find("#paypal_button", wait: medium_max_wait).click + # find('#closeCart').trigger('click') # Hide cart overlay so the click isn't blocked by it + switch_to_paypal_login login_to_paypal - click_button "Pay Now" - - within("[data-hook=order_details_adjustments]") do + click_pay_button + within("[data-hook=order_details_adjustments]", wait: long_max_wait) do page.should have_content('FREE iPad ZOMG!') end end @@ -278,7 +288,7 @@ def fill_in_guest click_button "Save and Continue" # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + find("#paypal_button", wait: medium_max_wait).click page.should have_content("PayPal failed. Security header is not valid") end end @@ -297,7 +307,7 @@ def fill_in_guest Spree::Zone.first.update_attribute(:default_tax, true) end - xit do + it do add_to_cart(product3) visit '/cart' @@ -309,17 +319,25 @@ def fill_in_guest fill_in_guest fill_in_billing click_button "Save and Continue" + # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + find("#paypal_button", wait: medium_max_wait).click - within_transaction_cart do - # included taxes should not go on paypal - page.should_not have_content(tax_string) + within('.cartContainer', wait: long_max_wait) do + within_transaction_cart do + # included taxes should not go on paypal + page.should_not have_content(tax_string) + end end + find('#closeCart').trigger('click') # Hide cart overlay so the click isn't blocked by it + switch_to_paypal_login login_to_paypal - click_button "Pay Now" - page.should have_content("Your order has been processed successfully") + + sleep(forced_sleep) + click_button "Pay Now", wait: long_max_wait + sleep(forced_sleep) + page.should have_content("Your order has been processed successfully", wait: long_max_wait) end end @@ -341,7 +359,7 @@ def fill_in_guest click_button "Save and Continue" # Delivery step doesn't require any action click_button "Save and Continue" - find("#paypal_button").click + find("#paypal_button", wait: medium_max_wait).click switch_to_paypal_login login_to_paypal click_button("Pay Now") diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb index 56965137..d400d70c 100644 --- a/spec/support/capybara.rb +++ b/spec/support/capybara.rb @@ -7,6 +7,6 @@ Capybara.javascript_driver = :poltergeist Capybara.register_driver(:poltergeist) do |app| - Capybara::Poltergeist::Driver.new app, js_errors: true, timeout: 60, phantomjs_options: ['--ssl-protocol=TLSv1.2'] + Capybara::Poltergeist::Driver.new app, js_errors: true, timeout: 180, phantomjs_options: ['--ssl-protocol=TLSv1.2'] end end