Skip to content

Commit ab06994

Browse files
authored
Merge pull request #10 from w3bdesign/dev
Setup and install Laravel Dusk
2 parents 7a5c4a0 + 09eff16 commit ab06994

File tree

9 files changed

+2218
-1
lines changed

9 files changed

+2218
-1
lines changed

.phpstorm.meta.php

Lines changed: 1937 additions & 0 deletions
Large diffs are not rendered by default.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"barryvdh/laravel-ide-helper": "^2.9",
2121
"facade/ignition": "^2.5",
2222
"fakerphp/faker": "^1.9.1",
23+
"laravel/dusk": "^6.11",
2324
"laravel/sail": "^0.0.5",
2425
"mockery/mockery": "^1.4.2",
2526
"nunomaduro/collision": "^5.0",

composer.lock

Lines changed: 144 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Browser/ExampleTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Tests\Browser;
4+
5+
use Illuminate\Foundation\Testing\DatabaseMigrations;
6+
use Laravel\Dusk\Browser;
7+
use Tests\DuskTestCase;
8+
9+
class ExampleTest extends DuskTestCase
10+
{
11+
/**
12+
* A basic browser test example.
13+
*
14+
* @return void
15+
*/
16+
public function testBasicExample()
17+
{
18+
$this->browse(function (Browser $browser) {
19+
$browser->visit('/')
20+
->assertSee('Laravel');
21+
});
22+
}
23+
}

tests/Browser/Pages/HomePage.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Tests\Browser\Pages;
4+
5+
use Laravel\Dusk\Browser;
6+
7+
class HomePage extends Page
8+
{
9+
/**
10+
* Get the URL for the page.
11+
*
12+
* @return string
13+
*/
14+
public function url()
15+
{
16+
return '/';
17+
}
18+
19+
/**
20+
* Assert that the browser is on the page.
21+
*
22+
* @param \Laravel\Dusk\Browser $browser
23+
* @return void
24+
*/
25+
public function assert(Browser $browser)
26+
{
27+
//
28+
}
29+
30+
/**
31+
* Get the element shortcuts for the page.
32+
*
33+
* @return array
34+
*/
35+
public function elements()
36+
{
37+
return [
38+
'@element' => '#selector',
39+
];
40+
}
41+
}

tests/Browser/Pages/Page.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Tests\Browser\Pages;
4+
5+
use Laravel\Dusk\Page as BasePage;
6+
7+
abstract class Page extends BasePage
8+
{
9+
/**
10+
* Get the global element shortcuts for the site.
11+
*
12+
* @return array
13+
*/
14+
public static function siteElements()
15+
{
16+
return [
17+
'@element' => '#selector',
18+
];
19+
}
20+
}

tests/Browser/console/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

tests/DuskTestCase.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use Facebook\WebDriver\Chrome\ChromeOptions;
6+
use Facebook\WebDriver\Remote\DesiredCapabilities;
7+
use Facebook\WebDriver\Remote\RemoteWebDriver;
8+
use Laravel\Dusk\TestCase as BaseTestCase;
9+
10+
abstract class DuskTestCase extends BaseTestCase
11+
{
12+
use CreatesApplication;
13+
14+
/**
15+
* Prepare for Dusk test execution.
16+
*
17+
* @beforeClass
18+
* @return void
19+
*/
20+
public static function prepare()
21+
{
22+
if (! static::runningInSail()) {
23+
static::startChromeDriver();
24+
}
25+
}
26+
27+
/**
28+
* Create the RemoteWebDriver instance.
29+
*
30+
* @return \Facebook\WebDriver\Remote\RemoteWebDriver
31+
*/
32+
protected function driver()
33+
{
34+
$options = (new ChromeOptions)->addArguments([
35+
'--disable-gpu',
36+
'--headless',
37+
'--window-size=1920,1080',
38+
]);
39+
40+
return RemoteWebDriver::create(
41+
$_ENV['DUSK_DRIVER_URL'] ?? 'http://localhost:9515',
42+
DesiredCapabilities::chrome()->setCapability(
43+
ChromeOptions::CAPABILITY,
44+
$options
45+
)
46+
);
47+
}
48+
}

0 commit comments

Comments
 (0)