Skip to content
This repository was archived by the owner on Feb 7, 2023. It is now read-only.

Commit 0c80e2b

Browse files
committed
Add Laravel Dusk
1 parent 6c872d0 commit 0c80e2b

File tree

6 files changed

+142
-1
lines changed

6 files changed

+142
-1
lines changed

resources/assets/js/components/ChatComposer.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template lang="html">
22
<div class="chat-composer">
3-
<input type="text" placeholder="Start typing your message..." v-model="messageText" @keyup.enter="sendMessage">
3+
<input id="message" type="text" placeholder="Start typing your message..." v-model="messageText" @keyup.enter="sendMessage">
44
<button class="btn btn-primary" @click="sendMessage">Send</button>
55
</div>
66
</template>

tests/Browser/ExampleTest.php

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace Tests\Browser;
4+
5+
use App\User;
6+
use Tests\DuskTestCase;
7+
use Laravel\Dusk\Chrome;
8+
use Illuminate\Foundation\Testing\DatabaseMigrations;
9+
10+
class ExampleTest extends DuskTestCase
11+
{
12+
use DatabaseMigrations;
13+
14+
/**
15+
* A basic browser test example.
16+
*
17+
* @return void
18+
*/
19+
public function testBasicExample()
20+
{
21+
$user1 = factory(User::class)->create([
22+
'name' => 'John Doe'
23+
]);
24+
25+
$user2 = factory(User::class)->create([
26+
'name' => 'Jane Doe'
27+
]);
28+
29+
$this->browse(function ($first, $second) use($user1, $user2) {
30+
$first->loginAs($user1)
31+
->visit('/chat')
32+
->waitFor('.chat-composer');
33+
34+
$second->loginAs($user2)
35+
->visit('/chat')
36+
->waitFor('.chat-composer')
37+
->type('#message', 'Hey John')
38+
->press('Send');
39+
40+
$first->waitForText('Hey John')
41+
->assertSee('Jane Doe');
42+
});
43+
}
44+
}

tests/Browser/Pages/HomePage.php

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
* @return void
23+
*/
24+
public function assert(Browser $browser)
25+
{
26+
//
27+
}
28+
29+
/**
30+
* Get the element shortcuts for the page.
31+
*
32+
* @return array
33+
*/
34+
public function elements()
35+
{
36+
return [
37+
'@element' => '#selector',
38+
];
39+
}
40+
}

tests/Browser/Pages/Page.php

+20
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/screenshots/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

tests/DuskTestCase.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use Laravel\Dusk\TestCase as BaseTestCase;
6+
use Facebook\WebDriver\Remote\RemoteWebDriver;
7+
use Facebook\WebDriver\Remote\DesiredCapabilities;
8+
9+
abstract class DuskTestCase extends BaseTestCase
10+
{
11+
use CreatesApplication;
12+
13+
/**
14+
* Prepare for Dusk test execution.
15+
*
16+
* @beforeClass
17+
* @return void
18+
*/
19+
public static function prepare()
20+
{
21+
static::startChromeDriver();
22+
}
23+
24+
/**
25+
* Create the RemoteWebDriver instance.
26+
*
27+
* @return \Facebook\WebDriver\Remote\RemoteWebDriver
28+
*/
29+
protected function driver()
30+
{
31+
return RemoteWebDriver::create(
32+
'http://localhost:9515', DesiredCapabilities::chrome()
33+
);
34+
}
35+
}

0 commit comments

Comments
 (0)