diff options
author | William Desportes <williamdes@wdes.fr> | 2021-02-09 14:16:07 +0300 |
---|---|---|
committer | William Desportes <williamdes@wdes.fr> | 2021-02-09 14:16:41 +0300 |
commit | 5ed688bdae5b5fa3f313b9f5aebf8f610551b8a4 (patch) | |
tree | 6082291e0a286e0895bb51809e697515428d099c /test | |
parent | 8d1a95ded447083ac8c5ce96af4fca1ded9a9d3b (diff) | |
parent | fc5f1f27973d05ea476d01a622e69e9ff0c31bae (diff) |
Merge branch 'QA_5_1'
Signed-off-by: William Desportes <williamdes@wdes.fr>
Diffstat (limited to 'test')
-rw-r--r-- | test/README.rst | 7 | ||||
-rw-r--r-- | test/config.e2e.inc.php | 1 | ||||
-rw-r--r-- | test/nginx.conf | 6 | ||||
-rw-r--r-- | test/php-fpm.conf | 3 | ||||
-rw-r--r-- | test/selenium/TestBase.php | 71 | ||||
-rwxr-xr-x | test/start-local-server | 8 | ||||
-rwxr-xr-x | test/stop-local-server | 18 |
7 files changed, 87 insertions, 27 deletions
diff --git a/test/README.rst b/test/README.rst index 99c838567b..e466649096 100644 --- a/test/README.rst +++ b/test/README.rst @@ -47,10 +47,9 @@ TESTSUITE_BROWSERSTACK_KEY For example you can use following setup in ``phpunit.xml``:: <php> - <env name="TESTSUITE_SERVER" value="localhost"/> <env name="TESTSUITE_USER" value="root"/> <env name="TESTSUITE_PASSWORD" value="root"/> - <env name="TESTSUITE_DATABASE" value="test"/> + <env name="TESTSUITE_DATABASE_PREFIX" value="test"/> <env name="TESTSUITE_URL" value="http://localhost/phpmyadmin/" /> <env name="TESTSUITE_SELENIUM_HOST" value="127.0.0.1" /> <env name="TESTSUITE_SELENIUM_PORT" value="4444" /> @@ -59,9 +58,7 @@ For example you can use following setup in ``phpunit.xml``:: Using BrowserStack ------------------ -We're using BrowserStack to run our tests on the Travis CI. If you are a team -member, you can be granted access to the team account, but you can register own -account there as well. +We're using our selenium tests on the GitHub CI. To run tests locally, you need to install BrowserStack tool to enable local testing, see their website for instructions: diff --git a/test/config.e2e.inc.php b/test/config.e2e.inc.php index b311fce528..335aaa3468 100644 --- a/test/config.e2e.inc.php +++ b/test/config.e2e.inc.php @@ -6,5 +6,6 @@ $i = 0; $cfg['Servers'] = []; $i++; $cfg['Servers'][$i]['verbose'] = 'Local'; +$cfg['Servers'][$i]['host'] = '127.0.0.1'; $cfg['Servers'][$i]['auth_type'] = 'cookie'; $cfg['UploadDir'] = './test/test_data/'; diff --git a/test/nginx.conf b/test/nginx.conf index f7f7e68cdd..ff78a46361 100644 --- a/test/nginx.conf +++ b/test/nginx.conf @@ -4,7 +4,7 @@ daemon on; pid %DIR%/nginx.pid; -error_log %ROOT%/nginx-error.log; +error_log %DIR%/nginx-error.log; events { worker_connections 1024; @@ -49,8 +49,8 @@ http { access_log off; server { - access_log %ROOT%/nginx-access.log; - error_log %ROOT%/nginx-error.log error; + access_log %DIR%/nginx-access.log; + error_log %DIR%/nginx-error.log error; listen 8000 default_server; server_name _; diff --git a/test/php-fpm.conf b/test/php-fpm.conf index ca8da3818d..fd612ac436 100644 --- a/test/php-fpm.conf +++ b/test/php-fpm.conf @@ -1,6 +1,7 @@ [global] -error_log = %ROOT%/php.log +error_log = %DIR%/php.log log_level = warning +pid = %DIR%/php-fpm.pid [www] listen = %DIR%/php-fpm.sock diff --git a/test/selenium/TestBase.php b/test/selenium/TestBase.php index adeb65ce35..f048913639 100644 --- a/test/selenium/TestBase.php +++ b/test/selenium/TestBase.php @@ -54,6 +54,11 @@ use function strlen; use function substr; use function trim; use function usleep; +use const DIRECTORY_SEPARATOR; +use function time; +use function file_put_contents; +use const JSON_PRETTY_PRINT; +use const JSON_UNESCAPED_SLASHES; /** * Base class for Selenium tests. @@ -271,6 +276,21 @@ abstract class TestBase extends TestCase } /** + * Get the current running test name + * + * Usefull for browserstack + * + * @see https://github.com/phpmyadmin/phpmyadmin/pull/14595#issuecomment-418541475 + * Reports the name of the test to browserstack + */ + public function getTestName(): string + { + $className = substr(static::class, strlen('PhpMyAdmin\Tests\Selenium\\')); + + return $className . ': ' . $this->getName(); + } + + /** * Add specific capabilities * * @param DesiredCapabilities $capabilities The capabilities object @@ -280,23 +300,15 @@ abstract class TestBase extends TestCase $buildLocal = true; $buildId = 'Manual'; $projectName = 'phpMyAdmin'; - /** - * Usefull for browserstack - * - * @see https://github.com/phpmyadmin/phpmyadmin/pull/14595#issuecomment-418541475 - * Reports the name of the test to browserstack - */ - $className = substr(static::class, strlen('PhpMyAdmin\Tests\Selenium\\')); - $testName = $className . ': ' . $this->getName(); if (getenv('BUILD_TAG')) { $buildId = getenv('BUILD_TAG'); $buildLocal = false; $projectName = 'phpMyAdmin (Jenkins)'; - } elseif (getenv('TRAVIS_JOB_NUMBER')) { - $buildId = 'travis-' . getenv('TRAVIS_JOB_NUMBER'); + } elseif (getenv('GITHUB_ACTION')) { + $buildId = 'github-' . getenv('GITHUB_ACTION'); $buildLocal = true; - $projectName = 'phpMyAdmin (Travis)'; + $projectName = 'phpMyAdmin (GitHub - Actions)'; } if (! $buildLocal) { @@ -310,7 +322,7 @@ abstract class TestBase extends TestCase 'osVersion' => '10', 'resolution' => '1920x1080', 'projectName' => $projectName, - 'sessionName' => $testName, + 'sessionName' => $this->getTestName(), 'buildName' => $buildId, 'localIdentifier' => $buildId, 'local' => $buildLocal, @@ -621,6 +633,11 @@ abstract class TestBase extends TestCase if ($this->sqlWindowHandle) { $this->webDriver->switchTo()->window($this->sqlWindowHandle); + if (! $this->isSuccessLogin()) { + $this->takeScrenshot('SQL_window_not_logged_in'); + + return false; + } $this->byXPath('//*[contains(@class,"nav-item") and contains(., "SQL")]')->click(); $this->waitAjax(); $this->typeInTextArea($query); @@ -646,6 +663,34 @@ abstract class TestBase extends TestCase return $didSucceed; } + public function takeScrenshot(string $comment): void + { + $screenshotDir = + __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR + . '..' . DIRECTORY_SEPARATOR . 'build' . DIRECTORY_SEPARATOR + . 'selenium'; + if ($this->webDriver === null) { + return; + } + $key = time(); + + // This call will also create the file path + $this->webDriver->takeScreenshot( + $screenshotDir . DIRECTORY_SEPARATOR + . 'screenshot_' . $key . '_' . $comment . '.png' + ); + $htmlOutput = $screenshotDir . DIRECTORY_SEPARATOR . 'source_' . $key . '.html'; + file_put_contents($htmlOutput, $this->webDriver->getPageSource()); + $testInfo = $screenshotDir . DIRECTORY_SEPARATOR . 'source_' . $key . '.json'; + file_put_contents($testInfo, json_encode( + [ + 'filesKey' => $key, + 'testName' => $this->getTestName(), + ], + JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES + )); + } + /** * Check if user is logged in to phpmyadmin * @@ -1180,7 +1225,7 @@ abstract class TestBase extends TestCase public function onNotSuccessfulTest(Throwable $t): void { $this->markTestAs('failed', $t->getMessage()); - + $this->takeScrenshot('test_failed'); // End testing session if ($this->webDriver !== null) { $this->webDriver->quit(); diff --git a/test/start-local-server b/test/start-local-server index 0bb19244fb..4519af68bb 100755 --- a/test/start-local-server +++ b/test/start-local-server @@ -27,10 +27,6 @@ echo "Using temporary dir: ${DIR}" # You can define FPM_PATH to override the path for example FPM_PATH="php-fpm7.4" FPM_PATH="${FPM_PATH:-php-fpm}" -if [ ! -z "${TRAVIS}" ]; then - PHP_VERSION=$(phpenv version-name) - FPM_PATH="$HOME/.phpenv/versions/$PHP_VERSION/sbin/php-fpm" -fi # Start servers "$FPM_PATH" --fpm-config $DIR/php-fpm.conf -c $DIR/php.ini @@ -46,7 +42,7 @@ if [ ! -z "$TESTSUITE_BROWSERSTACK_KEY" ] ; then unzip BrowserStackLocal-linux-x64.zip fi # Start BrowserStack Local forwarder - ~/browserstack/BrowserStackLocal --force-local --localIdentifier "travis-$TRAVIS_JOB_NUMBER" --onlyAutomate --key "$TESTSUITE_BROWSERSTACK_KEY" --daemon start + ~/browserstack/BrowserStackLocal --force-local --localIdentifier "gh-$GITHUB_ACTION" --onlyAutomate --key "$TESTSUITE_BROWSERSTACK_KEY" --daemon start elif [ -z "$SKIP_STANDALONE" ] ; then echo "Using: selenium-standalone" if [ ! -f selenium-standalone ]; then @@ -58,3 +54,5 @@ elif [ -z "$SKIP_STANDALONE" ] ; then else echo "Using: nothing." fi + +echo "${DIR}" > /tmp/last_temp_dir_phpMyAdminTests diff --git a/test/stop-local-server b/test/stop-local-server index f187848f97..d7fb884e06 100755 --- a/test/stop-local-server +++ b/test/stop-local-server @@ -14,6 +14,8 @@ if [ "$CI_MODE" != "selenium" ] ; then exit 0 fi +SELENIUM_TEMPDIR="$(cat /tmp/last_temp_dir_phpMyAdminTests)" + if [ ! -z "$TESTSUITE_BROWSERSTACK_KEY" ] ; then # Stop BrowserStack Local forwarder ~/browserstack/BrowserStackLocal --daemon stop @@ -24,3 +26,19 @@ if [ -f ~/selenium-standalone.pid~ ] ; then kill $(cat ~/selenium-standalone.pid~) rm ~/selenium-standalone.pid~ fi + +if [ ! -z "${SELENIUM_TEMPDIR}" ] && [ -f "${SELENIUM_TEMPDIR}/nginx.pid" ]; then + # Stop nginx server + kill $(cat "${SELENIUM_TEMPDIR}/nginx.pid") +fi + +if [ ! -z "${SELENIUM_TEMPDIR}" ] && [ -f "${SELENIUM_TEMPDIR}/php-fpm.pid" ]; then + # Stop php-fpm server + kill $(cat "${SELENIUM_TEMPDIR}/php-fpm.pid") +fi + +if [ ! -z "${SELENIUM_TEMPDIR}" ] && [ -d "${SELENIUM_TEMPDIR}" ]; then + # Delete the temporary folder + rm -rf "${SELENIUM_TEMPDIR}" + echo "Deleted temporary dir: ${SELENIUM_TEMPDIR}" +fi |