33namespace JackBayliss \DuskParallel ;
44
55use Facebook \WebDriver \Chrome \ChromeOptions ;
6+ use Facebook \WebDriver \Exception \NoAlertOpenException ;
67use Facebook \WebDriver \Remote \DesiredCapabilities ;
78use Facebook \WebDriver \Remote \RemoteWebDriver ;
9+ use Illuminate \Foundation \Testing \RefreshDatabaseState ;
810use Illuminate \Support \Facades \ParallelTesting ;
911use Laravel \Dusk \Browser as DuskBrowser ;
1012use 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