Skip to content

Commit

Permalink
Merge pull request #76 from musimana/bugfix/DuskTestConfig
Browse files Browse the repository at this point in the history
fix: Dusk Test Config
  • Loading branch information
musimana authored May 28, 2024
2 parents 2263514 + 85a27d2 commit f8fc113
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 128 deletions.
8 changes: 4 additions & 4 deletions app/Providers/DuskServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ public function boot(): void
{
Browser::macro('getScreenshotFilename', function (string $filename_base, string $count_string) {
return date('Y-m-d') . '_' . str_replace(' ', '_', strtolower(config('app.name')))
. '/' . config('dusk.screen_width') . 'x' . config('dusk.screen_height')
. '/' . config('tests.dusk.screen_width') . 'x' . config('tests.dusk.screen_height')
. '/' . $filename_base . '_' . $count_string;
});

Browser::macro('screenshotWholePage', function (string $filename_base) {
/** @var Browser $browser */
$browser = $this;
$browser->scrollToTop()->pause(config('dusk.pause_length'));
$browser->scrollToTop()->pause(config('tests.dusk.pause_length'));

$screen_max = ceil($browser->script('return document.body.offsetHeight / window.innerHeight')[0]);

for ($screen = 1; $screen <= $screen_max; $screen++) {
$browser->screenshot($browser->getScreenshotFilename($filename_base, (string) $screen))
->pause(config('dusk.pause_length'))
->pause(config('tests.dusk.pause_length'))
->scrollDownScreenHeight();
}

$browser->scrollToTop()->pause(config('dusk.pause_length'));
$browser->scrollToTop()->pause(config('tests.dusk.pause_length'));

return $browser;
});
Expand Down
101 changes: 0 additions & 101 deletions config/dusk.php

This file was deleted.

109 changes: 109 additions & 0 deletions config/tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,113 @@

'default_password' => env('TESTS_DEFAULT_PASSWORD', 'password'),

/*
|--------------------------------------------------------------------------
| Dusk Browser Tests Settings
|--------------------------------------------------------------------------
|
| Setting that control the Dusk browser test suite.
|
*/

'dusk' => [

/*
|--------------------------------------------------------------------------
| Headless Disabled
|--------------------------------------------------------------------------
|
| Determine whether the Dusk command has disabled headless mode.
|
| Set the `DUSK_HEADLESS_DISABLED` DotEnv variable to `true` to run the
| tests in a browser window, or `false` to run them purely from the command
| line.
|
| This option is referenced by both the app & the Laravel Dusk package.
|
*/

'headless_disabled' => env('DUSK_HEADLESS_DISABLED', true),

/*
|--------------------------------------------------------------------------
| Pause Length (milliseconds)
|--------------------------------------------------------------------------
|
| The length of time in milliseconds to pause for after each browser
| wherever the pause method is called by browser tests.
|
| Increasing this value can be useful for debugging, or tutorial video
| generation.
|
| This option is only referenced by the app.
|
*/

'pause_length' => env('DUSK_PAUSE_LENGTH', 1000),

/*
|--------------------------------------------------------------------------
| Wait Length (seconds)
|--------------------------------------------------------------------------
|
| The length of time in seconds to wait for an action to complete wherever
| a the pause method is called by browser tests.
|
| Increasing this value can be useful for debugging, or tutorial video
| generation.
|
| This option is only referenced by the app.
|
*/

'wait_length' => env('DUSK_WAIT_LENGTH', 5),

/*
|--------------------------------------------------------------------------
| Screen Width
|--------------------------------------------------------------------------
|
| The width in pixels of the browser window to be used during browser
| tests.
|
| This option is only referenced by the app.
|
*/

'screen_width' => env('DUSK_SCREEN_WIDTH', 1920),

/*
|--------------------------------------------------------------------------
| Screen Height
|--------------------------------------------------------------------------
|
| The height in pixels of the browser window to be used during browser
| tests.
|
| This option is only referenced by the app.
|
*/

'screen_height' => env('DUSK_SCREEN_HEIGHT', 1080),

/*
|--------------------------------------------------------------------------
| Start Maximized
|--------------------------------------------------------------------------
|
| Determines if the browser window size should be maximised at the start of
| each test. Requires headless mode to be disabled to have any effect.
|
| Should be set to false for the screen width and height variables to have
| any effect.
|
| This option is referenced by both the app & the Laravel Dusk package.
|
*/

'start_maximised' => env('DUSK_START_MAXIMISED', false),

],

];
6 changes: 3 additions & 3 deletions tests/Browser/Components/HeaderNav.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function elements(): array
/** Click the given navbar item, with handling for the responsive navbar. */
public function clickNavItem(Browser $browser, string $selector): void
{
if (config('dusk.screen_width') < 1024) {
if (config('tests.dusk.screen_width') < 1024) {
$this->toggleMobileMenu($browser);
}

Expand All @@ -60,7 +60,7 @@ public function clickNavItem(Browser $browser, string $selector): void
/** Click the given navbar item, with handling for the responsive navbar. */
public function clickNavSubItem(Browser $browser, string $selector, string $route): void
{
if (config('dusk.screen_width') < 1024) {
if (config('tests.dusk.screen_width') < 1024) {
$this->toggleMobileMenu($browser);
}

Expand All @@ -72,7 +72,7 @@ public function clickNavSubItem(Browser $browser, string $selector, string $rout
/** Click the given navbar item, with handling for the responsive navbar. */
public function toggleNavItem(Browser $browser, string $selector): void
{
if (config('dusk.screen_width') < 1024) {
if (config('tests.dusk.screen_width') < 1024) {
$this->toggleMobileMenu($browser);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Browser/Pages/Admin/Page/AdminEditPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public function assert(Browser $browser): void
->assertHasCorrectCookies()
->assertHasRenderedCorrectly($this->page->getTitle())

->pause(config('dusk.pause_length'));
->pause(config('tests.dusk.pause_length'));
}
}
2 changes: 1 addition & 1 deletion tests/Browser/Pages/AdminPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function elements(): array
public function assertHasLoadedCorrectly(Browser $browser, string $url): void
{
$browser
->waitForLocation($url, config('tests.wait_length'))
->waitForLocation($url, config('tests.dusk.wait_length'))
->assertUrlIs($url)
->assertScript('window.__VUE__')
->assertScript('document.readyState', 'complete');
Expand Down
2 changes: 1 addition & 1 deletion tests/Browser/Pages/AuthPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class AuthPage extends Page
public function assertHasLoadedCorrectly(Browser $browser, string $url): void
{
$browser
->waitForLocation($url, config('tests.wait_length'))
->waitForLocation($url, config('tests.dusk.wait_length'))
->assertUrlIs($url)
->assertScript('window.__VUE__')
->assertScript('document.readyState', 'complete');
Expand Down
2 changes: 1 addition & 1 deletion tests/Browser/Pages/Guest/Homepage.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public function assert(Browser $browser): void
->assertHasCorrectCookies()
->assertHasRenderedCorrectly(config('app.name'))

->pause(config('dusk.pause_length'));
->pause(config('tests.dusk.pause_length'));
}
}
2 changes: 1 addition & 1 deletion tests/Browser/Pages/Guest/PageView.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public function assert(Browser $browser): void
->assertHasCorrectCookies()
->assertHasRenderedCorrectly($this->page->getMetaTitle())

->pause(config('dusk.pause_length'));
->pause(config('tests.dusk.pause_length'));
}
}
2 changes: 1 addition & 1 deletion tests/Browser/Pages/SitemapPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ abstract class SitemapPage extends Page
public function assertHasLoadedCorrectly(Browser $browser, string $url): void
{
$browser
->waitForLocation($url, config('tests.wait_length'))
->waitForLocation($url, config('tests.dusk.wait_length'))
->assertUrlIs($url);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Browser/Pages/Sitemaps/SitemapIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public function assert(Browser $browser): void
->assertVisible('sitemapindex')
->assertVisible('sitemap')
->assertVisible('loc')
->pause(config('dusk.pause_length'));
->pause(config('tests.dusk.pause_length'));
}
}
2 changes: 1 addition & 1 deletion tests/Browser/Pages/Sitemaps/SitemapItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public function assert(Browser $browser): void

->assertVisible('urlset')
->assertVisible('url')
->pause(config('dusk.pause_length'));
->pause(config('tests.dusk.pause_length'));
}
}
2 changes: 1 addition & 1 deletion tests/Browser/Pages/StandardPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function elements(): array
public function assertHasLoadedCorrectly(Browser $browser, string $url): void
{
$browser
->waitForLocation($url, config('tests.wait_length'))
->waitForLocation($url, config('tests.dusk.wait_length'))
->assertUrlIs($url)
->assertScript('window.__VUE__')
->assertScript('document.readyState', 'complete');
Expand Down
2 changes: 1 addition & 1 deletion tests/Browser/Pages/User/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function assert(Browser $browser): void
->assertHasRenderedCorrectly('Dashboard')

->assertAuthenticatedAs($this->user)
->pause(config('dusk.pause_length'));
->pause(config('tests.dusk.pause_length'));
}
}
2 changes: 1 addition & 1 deletion tests/Browser/Pages/User/ForgotPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public function assert(Browser $browser): void
->assertHasCorrectCookies()
->assertHasRenderedCorrectly('Forgot Password')

