-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from aik099/session-reset-window-close-test
Added test to confirm, that opened windows are closed by the `Session::reset` call
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace Behat\Mink\Tests\Driver\Js; | ||
|
||
use Behat\Mink\Tests\Driver\TestCase; | ||
|
||
final class SessionResetTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider initialWindowNameDataProvider | ||
*/ | ||
public function testSessionResetClosesWindows(?string $initialWindowName): void | ||
{ | ||
$session = $this->getSession(); | ||
$session->visit($this->pathTo('/window.html')); | ||
|
||
if (null !== $initialWindowName) { | ||
$session->executeScript('window.name = "'.$initialWindowName.'";'); | ||
} | ||
|
||
$page = $session->getPage(); | ||
|
||
$page->clickLink('Popup #1'); | ||
$page->clickLink('Popup #2'); | ||
|
||
$expectedInitialWindowName = $session->evaluateScript('window.name'); | ||
|
||
$windowNames = $session->getWindowNames(); | ||
$this->assertCount(3, $windowNames, 'Incorrect opened window count.'); // Initial window + 2 opened popups. | ||
|
||
$session->reset(); | ||
|
||
$windowNames = $session->getWindowNames(); | ||
$this->assertCount(1, $windowNames, 'Incorrect opened window count.'); // Initial window only. | ||
|
||
$actualInitialWindowName = $session->evaluateScript('window.name'); | ||
$this->assertEquals($expectedInitialWindowName, $actualInitialWindowName, 'Not inside an initial window.'); | ||
} | ||
|
||
public static function initialWindowNameDataProvider(): array | ||
{ | ||
return array( | ||
'no name' => array(null), | ||
'non-empty name' => array('initial-window'), | ||
); | ||
} | ||
|
||
/** | ||
* @after | ||
*/ | ||
protected function resetSessions() | ||
{ | ||
$session = $this->getSession(); | ||
|
||
// Stop the session instead of resetting, because resetting behavior is being tested. | ||
if ($session->isStarted()) { | ||
$session->stop(); | ||
} | ||
|
||
parent::resetSessions(); | ||
} | ||
} |