diff --git a/src/Session.php b/src/Session.php index d8107724c..ebe853cb2 100644 --- a/src/Session.php +++ b/src/Session.php @@ -55,10 +55,12 @@ public function isStarted() } /** - * Starts session driver. + * Starts session driver if session is not started. * * Calling any action before visiting a page is an undefined behavior. * The only supported method calls on a fresh driver are + * - resizeWindow() + * - maximizeWindow() * - visit() * - setRequestHeader() * - setBasicAuth() @@ -67,7 +69,9 @@ public function isStarted() */ public function start() { - $this->driver->start(); + if (!$this->isStarted()) { + $this->driver->start(); + } } /** @@ -92,6 +96,8 @@ public function restart() * * Calling any action before visiting a page is an undefined behavior. * The only supported method calls on a fresh driver are + * - resizeWindow() + * - maximizeWindow() * - visit() * - setRequestHeader() * - setBasicAuth() @@ -140,11 +146,7 @@ public function getSelectorsHandler() */ public function visit($url) { - // start session if needed - if (!$this->isStarted()) { - $this->start(); - } - + $this->start(); $this->driver->visit($url); } @@ -363,6 +365,7 @@ public function wait($time, $condition = 'false') */ public function resizeWindow($width, $height, $name = null) { + $this->start(); $this->driver->resizeWindow($width, $height, $name); } @@ -373,6 +376,7 @@ public function resizeWindow($width, $height, $name = null) */ public function maximizeWindow($name = null) { + $this->start(); $this->driver->maximizeWindow($name); } } diff --git a/tests/SessionTest.php b/tests/SessionTest.php index f89705ae7..6167d3661 100644 --- a/tests/SessionTest.php +++ b/tests/SessionTest.php @@ -57,14 +57,32 @@ public function testIsStarted() $this->assertTrue($this->session->isStarted()); } - public function testStart() + public function testStartWithoutRunningSession() { + $this->driver + ->expects($this->once()) + ->method('isStarted') + ->willReturn(false); + $this->driver->expects($this->once()) ->method('start'); $this->session->start(); } + public function testStartWithRunningSession() + { + $this->driver + ->expects($this->once()) + ->method('isStarted') + ->willReturn(true); + + $this->driver->expects($this->never()) + ->method('start'); + + $this->session->start(); + } + public function testStop() { $this->driver->expects($this->once()) @@ -83,34 +101,10 @@ public function testRestart() $this->session->restart(); } - public function testVisitWithoutRunningSession() - { - $this->driver - ->expects($this->once()) - ->method('isStarted') - ->willReturn(false); - - $this->driver - ->expects($this->once()) - ->method('start'); - - $this->driver - ->expects($this->once()) - ->method('visit') - ->with($url = 'some_url'); - - $this->session->visit($url); - } - - public function testVisitWithRunningSession() + public function testVisit() { $this->driver ->expects($this->once()) - ->method('isStarted') - ->willReturn(true); - - $this->driver - ->expects($this->never()) ->method('start'); $this->driver @@ -322,6 +316,10 @@ public function testWait() public function testResizeWindow() { + $this->driver + ->expects($this->once()) + ->method('start'); + $this->driver->expects($this->once()) ->method('resizeWindow') ->with(800, 600, 'test'); @@ -331,6 +329,10 @@ public function testResizeWindow() public function testMaximizeWindow() { + $this->driver + ->expects($this->once()) + ->method('start'); + $this->driver->expects($this->once()) ->method('maximizeWindow') ->with('test');