|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: How to fill Stripe payment with Codeception |
| 4 | +date: 2025-05-01 20:16:57 |
| 5 | +excerpt: How to fill Stripe payment with Codeception WebDriver. |
| 6 | +categories: stripe codeception webdriver selenium php |
| 7 | +--- |
| 8 | + |
| 9 | +This post goes over how to fill [Stripe payment](https://stripe-payments-demo.appspot.com/) with [Codeception WebDriver](https://codeception.com/docs/modules/WebDriver). |
| 10 | + |
| 11 | +## Bootstrap |
| 12 | + |
| 13 | +Follow the [quickstart](https://codeception.com/quickstart) to bootstrap Codeception. |
| 14 | + |
| 15 | +## Before |
| 16 | + |
| 17 | +In the `_before`, open the [Stripe page](https://stripe-payments-demo.appspot.com/) and switch to the Stripe iframe: |
| 18 | + |
| 19 | +```php |
| 20 | +public function _before(AcceptanceTester $I): void |
| 21 | +{ |
| 22 | + $I->amOnPage('/'); |
| 23 | + $iframe = 'iframe[title="Secure card payment input frame"]'; |
| 24 | + $I->waitForElement($iframe); |
| 25 | + $I->scrollTo($iframe); |
| 26 | + $I->switchToIFrame($iframe); |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +The `scrollTo` isn't necessary but helps with troubleshooting the test. |
| 31 | + |
| 32 | +## Card |
| 33 | + |
| 34 | +Fill the the card number: |
| 35 | + |
| 36 | +```php |
| 37 | +$I->fillField('input[placeholder="Card number"]', '4242424242424242'); |
| 38 | +``` |
| 39 | + |
| 40 | +You can also use the selectors: |
| 41 | + |
| 42 | +- `input[name="cardnumber"]` |
| 43 | +- `input[aria-label="Credit or debit card number"]` |
| 44 | + |
| 45 | +## Expiration |
| 46 | + |
| 47 | +Fill the expiration date: |
| 48 | + |
| 49 | +```php |
| 50 | +$I->fillField('input[placeholder="MM / YY"]', '1234'); |
| 51 | +``` |
| 52 | + |
| 53 | +You can also use the selectors: |
| 54 | + |
| 55 | +- `input[name="exp-date"]` |
| 56 | +- `input[aria-label="Credit or debit card expiration date"]` |
| 57 | + |
| 58 | +Alternatively, you can type the value: |
| 59 | + |
| 60 | +```php |
| 61 | +$I->type('1234'); |
| 62 | +``` |
| 63 | + |
| 64 | +## CVC |
| 65 | + |
| 66 | +Fill the expiration CVC: |
| 67 | + |
| 68 | +```php |
| 69 | +$I->fillField('input[placeholder="CVC"]', '123'); |
| 70 | +``` |
| 71 | + |
| 72 | +You can also use the following selectors: |
| 73 | + |
| 74 | +- `input[name="cvc"]` |
| 75 | +- `input[aria-label="Credit or debit card CVC/CVV"]` |
| 76 | + |
| 77 | +```php |
| 78 | +$I->type('123'); |
| 79 | +``` |
| 80 | + |
| 81 | +Alternatively, you can type the value: |
| 82 | + |
| 83 | +```php |
| 84 | +$I->type('123'); |
| 85 | +``` |
| 86 | + |
| 87 | +## After |
| 88 | + |
| 89 | +Don't forget to switch back to the parent page after you're done: |
| 90 | + |
| 91 | +```php |
| 92 | +$I->switchToIFrame(); |
| 93 | +``` |
0 commit comments