Skip to content

Commit 0d08a1a

Browse files
committed
move tweaks
1 parent 8f649e5 commit 0d08a1a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/Http/Middleware/SwitchDatabaseForParallelTesting.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Closure;
66
use Illuminate\Http\Request;
7+
use Illuminate\Support\Facades\Cache;
78
use Illuminate\Support\Facades\Config;
89
use Illuminate\Support\Facades\DB;
910

@@ -19,6 +20,8 @@ public function handle(Request $request, Closure $next): mixed
1920
Config::set("database.connections.{$connection}.database", $testDatabase);
2021
DB::purge($connection);
2122
}
23+
24+
Cache::forgetDriver(config('cache.default'));
2225
}
2326

2427
return $next($request);

src/TestCase.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
namespace JackBayliss\DuskParallel;
44

55
use Facebook\WebDriver\Chrome\ChromeOptions;
6+
use Facebook\WebDriver\Exception\NoAlertOpenException;
67
use Facebook\WebDriver\Remote\DesiredCapabilities;
78
use Facebook\WebDriver\Remote\RemoteWebDriver;
9+
use Illuminate\Foundation\Testing\RefreshDatabaseState;
810
use Illuminate\Support\Facades\ParallelTesting;
911
use Laravel\Dusk\Browser as DuskBrowser;
1012
use Laravel\Dusk\TestCase as DuskTestCase;
@@ -17,8 +19,16 @@ abstract class TestCase extends DuskTestCase
1719
*/
1820
protected static bool $parallelProcessSetUp = false;
1921

22+
/**
23+
* When DUSK_DRIVER_URL is set we're using an external Selenium/WebDriver service,
24+
* so there's no need to launch a local ChromeDriver process.
25+
*/
2026
public static function startChromeDriver(array $arguments = []): void
2127
{
28+
if (ParallelDriver::hasExplicitDriverUrl()) {
29+
return;
30+
}
31+
2232
parent::startChromeDriver(ParallelDriver::resolveDriverArguments($arguments));
2333
}
2434

@@ -70,4 +80,24 @@ protected function driver(): RemoteWebDriver
7080
)
7181
);
7282
}
83+
84+
/**
85+
* Capture failure screenshots for each browser.
86+
*
87+
* Overrides the default to dismiss any open JS dialog before attempting a screenshot.
88+
* Without this, an open alert causes UnexpectedAlertOpenException which overwrites the
89+
* real assertion failure, making the test appear to fail for a different reason.
90+
*/
91+
protected function captureFailuresFor($browsers): void
92+
{
93+
$browsers->each(function ($browser) {
94+
try {
95+
$browser->driver->switchTo()->alert()->dismiss();
96+
} catch (NoAlertOpenException $e) {
97+
// No dialog open — nothing to dismiss.
98+
}
99+
});
100+
101+
parent::captureFailuresFor($browsers);
102+
}
73103
}

0 commit comments

Comments
 (0)