Skip to content

Fix Firefox Behat testing stability #2113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
container:
image: ghcr.io/mvorisek/image-php:latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

Expand Down
26 changes: 14 additions & 12 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
type: 'StaticAnalysis'
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Configure PHP
run: |
Expand Down Expand Up @@ -111,7 +111,7 @@ jobs:
ORACLE_PASSWORD: atk4_pass
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Configure PHP
run: |
Expand Down Expand Up @@ -245,6 +245,8 @@ jobs:
type: 'Firefox'
- php: 'latest'
type: 'Chrome Slow'
- php: 'latest'
type: 'Firefox Slow'
env:
LOG_COVERAGE: "${{ fromJSON('{true: \"1\", false: \"\"}')[matrix.php == '8.2' && matrix.type == 'Chrome' && (github.event_name == 'pull_request' || (github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master')))] }}"
services:
Expand Down Expand Up @@ -272,7 +274,7 @@ jobs:
ORACLE_PASSWORD: atk4_pass
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Configure PHP
run: |
Expand All @@ -292,7 +294,7 @@ jobs:
restore-keys: |
${{ runner.os }}-composer-

- name: Install JS dependencies (only for coverage or Slow)
- name: Install JS dependencies (only for coverage or Chrome Slow)
if: env.LOG_COVERAGE || matrix.type == 'Chrome Slow'
run: |
if [ -n "$LOG_COVERAGE" ]; then
Expand All @@ -313,25 +315,25 @@ jobs:
(cd public/external && npm ci --loglevel=error && git clean -dxfq .)
fi

- name: Lint JS files (only for Slow)
- name: Lint JS files (only for Chrome Slow)
if: matrix.type == 'Chrome Slow'
run: |
cp public/external/postinstall.js js
(cd js && npm run lint)

- name: Compile HTML files (only for Slow)
- name: Compile HTML files (only for Chrome Slow)
if: matrix.type == 'Chrome Slow'
run: |
cp -r template template.orig
find template -not -type d -not -name '*.pug' -delete
(cd template && pug --doctype html --pretty --silent .)

- name: Compile CSS files (only for Slow)
- name: Compile CSS files (only for Chrome Slow)
if: matrix.type == 'Chrome Slow'
run: |
lessc public/css/agileui.less public/css/agileui.min.css --clean-css="--s1 --advanced" --source-map

- name: Compile JS files (only for coverage or Slow)
- name: Compile JS files (only for coverage or Chrome Slow)
if: env.LOG_COVERAGE || matrix.type == 'Chrome Slow'
run: |
if [ -n "$LOG_COVERAGE" ]; then
Expand All @@ -341,7 +343,7 @@ jobs:
(cd js && npm run build)
fi

- name: Diff compiled files (only for Slow)
- name: Diff compiled files (only for Chrome Slow)
if: matrix.type == 'Chrome Slow'
run: |
diff -ru public.orig public
Expand Down Expand Up @@ -372,8 +374,8 @@ jobs:
ci_wait_until '[ -e /tmp/.X11-unix/X99 ]'
su browser -c 'java -Dwebdriver.chrome.whitelistedIps=127.0.0.1 -jar /opt/selenium-server-standalone.jar -role standalone -host 127.0.0.1 -port 4444 -sessionTimeout 15 -browserTimeout 12 > /dev/null 2>&1 &'
ci_wait_until 'nc -w 1 127.0.0.1 4444'
if [ "${{ matrix.type }}" = "Firefox" ]; then sed -i "s~chrome~firefox~" behat.yml.dist; fi
if [ "${{ matrix.type }}" = "Chrome Slow" ]; then echo 'sleep(1);' >> demos/init-app.php; fi
if [ "${{ matrix.type }}" = "Firefox" ] || [ "${{ matrix.type }}" = "Firefox Slow" ]; then sed -i "s~chrome~firefox~" behat.yml.dist; fi
if [ "${{ matrix.type }}" = "Chrome Slow" ] || [ "${{ matrix.type }}" = "Firefox Slow" ]; then echo 'usleep(500_000);' >> demos/init-app.php; fi

- name: "Run tests: SQLite"
run: |
Expand Down Expand Up @@ -463,7 +465,7 @@ jobs:
image: ghcr.io/mvorisek/image-php:latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Python and dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public function caughtException(\Throwable $exception): void
// remove header
$this->layout->template->tryDel('Header');

if (($this->isJsUrlRequest() || ($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '') === 'XMLHttpRequest')
if (($this->isJsUrlRequest() || $this->getRequest()->getHeaderLine('X-Requested-With') === 'XMLHttpRequest')
&& !isset($_GET['__atk_tab'])) {
$this->outputResponseJson([
'success' => false,
Expand Down
28 changes: 25 additions & 3 deletions src/Behat/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,12 @@ protected function disableAnimations(): void
]);

$this->getSession()->executeScript(
'if (Array.prototype.filter.call(document.getElementsByTagName(\'style\'), (e) => e.getAttribute(\'about\') === \'atk-test-behat\').length === 0) {'
. ' $(\'<style about="atk-test-behat">' . $css . '</style>\').appendTo(\'head\');'
'if (Array.prototype.filter.call(document.getElementsByTagName(\'style\'), (e) => e.getAttribute(\'about\') === \'atk4-ui-behat\').length === 0) {'
. ' $(\'<style about="atk4-ui-behat">' . $css . '</style>\').appendTo(\'head\');'
. ' jQuery.fx.off = true;'
// fix self::getFinishedScript() detection for Firefox - document.readyState is updated after at least part of a new page has been loaded
. ' window.addEventListener(\'beforeunload\', (event) => jQuery.active++);'
. ' }'
. 'jQuery.fx.off = true;'
);
}

Expand Down Expand Up @@ -353,6 +355,26 @@ public function iClickUsingSelector(string $selector): void
$element->click();
}

/**
* \Behat\Mink\Driver\Selenium2Driver::clickOnElement() does not wait until AJAX is completed after scroll.
*
* One solution can be waiting for AJAX after each \WebDriver\AbstractWebDriver::curl() call.
*
* @Then PATCH DRIVER I click using selector :selector
*/
public function iClickPatchedUsingSelector(string $selector): void
{
$element = $this->findElement(null, $selector);

$driver = $this->getSession()->getDriver();
\Closure::bind(static function () use ($driver, $element) {
$driver->mouseOverElement($driver->findElement($element->getXpath()));
}, null, MinkSeleniumDriver::class)();
$this->jqueryWait();

$element->click();
}

/**
* @Then I click paginator page :arg1
*/
Expand Down
2 changes: 1 addition & 1 deletion tests-behat/scroll.feature
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ Feature: Dynamic scroll
Given I am on "interactive/scroll-grid-container.php"
Then I should see "Brazil"
Then I should not see "Canada"
When I click using selector "//table//tr/td[text()='Brazil']"
When PATCH DRIVER I click using selector "//table//tr/td[text()='Brazil']"
Then I should see "Brazil"
Then I should see "Canada"