diff --git a/.github/workflows/test-selenium.yml b/.github/workflows/test-selenium.yml index 78468a9a52..174a6adf16 100644 --- a/.github/workflows/test-selenium.yml +++ b/.github/workflows/test-selenium.yml @@ -11,7 +11,7 @@ on: jobs: test-selenium: name: Selenium tests on php ${{ matrix.php-version }} and ${{ matrix.os }} - if: "!contains(github.event.head_commit.message, '[ci skip]')" + if: "!contains(github.event.head_commit.message, '[ci skip]') && !contains(github.event.head_commit.message, '[ci selenium skip]')" runs-on: ${{ matrix.os }} services: database-server: @@ -95,7 +95,10 @@ jobs: CI_MODE: selenium FPM_PATH: php-fpm8.0 SKIP_STANDALONE: 1 - run: ./test/start-local-server + run: | + ./test/start-local-server + echo ::set-output name=SELENIUM_TEMPDIR::"$(cat /tmp/last_temp_dir_phpMyAdminTests)" + id: start-local-server - name: Run selenium tests env: CI_MODE: selenium @@ -110,11 +113,15 @@ jobs: # Allowed errors: https://github.com/phpmyadmin/phpmyadmin/issues/16479 continue-on-error: true run: ./vendor/bin/phpunit --group selenium --verbose --debug --no-coverage - - name: Output logs + - name: Output logs and stop server + env: + CI_MODE: selenium + SELENIUM_TEMPDIR: ${{ steps.start-local-server.outputs.SELENIUM_TEMPDIR }} if: ${{ success() || failure() }} run: | - if [ -f php.log ] ; then cat php.log ; fi - if [ -f nginx-error.log ] ; then cat nginx-error.log ; fi + if [ -f "${SELENIUM_TEMPDIR}/php.log" ] ; then cat "${SELENIUM_TEMPDIR}/php.log" ; fi + if [ -f "${SELENIUM_TEMPDIR}/nginx-error.log" ] ; then cat "${SELENIUM_TEMPDIR}/nginx-error.log" ; fi + ./test/stop-local-server - name: 'Upload screenshots' uses: actions/upload-artifact@v2 if: ${{ success() || failure() }} diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 55be8adef0..dacd9f0953 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -13,6 +13,7 @@ test/doctum-config.php */node_modules/* */tmp/* + */build/* */twig-templates/* */vendor/* 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. @@ -273,6 +275,21 @@ abstract class TestBase extends TestCase $this->webDriver->get($url); } + /** + * 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 * @@ -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