101 - Getting Started with Laravel Dusk

This commit is contained in:
Adam Wathan
2017-05-02 15:51:20 -04:00
parent 0bcdd67a81
commit 41fbdcae1a
11 changed files with 245 additions and 3 deletions

1
.gitignore vendored
View File

@@ -9,3 +9,4 @@
Homestead.json
Homestead.yaml
.env
.env.dusk.local

View File

@@ -6,6 +6,7 @@ use App\TicketCodeGenerator;
use App\Billing\PaymentGateway;
use App\HashidsTicketCodeGenerator;
use App\Billing\StripePaymentGateway;
use Laravel\Dusk\DuskServiceProvider;
use Illuminate\Support\ServiceProvider;
use App\OrderConfirmationNumberGenerator;
use App\RandomOrderConfirmationNumberGenerator;
@@ -29,6 +30,10 @@ class AppServiceProvider extends ServiceProvider
*/
public function register()
{
if ($this->app->environment('local', 'testing')) {
$this->app->register(DuskServiceProvider::class);
}
$this->app->bind(StripePaymentGateway::class, function () {
return new StripePaymentGateway(config('services.stripe.secret'));
});

View File

@@ -10,7 +10,8 @@
"zondicons/blade-bridge": "^0.1.0",
"stripe/stripe-php": "^4.3",
"guzzlehttp/guzzle": "^6.2",
"hashids/hashids": "^2.0"
"hashids/hashids": "^2.0",
"laravel/dusk": "^1.1"
},
"require-dev": {
"fzaninotto/faker": "~1.4",

112
composer.lock generated
View File

@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "94fd2c7211ef4aa80724947e13ba4651",
"content-hash": "caee9b77188f151d418e434e7e9e9f21",
"hash": "7cbaa1ad75bde284c40bd5c43c2329c7",
"content-hash": "2ebfbcd062d6383b3b54cc0757b1eacf",
"packages": [
{
"name": "doctrine/inflector",
@@ -116,6 +116,58 @@
],
"time": "2017-03-29 16:04:15"
},
{
"name": "facebook/webdriver",
"version": "1.4.1",
"source": {
"type": "git",
"url": "https://github.com/facebook/php-webdriver.git",
"reference": "eadb0b7a7c3e6578185197fd40158b08c3164c83"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/facebook/php-webdriver/zipball/eadb0b7a7c3e6578185197fd40158b08c3164c83",
"reference": "eadb0b7a7c3e6578185197fd40158b08c3164c83",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-zip": "*",
"php": "^5.5 || ~7.0",
"symfony/process": "^2.8 || ^3.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.0",
"php-mock/php-mock-phpunit": "^1.1",
"phpunit/phpunit": "4.6.* || ~5.0",
"satooshi/php-coveralls": "^1.0",
"squizlabs/php_codesniffer": "^2.6"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-community": "1.5-dev"
}
},
"autoload": {
"psr-4": {
"Facebook\\WebDriver\\": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"Apache-2.0"
],
"description": "A PHP client for Selenium WebDriver",
"homepage": "https://github.com/facebook/php-webdriver",
"keywords": [
"facebook",
"php",
"selenium",
"webdriver"
],
"time": "2017-04-28 14:54:49"
},
{
"name": "guzzlehttp/guzzle",
"version": "6.2.3",
@@ -357,6 +409,62 @@
],
"time": "2017-01-01 13:33:33"
},
{
"name": "laravel/dusk",
"version": "v1.1.0",
"source": {
"type": "git",
"url": "https://github.com/laravel/dusk.git",
"reference": "6b81e97ae1ce384e3d8dbd020b2b9751c1449889"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/dusk/zipball/6b81e97ae1ce384e3d8dbd020b2b9751c1449889",
"reference": "6b81e97ae1ce384e3d8dbd020b2b9751c1449889",
"shasum": ""
},
"require": {
"facebook/webdriver": "~1.0",
"illuminate/console": "~5.4",
"illuminate/support": "~5.4",
"nesbot/carbon": "~1.20",
"php": ">=5.6.4",
"symfony/console": "~3.2",
"symfony/process": "~3.2"
},
"require-dev": {
"mockery/mockery": "^0.9.6",
"phpunit/phpunit": "^5.7"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"Laravel\\Dusk\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"description": "Laravel Dusk provides simple end-to-end testing and browser automation.",
"keywords": [
"laravel",
"testing",
"webdriver"
],
"time": "2017-04-23 17:13:04"
},
{
"name": "laravel/framework",
"version": "v5.4.16",

View File

@@ -11,6 +11,10 @@
|
*/
Route::get('/', function () {
return "Laravel";
});
Route::get('/concerts/{id}', 'ConcertsController@show');
Route::post('/concerts/{id}/orders', 'ConcertOrdersController@store');
Route::get('/orders/{confirmationNumber}', 'OrdersController@show');

View File

@@ -0,0 +1,23 @@
<?php
namespace Tests\Browser;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class ExampleTest extends DuskTestCase
{
/**
* A basic browser test example.
*
* @return void
*/
public function testBasicExample()
{
$this->browse(function (Browser $browser) {
$browser->visit('/')
->assertSee('Laravel');
});
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Tests\Browser\Pages;
use Laravel\Dusk\Browser;
class HomePage extends Page
{
/**
* Get the URL for the page.
*
* @return string
*/
public function url()
{
return '/';
}
/**
* Assert that the browser is on the page.
*
* @param Browser $browser
* @return void
*/
public function assert(Browser $browser)
{
//
}
/**
* Get the element shortcuts for the page.
*
* @return array
*/
public function elements()
{
return [
'@element' => '#selector',
];
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Tests\Browser\Pages;
use Laravel\Dusk\Page as BasePage;
abstract class Page extends BasePage
{
/**
* Get the global element shortcuts for the site.
*
* @return array
*/
public static function siteElements()
{
return [
'@element' => '#selector',
];
}
}

2
tests/Browser/console/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*
!.gitignore

2
tests/Browser/screenshots/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*
!.gitignore

35
tests/DuskTestCase.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
namespace Tests;
use Laravel\Dusk\TestCase as BaseTestCase;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
abstract class DuskTestCase extends BaseTestCase
{
use CreatesApplication;
/**
* Prepare for Dusk test execution.
*
* @beforeClass
* @return void
*/
public static function prepare()
{
static::startChromeDriver();
}
/**
* Create the RemoteWebDriver instance.
*
* @return \Facebook\WebDriver\Remote\RemoteWebDriver
*/
protected function driver()
{
return RemoteWebDriver::create(
'http://localhost:9515', DesiredCapabilities::chrome()
);
}
}