Dusk: Type value is wrong in iframe inputs

Created on 2 Oct 2018  路  4Comments  路  Source: laravel/dusk

In one of my Dusk tests I'm testing a Stripe elements form. When I switch to the iframe for the card number it 9 times out of 10 inputs the number incorrectly. If I use a non iframe input everything works fine.

A sample of my test:

/** @test */
public function it_can_save_a_card()
{
  $this->browse(function ($browser) {
    $browser->loginAs($this->user)
      ->visit('/account/business/billing')
      ->type('name', 'Mr Test User')
      ->type('noniframecardnumber', '4242424242424242');

    $browser->click('#stripe-card-number');
    $browser->waitFor('#stripe-card-number iframe', 15);
    $browser->driver->switchTo()->frame($browser->script('return $("#stripe-card-number iframe").attr("name");')[0]);
    $browser->type('cardnumber', '4242424242424242');

    $browser->driver->switchTo()->defaultContent();
  });
}

The failure screenshot (I included a standard input at the bottom):

failure-it_can_save_a_card-0

Any ideas why this might be happening?

Thanks.

Most helpful comment

Could be a timing issue, maybe Dusk is typing too fast.

Try a pause after each character:

foreach (str_split('4242424242424242') as $char) {
    $browser->append('cardnumber', $char)->pause(100);
}

All 4 comments

Does the Stripe iframe have any JavaScript?

Yea the Stripe Elements drop in is pretty Javascript heavy. For example, it validates credit card numbers on the fly and also formats the output with spaces and such.

I forgot to mention, this test is pretty old and has always worked fine until recently. That said I understand something could have changed within Stripe just as much as it could have Dusk.

Could be a timing issue, maybe Dusk is typing too fast.

Try a pause after each character:

foreach (str_split('4242424242424242') as $char) {
    $browser->append('cardnumber', $char)->pause(100);
}

That got it. Thanks so much.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

subathanikaikumaran picture subathanikaikumaran  路  3Comments

godruoyi picture godruoyi  路  6Comments

ahtinurme picture ahtinurme  路  6Comments

dmitryuk picture dmitryuk  路  5Comments

antonioribeiro picture antonioribeiro  路  5Comments