Created
May 21, 2019 00:16
-
-
Save nasrulhazim/4e2a870d6376a5e5420972a4a5fbf42d to your computer and use it in GitHub Desktop.
Use SQLite in Laravel Dusk
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; | |
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 | |
) | |
); | |
} | |
} |
use CreatesApplication;
The execution will fail:
Fatal error: Trait "Tests\CreatesApplication" not found in /Users/srabol/Herd/dusk/tests/DuskTestCase.php on line 12
the codes is 5 years back, you need to update based on latest version which I'm not sure the changes required. feels free to update / provide fixes required.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use CreatesApplication;
The execution will fail: