Commit ec99dfb7 authored by Viral Solani's avatar Viral Solani

Login Test with Laravel Dusk

parent 97149f41
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "7d2cd7caa0bc96f03fb6d406c444a09f",
"content-hash": "09bb7ab94ae6872b0f3b04e4eac8e215",
"packages": [
{
"name": "arcanedev/log-viewer",
......@@ -5063,6 +5063,66 @@
],
"time": "2019-03-17T17:37:11+00:00"
},
{
"name": "facebook/webdriver",
"version": "1.6.0",
"source": {
"type": "git",
"url": "https://github.com/facebook/php-webdriver.git",
"reference": "bd8c740097eb9f2fc3735250fc1912bc811a954e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/facebook/php-webdriver/zipball/bd8c740097eb9f2fc3735250fc1912bc811a954e",
"reference": "bd8c740097eb9f2fc3735250fc1912bc811a954e",
"shasum": ""
},
"require": {
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-zip": "*",
"php": "^5.6 || ~7.0",
"symfony/process": "^2.8 || ^3.1 || ^4.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.0",
"jakub-onderka/php-parallel-lint": "^0.9.2",
"php-coveralls/php-coveralls": "^2.0",
"php-mock/php-mock-phpunit": "^1.1",
"phpunit/phpunit": "^5.7",
"sebastian/environment": "^1.3.4 || ^2.0 || ^3.0",
"squizlabs/php_codesniffer": "^2.6",
"symfony/var-dumper": "^3.3 || ^4.0"
},
"suggest": {
"ext-SimpleXML": "For Firefox profile creation"
},
"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": "2018-05-16T17:37:13+00:00"
},
{
"name": "filp/whoops",
"version": "2.3.1",
......@@ -5419,6 +5479,69 @@
],
"time": "2018-06-13T13:22:40+00:00"
},
{
"name": "laravel/dusk",
"version": "v5.0.3",
"source": {
"type": "git",
"url": "https://github.com/laravel/dusk.git",
"reference": "3ebbec38a49c022d28851885d05a799257c554d9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/dusk/zipball/3ebbec38a49c022d28851885d05a799257c554d9",
"reference": "3ebbec38a49c022d28851885d05a799257c554d9",
"shasum": ""
},
"require": {
"facebook/webdriver": "^1.3",
"illuminate/console": "~5.7.0|~5.8.0|~5.9.0",
"illuminate/support": "~5.7.0|~5.8.0|~5.9.0",
"nesbot/carbon": "^1.20|^2.0",
"php": ">=7.1.0",
"symfony/console": "^4.0",
"symfony/finder": "^4.0",
"symfony/process": "^4.0",
"vlucas/phpdotenv": "^2.2|^3.3"
},
"require-dev": {
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^7.5|^8.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "5.0-dev"
},
"laravel": {
"providers": [
"Laravel\\Dusk\\DuskServiceProvider"
]
}
},
"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": "2019-04-02T19:59:29+00:00"
},
{
"name": "laravel/telescope",
"version": "v2.0.4",
......
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Browser Test Suite">
<directory suffix="Test.php">./tests/Browser</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
</phpunit>
<?php
namespace Tests\Browser;
use Laravel\Dusk\Browser;
use Tests\Browser\Pages\Login;
use Tests\DuskTestCase;
use App\Models\Access\User\User;
class LoginTest extends DuskTestCase
{
/** @test */
public function it_can_login_a_admin_user()
{
$user = User::find(1);
$this->browse(function (Browser $browser) use ($user) {
$browser->visit(new Login())
->type('email', $user->email)
->type('password', '1234')
->press('Login')
->assertSee('Dashboard')
->assertSee('Access Management');
});
}
/* @test */
// public function it_can_see_the_login_page()
// {
// $this->browse(function (Browser $browser) {
// $browser->visit(new Login());
// });
// }
/* @test */
// public function login_fails_when_a_required_field_is_not_filled_in()
// {
// $this->browse(function (Browser $browser) {
// $browser->visit(new Login())
// ->type('email', '')
// ->type('password', '')
// ->press('Login')
// ->assertPathIs('/login')
// ->assertSee('The email field is required.')
// ->assertSee('The password field is required.');
// });
// }
}
<?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 \Laravel\Dusk\Browser $browser
* @return void
*/
public function assert(Browser $browser)
{
//
}
/**
* Get the element shortcuts for the page.
*
* @return array
*/
public function elements()
{
return [
'@element' => '#selector',
];
}
}
<?php
namespace Tests\Browser\Pages;
use Laravel\Dusk\Browser;
class Login extends Page
{
/**
* Get the URL for the page.
*
* @return string
*/
public function url()
{
return '/login';
}
/**
* Assert that the browser is on the page.
*
* @param Browser $browser
*/
public function assert(Browser $browser)
{
$browser->assertSee('Login')
->assertSee('E-mail Address')
->assertInputValue('email', '')
->assertSee('Password')
->assertInputValue('password', '')
->assertNotChecked('remember')
->assertSee('Login')
->assertSee('Forgot Your Password?');
}
/**
* Get the element shortcuts for the page.
*
* @return array
*/
public function elements()
{
return [
];
}
}
<?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',
];
}
}
<?php
namespace Tests;
use Laravel\Dusk\TestCase as BaseTestCase;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
abstract class DuskTestCase extends BaseTestCase
{
use CreatesApplication;
/**
* 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
)
);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment