Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test to confirm, that opened windows are closed by the Session::reset call #96

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading