How to use Behat/Mink to fill out a test Stripe checkout form?

Viewed 10

I'm trying to test my checkout flow that integrates Drupal 9 with Stripe checkout.

I use Behat for testing Drupal, but I'm having trouble getting it to work on the Stripe checkout page.

An example of the Stripe checkout page I am trying to work with can be accessed by going to the Stripe docs and clicking the Checkout button.

Here's my behat step:

  /**
   * Enter a Stripe Visa credit card.
   *
   * @Then I fill in a valid card on Stripe
   */
  public function fillInCardOnStripe(): void {
    $selector_card_number = 'cardNumber';
    $selector_card_expiry = 'cardExpiry';
    $selector_cvc = 'cardCVC';
    $selector_billing_name = 'billingName';

    $test_card_number = '4242424242424242';
    $test_card_expiry = '11/25';
    $test_cvc = '123';
    $test_billing_name = 'Marcus Aurelius';

    $this->assertEnterField($selector_card_number, $test_card_number);
    $this->assertEnterField($selector_card_expiry, $test_card_expiry);
    $this->assertEnterField($selector_cvc, $test_cvc);
    $this->assertEnterField($selector_billing_name, $test_billing_name);
  }

However, when my test navigates to the Stripe checkout page, I get the following error:

And I fill in a valid card on Stripe                                                                                # DrupalMinkContext::fillInCardOnStripe()
  Form field with id|name|label|value|placeholder "cardNumber" not found.

I don't understand why because when I open the browser dev tools, the name of the Stripe card number input element is cardNumber.

How can I fill out the card number fields on the Stripe checkout page?

0 Answers
Related