Skip to content

Commit

Permalink
Merge pull request #96 from aik099/session-reset-window-close-test
Browse files Browse the repository at this point in the history
Added test to confirm, that opened windows are closed by the `Session::reset` call
  • Loading branch information
stof authored Jun 26, 2024
2 parents 3620283 + dd8a81d commit 1b88ec3
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/Js/SessionResetTest.php
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();
}
}

0 comments on commit 1b88ec3

Please sign in to comment.