-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Harden window closing code upon session reset
- Loading branch information
Showing
2 changed files
with
70 additions
and
3 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
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 Mink\WebdriverClassDriver\Tests\Custom; | ||
|
||
use Behat\Mink\Tests\Driver\TestCase; | ||
|
||
class SessionResetTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider initialWindowNameDataProvider | ||
*/ | ||
public function testSessionResetClosesWindows(?string $initialWindowName) | ||
{ | ||
$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); | ||
|
||
$session->reset(); | ||
|
||
$windowNames = $session->getWindowNames(); | ||
$this->assertCount(1, $windowNames); | ||
|
||
$actualInitialWindowName = $session->evaluateScript('window.name'); | ||
$this->assertEquals($expectedInitialWindowName, $actualInitialWindowName); | ||
} | ||
|
||
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(); | ||
} | ||
} |