Skip to content

Commit 4db79d3

Browse files
committed
chrome-mink-driver#158: Remove fallback efforts for missing windows
[minkphp/driver-testsuite#101](minkphp/driver-testsuite#101) has introduced test coverage which expects an exception if we attempt to switch to a window which does not exist. chrome-mink-driver previously tried to handle this by dynamically creating popups with `window.open()`, but we will now throw a DriverException instead.
1 parent 4ff5c6d commit 4db79d3

File tree

2 files changed

+1
-32
lines changed

2 files changed

+1
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Changelog
66
* Test using [zenika/alpine-chrome](https://github.com/Zenika/alpine-chrome) instead of custom build(s) (#155)
77
* Fix returned value of `isTextTypeInput` (#149)
88
* Session reset should close non-main windows (#152, !178)
9+
* Remove fallback behaviours for switching to windows that don't exist (#158, !193)
910

1011
## 2.9.3
1112

src/ChromeDriver.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -340,38 +340,6 @@ public function switchToWindow($name = null)
340340
return;
341341
}
342342
}
343-
try {
344-
$this->runScript("window.latest_popup = window.open('', '{$name}');");
345-
$condition = "window.latest_popup.location.href != 'about:blank';";
346-
$this->wait(2000, $condition);
347-
$script = "[window.latest_popup.document.title, window.latest_popup.location.href]";
348-
list($title, $href) = $this->evaluateScript($script);
349-
350-
foreach ($this->getWindowNames() as $id) {
351-
$info = $this->page->send('Target.getTargetInfo', ['targetId' => $id])['targetInfo'];
352-
if ($info['type'] === 'page' && $info['url'] == $href && $info['title'] == $title) {
353-
$this->switchToWindow($id);
354-
return;
355-
}
356-
}
357-
} catch (\Exception $e) {
358-
}
359-
try {
360-
// Last effort, connect to each window and compare its window name.
361-
$currentWindow = $this->getCurrentWindow();
362-
foreach ($this->page->getTabs() as $tab) {
363-
$this->connectToWindow($tab['targetId']);
364-
$windowName = $this->evaluateScript('window.name');
365-
366-
if ($windowName === $name) {
367-
return;
368-
}
369-
}
370-
// Failed to find it, try to reconnect to the original window.
371-
$this->connectToWindow($currentWindow);
372-
} catch (\Exception $e) {
373-
}
374-
375343
throw new DriverException("Couldn't find window {$name}");
376344
}
377345
}

0 commit comments

Comments
 (0)