diff options
author | William Desportes <williamdes@wdes.fr> | 2021-02-09 00:45:08 +0300 |
---|---|---|
committer | William Desportes <williamdes@wdes.fr> | 2021-02-09 04:01:23 +0300 |
commit | fda5195be7dc84ad5c2a76d0899e11efed06766f (patch) | |
tree | 0aa64719b9943d3cac0a384759dd04df8e0537fe /test | |
parent | f4684ee691e55d2310398c4d92d4e9a473cf105d (diff) |
Fix logs system and temp dir for tests
Signed-off-by: William Desportes <williamdes@wdes.fr>
Diffstat (limited to 'test')
-rw-r--r-- | test/nginx.conf | 6 | ||||
-rw-r--r-- | test/php-fpm.conf | 3 | ||||
-rw-r--r-- | test/selenium/TestBase.php | 41 | ||||
-rwxr-xr-x | test/start-local-server | 4 | ||||
-rwxr-xr-x | test/stop-local-server | 18 |
5 files changed, 56 insertions, 16 deletions
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 3f6192ddd9..f048913639 100644 --- a/test/selenium/TestBase.php +++ b/test/selenium/TestBase.php @@ -57,6 +57,8 @@ 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. @@ -274,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 @@ -283,14 +300,6 @@ 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'); @@ -313,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, @@ -663,13 +672,23 @@ abstract class TestBase extends TestCase if ($this->webDriver === null) { return; } + $key = time(); + // This call will also create the file path $this->webDriver->takeScreenshot( $screenshotDir . DIRECTORY_SEPARATOR - . 'screenshot_' . time() . '_' . $comment . '.png' + . 'screenshot_' . $key . '_' . $comment . '.png' ); - $htmlOutput = $screenshotDir . DIRECTORY_SEPARATOR . 'source_' . time() . '.html'; + $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 + )); } /** diff --git a/test/start-local-server b/test/start-local-server index e5ffb85dd4..4519af68bb 100755 --- a/test/start-local-server +++ b/test/start-local-server @@ -42,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 @@ -54,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 |