Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
CheckoutTest fails locally.
Steps to reproduce
Tests are failing in HEAD with 8.9.x too, as seen in #3168822: PaymentMethodAddForm needs to implement TrustedCallbackInterface for Drupal 9 and several other tasks.
Locally I can see the failures too. When the test passed last time was with 3e85eaa2 (8.x-2.21), but locally tests still fail as looks like Stripe changed their iframe ids.
Proposed resolution
The problem happens when posting in the cart page for navigating to the checkout. It reloads the cart instead of going to the checkout.
Investigate what changed in commerce that broke these tests.
Remaining tasks
TBD
User interface changes
TBD
API changes
TBD
Data model changes
TBD
Comment | File | Size | Author |
---|---|---|---|
#32 | 3190728-commerce_stripe-fix-checkout-tests-32.patch | 7.34 KB | penyaskito |
Comments
Comment #2
penyaskitoSo the first problem is that
$this->submitForm([], 'Checkout');
reloads the cart, instead of submittingComment #3
penyaskitoI couldn't find why
$this->submitForm([], 'Checkout');
reloads the form instead of redirecting to checkout. This form is constructed by views, and commerce tests themselves usedrupalGet(checkout/1')
, so I think it's out of scope of this issue to find out why. Just changing todrupalGet(checkout/1')
.For the iframes, looks like Stripe changed the ids. As changing those is not reliable if they change them again, let's get them from the html with xpath.
Comment #5
jonathanshawNice, I fixed something similar in #3171898: Fix broken HEAD a while ago.
I think the remaining fails may be because you need to do the same fix in the CheckoutTest::complete3Ds() helper.
+1
Maybe it's worth having a switchToElementFrame() helper:
Comment #6
jonathanshawBroken head is critical for core at least.
Comment #7
penyaskitoI didn't get this to work locally becuase of the nested iframes, but in theory this should work.
Comment #8
jonathanshawNice.
You missed one :(
Comment #9
penyaskitoNice catch, I removed some of my changes before uploading the patch and undid something I shouldn't.
Removed that iframe id, as it's not necessary, it will be the first one in any case.
Comment #12
jonathanshawLooks like this patch ommitted the changes to CheckoutTest::complete3Ds(). Patches are tricky!
Comment #13
penyaskitoLooking at this again. The failures are because "challengeFrame" is not found. It's not found because it's generated on-the-fly by the first iframe, which just includes some js, but I still couldn't figure out how is the frame created or anything. Just waiting it's not working. Loading it outside of anything else doesn't help neither.
it's not enough, as might be pending js executing or loading.
And we cannot rely on
jQuery.active === 0
or alike as there is no jQuery AFAICS in the code by stripe.There's a
window.StripeM
object, but cannot know what we are waiting/looking for.Comment #14
penyaskitoMeh, sometimes you just need to wait in the right moment.
Comment #16
penyaskitoOops, leftover of my previous tests.
Comment #17
penyaskitoProof that the head is broken, as tests only run on commit.
Comment #19
penyaskitoTests passed and failed as expected.
Comment #20
jonathanshawNice. These should be more robust to future changes by Stripe.
Comment #21
jsacksick CreditAttribution: jsacksick at Centarro commentedI made changes to the tests myself locally.
I initially wanted to remove the following changes:
Since it didn't appear to be related to the original issue, but I realized there was no point in navigating to the cart page. Tests are already really slow, so if we can gain several seconds here and there, I think we should.
I also removed the call to
waitForStripe()
since we keep retrying until the iframe is found already.I have a failure locally that I can't really explain, so uploading my patch to see if the issue occurs on drupal.org.
Comment #22
jsacksick CreditAttribution: jsacksick at Centarro commentedI think this was due to me removing the
sleep(1)
inswitchToIframe()
, tests are now passing for me locally... Probably lost quite some time because of this small change :p.Comment #24
penyaskitoThis might pass now.
Comment #26
penyaskitoStill timing out without finding the element.
Comment #28
penyaskitoThis is not waiting enough, probably only running once on the loop.
Comment #29
penyaskitoForget about last one. Restored the waitForStripe method. This is the only way we can get this to green.
Comment #30
longwaveThe changes look good, and the tests are now green which is the main thing!
Comment #31
Jeff Veit CreditAttribution: Jeff Veit commentedD8 is passing.
D9 is failing, sadly, because I'd really like this patch committed so that D8 is passing again: it's holding up testing.
Comment #32
penyaskitoFixed tests. The reason was https://www.drupal.org/node/3056869.
Comment #33
longwaveThanks for fixing that, this change looks correct to me and the tests are green now.
Comment #35
jsacksick CreditAttribution: jsacksick at Centarro commentedCommitted! Thanks for your contribution penyaskito!