Performance improvements to browser tests
This commit is contained in:
parent
d9a09e92bd
commit
b859ed61f4
2 changed files with 31 additions and 14 deletions
|
@ -6,16 +6,16 @@ use Laravel\Dusk\TestCase;
|
||||||
use BadMethodCallException;
|
use BadMethodCallException;
|
||||||
use Pterodactyl\Models\User;
|
use Pterodactyl\Models\User;
|
||||||
use Tests\CreatesApplication;
|
use Tests\CreatesApplication;
|
||||||
|
use Pterodactyl\Console\Kernel;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Facebook\WebDriver\Chrome\ChromeOptions;
|
use Facebook\WebDriver\Chrome\ChromeOptions;
|
||||||
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
use Facebook\WebDriver\Remote\RemoteWebDriver;
|
||||||
use Facebook\WebDriver\Remote\DesiredCapabilities;
|
use Facebook\WebDriver\Remote\DesiredCapabilities;
|
||||||
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|
||||||
|
|
||||||
abstract class BrowserTestCase extends TestCase
|
abstract class BrowserTestCase extends TestCase
|
||||||
{
|
{
|
||||||
use CreatesApplication, DatabaseMigrations;
|
use CreatesApplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default password to use for new accounts.
|
* The default password to use for new accounts.
|
||||||
|
@ -24,6 +24,28 @@ abstract class BrowserTestCase extends TestCase
|
||||||
*/
|
*/
|
||||||
protected static $userPassword = 'Password123';
|
protected static $userPassword = 'Password123';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a fresh database instance before each test class is initialized. This is different
|
||||||
|
* than the default DatabaseMigrations as it is only run when the class is setup. The trait
|
||||||
|
* provided by Laravel will run on EACH test function, slowing things down significantly.
|
||||||
|
*
|
||||||
|
* If you need to reset the DB between function runs just include the trait in that specific
|
||||||
|
* test. In most cases you probably wont need to do this, or can modify the test slightly to
|
||||||
|
* avoid the need to do so.
|
||||||
|
*/
|
||||||
|
public static function setUpBeforeClass()
|
||||||
|
{
|
||||||
|
parent::setUpBeforeClass();
|
||||||
|
|
||||||
|
$app = require __DIR__ . '/../../bootstrap/app.php';
|
||||||
|
|
||||||
|
/** @var \Pterodactyl\Console\Kernel $kernel */
|
||||||
|
$kernel = $app->make(Kernel::class);
|
||||||
|
|
||||||
|
$kernel->bootstrap();
|
||||||
|
$kernel->call('migrate:fresh');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup tests.
|
* Setup tests.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
namespace Pterodactyl\Tests\Browser\Processes\Authentication;
|
namespace Pterodactyl\Tests\Browser\Processes\Authentication;
|
||||||
|
|
||||||
use Pterodactyl\Models\User;
|
|
||||||
use Illuminate\Support\Facades\Hash;
|
|
||||||
use Facebook\WebDriver\WebDriverKeys;
|
use Facebook\WebDriver\WebDriverKeys;
|
||||||
use Pterodactyl\Tests\Browser\BrowserTestCase;
|
use Pterodactyl\Tests\Browser\BrowserTestCase;
|
||||||
use Pterodactyl\Tests\Browser\Pages\LoginPage;
|
use Pterodactyl\Tests\Browser\Pages\LoginPage;
|
||||||
|
@ -20,10 +18,7 @@ class LoginProcessTest extends BrowserTestCase
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->user = factory(User::class)->create([
|
$this->user = $this->user();
|
||||||
'email' => 'test@example.com',
|
|
||||||
'password' => Hash::make('Password123'),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,8 +29,8 @@ class LoginProcessTest extends BrowserTestCase
|
||||||
$this->browse(function (PterodactylBrowser $browser) {
|
$this->browse(function (PterodactylBrowser $browser) {
|
||||||
$browser->visit(new LoginPage)
|
$browser->visit(new LoginPage)
|
||||||
->waitFor('@username')
|
->waitFor('@username')
|
||||||
->type('@username', 'test@example.com')
|
->type('@username', $this->user->email)
|
||||||
->type('@password', 'Password123')
|
->type('@password', self::$userPassword)
|
||||||
->click('@loginButton')
|
->click('@loginButton')
|
||||||
->waitForReload()
|
->waitForReload()
|
||||||
->assertPathIs('/')
|
->assertPathIs('/')
|
||||||
|
@ -52,7 +47,7 @@ class LoginProcessTest extends BrowserTestCase
|
||||||
$browser->visit(new LoginPage)
|
$browser->visit(new LoginPage)
|
||||||
->waitFor('@username')
|
->waitFor('@username')
|
||||||
->type('@username', $this->user->username)
|
->type('@username', $this->user->username)
|
||||||
->type('@password', 'Password123')
|
->type('@password', self::$userPassword)
|
||||||
->click('@loginButton')
|
->click('@loginButton')
|
||||||
->waitForReload()
|
->waitForReload()
|
||||||
->assertPathIs('/')
|
->assertPathIs('/')
|
||||||
|
@ -70,15 +65,15 @@ class LoginProcessTest extends BrowserTestCase
|
||||||
$browser->logout()
|
$browser->logout()
|
||||||
->visit(new LoginPage())
|
->visit(new LoginPage())
|
||||||
->waitFor('@username')
|
->waitFor('@username')
|
||||||
->type('@username', 'test@example.com')
|
->type('@username', $this->user->email)
|
||||||
->type('@password', 'invalid')
|
->type('@password', 'invalid')
|
||||||
->click('@loginButton')
|
->click('@loginButton')
|
||||||
->waitFor('.alert.error')
|
->waitFor('.alert.error')
|
||||||
->assertSeeIn('.alert.error', trans('auth.failed'))
|
->assertSeeIn('.alert.error', trans('auth.failed'))
|
||||||
->assertValue('@username', 'test@example.com')
|
->assertValue('@username', $this->user->email)
|
||||||
->assertValue('@password', '')
|
->assertValue('@password', '')
|
||||||
->assertFocused('@password')
|
->assertFocused('@password')
|
||||||
->type('@password', 'Password123')
|
->type('@password', self::$userPassword)
|
||||||
->keys('@password', [WebDriverKeys::ENTER])
|
->keys('@password', [WebDriverKeys::ENTER])
|
||||||
->waitForReload()
|
->waitForReload()
|
||||||
->assertPathIs('/')
|
->assertPathIs('/')
|
||||||
|
|
Loading…
Reference in a new issue