diff --git a/tests/Js/SessionResetTest.php b/tests/Js/SessionResetTest.php new file mode 100644 index 0000000..473a513 --- /dev/null +++ b/tests/Js/SessionResetTest.php @@ -0,0 +1,62 @@ +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(); + } +}