->pause(config('dusk.pause_length'));
->pause(config('tests.dusk.pause_length'));
}
}
8 changes: 4 additions & 4 deletions tests/Browser/Pages/User/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function assert(Browser $browser): void
->assertHasRenderedCorrectly('Login')

->assertGuest()
->pause(config('dusk.pause_length'));
->pause(config('tests.dusk.pause_length'));
}

/**
Expand All @@ -41,14 +41,14 @@ public function elements(): array
public function loginAsUser(Browser $browser, string $email): void
{
$browser
->pause(config('dusk.pause_length'))
->pause(config('tests.dusk.pause_length'))
->completeForm('form', [
'email' => $email,
'password' => config('tests.default_password'),
])
->pause(config('dusk.pause_length'))
->pause(config('tests.dusk.pause_length'))
->screenshotWholePage('login-filled-' . str_replace(['@', '.'], '_', $email))
->click('@button-login')
->waitForLocation(route('dashboard'), config('dusk.wait_length'));
->waitForLocation(route('dashboard'), config('tests.dusk.wait_length'));
}
}
2 changes: 1 addition & 1 deletion tests/Browser/Pages/User/ProfileEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function assert(Browser $browser): void
->assertHasRenderedCorrectly('Profile')

->assertAuthenticatedAs($this->user)
->pause(config('dusk.pause_length'));
->pause(config('tests.dusk.pause_length'));
}
}
Loading

0 comments on commit f8fc113

Please sign in to comment.