spree-contrib / better_spree_paypal_express

A better Spree PayPal Express Extension.
http://guides.spreecommerce.org
BSD 3-Clause "New" or "Revised" License
110 stars 270 forks source link

Test Suite Revamp - Cart Checkout flow update & Poltergeist debug #204

Closed fdocr closed 6 years ago

fdocr commented 6 years ago

I took a deeper look into the tests and started removing some of the PENDING: Temporarily skipped with xit. I guess the Spree checkout flow has changed over time, so I added a couple of tweaks.

I'm facing a problem though, I believe the poltergeist driver is not redirecting to PayPal as it should. This first commit includes debug commands (binding.pry & save_and_open_screenshot) so it's easier to catch up on the problem.

I caught the spec execution with binding.pry and manually browsed the server spawned by RSpec that Capybara uses to run the tests (dynamic port assigned on each execution, gotta look it up from the terminal). By doing this I was able to go through the entire process and click the "PayPal Checkout" button in my browser. This means the project works fine, but the tests are not able to validate this.

screen shot 2018-06-09 at 12 01 28 am

The spec fails after the third breakpoint (line 82) on paypal_spec.rb, my comments provide some extra context throughout. It fails because the browser should be in the PayPal checkout page, but the find("#paypal_button").click failed to take us there.

Doing some debugging I can stop the spec on line 78 and figure out the following values:

> find("#paypal_button")['innerHTML']
=> "<img src=\"https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif\">"

> find("#paypal_button")['href']
=> "http://127.0.0.1:62625/paypal?payment_method_id=1"

find("#paypal_button")['data-method']
=> "post"

This means that find("#paypal_button") is indeed the "PayPal Checkout" button and we attempt to click it (line 79), but it does nothing. I see the following output from the terminal though:

screen shot 2018-06-09 at 12 01 47 am

I have no idea why the request was sent to https://api-3t.sandbox.paypal.com/2.0/ as seen on the last screenshot. I also ran out of ideas on how to get Capybara/Poltergeist to head over to the PayPal checkout page. That's why I'm asking for help/suggestions :)

P.S. I'm running that one check inside the spec for speed/comfort using bundle exec rake spec SPEC_OPTS="-e \"pays for an order successfully\"" in case it comes in handy for anyone that might want to try it out.

fdocr commented 6 years ago

A kind fellow from teamcapybara pointed me in the right direction: PayPal increased the minimum TLS version required to connect (v1.2), therefore the need to init the poltergeist driver with a specific flag.

Also added some extra wait times because the PayPal sandbox response times are not great.

fdocr commented 6 years ago

The scope of this PR is complete, the following was achieved:

What’s missing/good things to have (outside the scope of this PR):

bbonislawski commented 6 years ago

Hello @fdoxyz , thanks for your contribution. We're reviewing it at the moment and we definitely want to merge it! We really appreciate your help and we'll get back to you soon

fdocr commented 6 years ago

Hi @bbonislawski, of course let me know of any changes you may consider suitable.

I actually found a tiny fix I can make to the PR. I'll push this after I hear back from you, in case any other changes are requested.

Thank you and the rest of the Spree team for everything, glad to help.