Created
January 16, 2019 06:13
-
-
Save keithbrink/a265e059e6a4cbc5aef4c8993d7b1fb8 to your computer and use it in GitHub Desktop.
Run a Dusk Test on Laravel Spark 7 Subscribe Form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests\Browser; | |
use Tests\DuskTestCase; | |
use Laravel\Dusk\Browser; | |
use Illuminate\Foundation\Testing\WithFaker; | |
class SubscriptionsTest extends DuskTestCase | |
{ | |
use WithFaker; | |
/** | |
* A basic browser test example. | |
* | |
* @return void | |
*/ | |
public function testSubscribe() | |
{ | |
$this->browse(function (Browser $browser) { | |
$browser->loginAs($this->customer_user) | |
->visit('/settings') | |
->click('a[href="#subscription"]') | |
->click('#subscription .radio-select:nth-child(1)') | |
->assertSee('Billing Information') | |
->type('@subscribeNameInput', $this->faker->name) | |
->type('@addressInput', $this->faker->streetAddress) | |
->type('@address2Input', $this->faker->secondaryAddress) | |
->type('@cityInput', $this->faker->city) | |
->type('@stateInput', $this->faker->stateAbbr) | |
->type('@zipInput', $this->faker->postcode) | |
->select('@countryInput', 'US') | |
->waitFor('#subscription iframe[allowpaymentrequest="true"]', 15); | |
$browser->driver->switchTo()->frame($browser->script('return $(\'#subscription iframe[allowpaymentrequest="true"]\').attr("name");')[0]); | |
foreach (str_split('4242424242424242') as $char) { | |
$browser->append('cardnumber', $char)->pause(100); | |
} | |
$browser->type('exp-date', '1222') | |
->type('cvc', '123'); | |
$browser->driver->switchTo()->defaultContent(); | |
$browser->press('Subscribe') | |
->waitForText('You are currently subscribed', 60) | |
->assertSee('You are currently subscribed'); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment