Skip to content

Instantly share code, notes, and snippets.

@nasrulhazim
Created May 21, 2019 00:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nasrulhazim/4e2a870d6376a5e5420972a4a5fbf42d to your computer and use it in GitHub Desktop.
Save nasrulhazim/4e2a870d6376a5e5420972a4a5fbf42d to your computer and use it in GitHub Desktop.
Use SQLite in Laravel Dusk
<?php
namespace Tests;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Laravel\Dusk\TestCase as BaseTestCase;
use Illuminate\Contracts\Console\Kernel;
abstract class DuskTestCase extends BaseTestCase
{
use CreatesApplication;
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__ . '/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
if(! file_exists(database_path('database.sqlite'))) {
touch(database_path('database.sqlite'));
}
$app['config']->set('database.default','sqlite');
$app['config']->set('database.connections.sqlite.database', database_path('database.sqlite'));
return $app;
}
/**
* Prepare for Dusk test execution.
*
* @beforeClass
*/
public static function prepare()
{
static::startChromeDriver();
}
/**
* Create the RemoteWebDriver instance.
*
* @return \Facebook\WebDriver\Remote\RemoteWebDriver
*/
protected function driver()
{
$options = (new ChromeOptions())->addArguments([
'--disable-gpu',
'--headless',
'--window-size=1920,1080',
]);
return RemoteWebDriver::create(
'http://localhost:9515', DesiredCapabilities::chrome()->setCapability(
ChromeOptions::CAPABILITY, $options
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment