diff --git a/test/selenium/CreateDropDatabaseTest.php b/test/selenium/CreateDropDatabaseTest.php index 6f141a556a..8285e1198d 100644 --- a/test/selenium/CreateDropDatabaseTest.php +++ b/test/selenium/CreateDropDatabaseTest.php @@ -79,11 +79,16 @@ class CreateDropDatabaseTest extends TestBase $this->waitAjax(); $this->scrollToBottom(); - $this->byCssSelector( - "input[name='selected_dbs[]'][value='" . $this->database_name . "']" - )->click(); - $this->byCssSelector("button.mult_submit")->click(); + $dbElement = $this->byCssSelector( + "input[name='selected_dbs[]'][value='" . $this->database_name . "']" + ); + $this->scrollToElement($dbElement, 0, 20); + $dbElement->click(); + + $multSubmit = $this->byCssSelector("button.mult_submit"); + $this->scrollToElement($multSubmit); + $multSubmit->click(); $this->byCssSelector("button.submitOK")->click(); $this->waitForElementNotPresent( diff --git a/test/selenium/Database/ProceduresTest.php b/test/selenium/Database/ProceduresTest.php index 95cea72357..8ec7ce30db 100644 --- a/test/selenium/Database/ProceduresTest.php +++ b/test/selenium/Database/ProceduresTest.php @@ -226,7 +226,7 @@ class ProceduresTest extends TestBase private function _executeProcedure($text, $length) { $this->waitAjax(); - $this->waitUntilElementIsVisible('linkText', ' Execute', 30)->click();// The space before Execute is because of   + $this->waitUntilElementIsVisible('partialLinkText', 'Execute', 30)->click();// The space before Execute is because of   $this->waitUntilElementIsVisible('name', "params[inp]", 30)->sendKeys($text); $this->byCssSelector("div.ui-dialog-buttonset button:nth-child(1)")->click(); diff --git a/test/selenium/Table/OperationsTest.php b/test/selenium/Table/OperationsTest.php index 2cbd1e93f5..77354a9a84 100644 --- a/test/selenium/Table/OperationsTest.php +++ b/test/selenium/Table/OperationsTest.php @@ -231,9 +231,10 @@ class OperationsTest extends TestBase */ public function testDropTable() { - $this->scrollToBottom(); - $this->waitUntilElementIsVisible('id', 'drop_tbl_anchor', 30); - $this->byId("drop_tbl_anchor")->click(); + $this->reloadPage(); + $dropLink = $this->waitUntilElementIsVisible('partialLinkText', 'Delete the table (DROP)', 30); + $this->scrollToElement($this->byId('selflink')); + $dropLink->click(); $this->byCssSelector("button.submitOK")->click(); $this->waitAjax(); diff --git a/test/selenium/TestBase.php b/test/selenium/TestBase.php index 3368198e3f..94b9fc14d9 100644 --- a/test/selenium/TestBase.php +++ b/test/selenium/TestBase.php @@ -65,6 +65,8 @@ abstract class TestBase extends TestCase */ protected $sessionId; + private const SESSION_REST_URL = 'https://api.browserstack.com/automate/sessions/'; + /** * Configures the selenium and database link. * @@ -318,6 +320,10 @@ abstract class TestBase extends TestCase ChromeOptions::CAPABILITY, $chromeOptions ); + $capabilities->setCapability( + 'loggingPrefs', + ['browser' => 'ALL'] + ); if ($this->hasCIConfig() && $this->hasBrowserstackConfig()) { $capabilities->setCapability( @@ -972,18 +978,46 @@ abstract class TestBase extends TestCase ); } + /** + * Scrolls to a coordinate such that the element + * + * @param WebDriverElement $element The element + * @param int $xOffset The x offset to apply (defaults to 0) + * @param int $yOffset The y offset to apply (defaults to 0) + * + * @return void + */ + public function scrollToElement(WebDriverElement $element, int $xOffset = 0, int $yOffset = 0): void + { + $this->webDriver->executeScript( + 'window.scrollBy(' . ($element->getLocation()->getX() + $xOffset) . ', ' . ($element->getLocation()->getY() + $yOffset) . ');' + ); + } + /** * Scroll to the bottom of page * * @return void */ - public function scrollToBottom() + public function scrollToBottom(): void { $this->webDriver->executeScript( 'window.scrollTo(0,document.body.scrollHeight);' ); } + /** + * Reload the page + * + * @return void + */ + public function reloadPage(): void + { + $this->webDriver->executeScript( + 'window.location.reload();' + ); + } + /** * Wait for AJAX completion * @@ -1029,10 +1063,59 @@ abstract class TestBase extends TestCase $this->_mysqli->close(); $this->_mysqli = null; } - + if (! $this->hasFailed()) { + $this->markTestAs('passed', ''); + } $this->webDriver->quit(); } + /** + * Mark test as failed or passed on BrowserStack + * + * @param string $status passed or failed + * @param string $message a message + * @return void + */ + private function markTestAs(string $status, string $message): void + { + // If this is being run on Browerstack, + // mark the test on Browerstack as failure + if ($this->hasBrowserstackConfig()) { + $payload = json_encode( + [ + 'status' => $status, + 'reason' => $message, + ] + ); + + $ch = curl_init(); + curl_setopt( + $ch, + CURLOPT_URL, + self::SESSION_REST_URL . $this->sessionId . '.json' + ); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); + curl_setopt( + $ch, + CURLOPT_USERPWD, + $GLOBALS['TESTSUITE_BROWSERSTACK_USER'] + . ':' . $GLOBALS['TESTSUITE_BROWSERSTACK_KEY'] + ); + + $headers = []; + $headers[] = 'Content-Type: application/json'; + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + + curl_exec($ch); + if (curl_errno($ch)) { + echo 'Error: ' . curl_error($ch) . PHP_EOL; + } + curl_close($ch); + } + } + /** * Mark unsuccessful tests as 'Failures' on Browerstack * @@ -1042,43 +1125,11 @@ abstract class TestBase extends TestCase */ public function onNotSuccessfulTest(Throwable $t): void { - $SESSION_REST_URL = 'https://api.browserstack.com/automate/sessions/'; - // If this is being run on Browerstack, - // mark the test on Browerstack as failure - if ($this->hasBrowserstackConfig()) { - $payload = json_encode( - [ - 'status' => 'failed', - 'reason' => $t->getMessage(), - ] - ); - - $ch = curl_init(); - curl_setopt( - $ch, - CURLOPT_URL, - $SESSION_REST_URL . $this->sessionId . ".json" - ); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); - curl_setopt( - $ch, - CURLOPT_USERPWD, - $GLOBALS['TESTSUITE_BROWSERSTACK_USER'] - . ":" . $GLOBALS['TESTSUITE_BROWSERSTACK_KEY'] - ); - - $headers = []; - $headers[] = "Content-Type: application/json"; - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - - $result = curl_exec($ch); - if (curl_errno($ch)) { - echo 'Error: ' . curl_error($ch) . PHP_EOL; - } - curl_close($ch); + // End testing session + if ($this->webDriver !== null) { + $this->webDriver->quit(); } + $this->markTestAs('failed', $t->getMessage()); if ($this->hasBrowserstackConfig()) { $ch = curl_init(); @@ -1086,7 +1137,7 @@ abstract class TestBase extends TestCase curl_setopt( $ch, CURLOPT_URL, - $SESSION_REST_URL . $this->sessionId . ".json" + self::SESSION_REST_URL . $this->sessionId . ".json" ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt(