diff --git a/.github/workflows/webdriver-chrome-headless.yml b/.github/workflows/webdriver-chrome-headless.yml index 7c43517..ac4a224 100644 --- a/.github/workflows/webdriver-chrome-headless.yml +++ b/.github/workflows/webdriver-chrome-headless.yml @@ -2,9 +2,9 @@ name: Chrome Headless Tests on: push: - branches: [ master ] + branches: [ "2.0" ] pull_request: - branches: [ master ] + branches: [ "2.0" ] jobs: build: diff --git a/.github/workflows/webdriver-chrome.yml b/.github/workflows/webdriver-chrome.yml index 3c82039..e346edf 100644 --- a/.github/workflows/webdriver-chrome.yml +++ b/.github/workflows/webdriver-chrome.yml @@ -2,9 +2,9 @@ name: Chrome Tests on: push: - branches: [ master ] + branches: [ "2.0" ] pull_request: - branches: [ master ] + branches: [ "2.0" ] jobs: build: diff --git a/.github/workflows/webdriver-firefox.yml b/.github/workflows/webdriver-firefox.yml index 2cb82a7..4cafa58 100644 --- a/.github/workflows/webdriver-firefox.yml +++ b/.github/workflows/webdriver-firefox.yml @@ -2,9 +2,9 @@ name: Firefox Tests on: push: - branches: [ master ] + branches: [ "2.0" ] pull_request: - branches: [ master ] + branches: [ "2.0" ] jobs: build: diff --git a/src/Codeception/Module/WebDriver.php b/src/Codeception/Module/WebDriver.php index c11c5b3..da96c29 100644 --- a/src/Codeception/Module/WebDriver.php +++ b/src/Codeception/Module/WebDriver.php @@ -698,7 +698,7 @@ protected function formatLogEntries(array $logEntries): string foreach ($logEntries as $logEntry) { // Timestamp is in milliseconds, but date() requires seconds. - $time = date('H:i:s', $logEntry['timestamp'] / 1000) . + $time = date('H:i:s', intval($logEntry['timestamp'] / 1000)) . // Append the milliseconds to the end of the time string '.' . ($logEntry['timestamp'] % 1000); $formattedLogs .= "{$time} {$logEntry['level']} - {$logEntry['message']}\n"; @@ -718,7 +718,7 @@ protected function logJSErrors(ScenarioDriven $test, array $browserLogEntries): && $this->isJSError($logEntry['level'], $logEntry['message']) ) { // Timestamp is in milliseconds, but date() requires seconds. - $time = date('H:i:s', $logEntry['timestamp'] / 1000) . + $time = date('H:i:s', intval($logEntry['timestamp'] / 1000)) . // Append the milliseconds to the end of the time string '.' . ($logEntry['timestamp'] % 1000); $test->getScenario()->comment("{$time} {$logEntry['level']} - {$logEntry['message']}"); @@ -3505,7 +3505,11 @@ public function seeNumberOfTabs($number): void */ public function closeTab(): void { + $currentTab = $this->webDriver->getWindowHandle(); $prevTab = $this->getRelativeTabHandle(-1); + if ($prevTab === $currentTab) { + throw new ModuleException($this, 'Will not close the last open tab'); + } $this->webDriver->close(); $this->webDriver->switchTo()->window($prevTab); } @@ -3553,8 +3557,12 @@ protected function getRelativeTabHandle($offset) $handle = $this->webDriver->getWindowHandle(); $handles = $this->webDriver->getWindowHandles(); - $idx = array_search($handle, $handles); - return $handles[($idx + $offset) % count($handles)]; + $currentHandleIdx = array_search($handle, $handles); + $newHandleIdx = ($currentHandleIdx + $offset) % count($handles); + if ($newHandleIdx < 0) { + $newHandleIdx = count($handles) + $newHandleIdx; + } + return $handles[$newHandleIdx]; } /** diff --git a/tests/web/WebDriverTest.php b/tests/web/WebDriverTest.php index d74d106..8048b49 100644 --- a/tests/web/WebDriverTest.php +++ b/tests/web/WebDriverTest.php @@ -1024,6 +1024,9 @@ public function testBrowserTabs() $this->module->switchToNextTab(2); $this->module->seeInCurrentUrl('example1'); $this->module->seeNumberOfTabs(3); + $this->module->closeTab(); + $this->module->seeNumberOfTabs(2); + $this->module->closeTab(); } public function testPerformOnWithArray()