Skip to content

Commit 41ab1c4

Browse files
authored
Fix Firefox Behat testing stability (#2113)
1 parent 05d1fde commit 41ab1c4

File tree

5 files changed

+42
-18
lines changed

5 files changed

+42
-18
lines changed

.github/workflows/build-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
container:
1313
image: ghcr.io/mvorisek/image-php:latest
1414
steps:
15-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v4
1616
with:
1717
ref: ${{ github.ref }}
1818

.github/workflows/test-unit.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
type: 'StaticAnalysis'
2525
steps:
2626
- name: Checkout
27-
uses: actions/checkout@v3
27+
uses: actions/checkout@v4
2828

2929
- name: Configure PHP
3030
run: |
@@ -111,7 +111,7 @@ jobs:
111111
ORACLE_PASSWORD: atk4_pass
112112
steps:
113113
- name: Checkout
114-
uses: actions/checkout@v3
114+
uses: actions/checkout@v4
115115

116116
- name: Configure PHP
117117
run: |
@@ -245,6 +245,8 @@ jobs:
245245
type: 'Firefox'
246246
- php: 'latest'
247247
type: 'Chrome Slow'
248+
- php: 'latest'
249+
type: 'Firefox Slow'
248250
env:
249251
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')))] }}"
250252
services:
@@ -272,7 +274,7 @@ jobs:
272274
ORACLE_PASSWORD: atk4_pass
273275
steps:
274276
- name: Checkout
275-
uses: actions/checkout@v3
277+
uses: actions/checkout@v4
276278

277279
- name: Configure PHP
278280
run: |
@@ -292,7 +294,7 @@ jobs:
292294
restore-keys: |
293295
${{ runner.os }}-composer-
294296
295-
- name: Install JS dependencies (only for coverage or Slow)
297+
- name: Install JS dependencies (only for coverage or Chrome Slow)
296298
if: env.LOG_COVERAGE || matrix.type == 'Chrome Slow'
297299
run: |
298300
if [ -n "$LOG_COVERAGE" ]; then
@@ -313,25 +315,25 @@ jobs:
313315
(cd public/external && npm ci --loglevel=error && git clean -dxfq .)
314316
fi
315317
316-
- name: Lint JS files (only for Slow)
318+
- name: Lint JS files (only for Chrome Slow)
317319
if: matrix.type == 'Chrome Slow'
318320
run: |
319321
cp public/external/postinstall.js js
320322
(cd js && npm run lint)
321323
322-
- name: Compile HTML files (only for Slow)
324+
- name: Compile HTML files (only for Chrome Slow)
323325
if: matrix.type == 'Chrome Slow'
324326
run: |
325327
cp -r template template.orig
326328
find template -not -type d -not -name '*.pug' -delete
327329
(cd template && pug --doctype html --pretty --silent .)
328330
329-
- name: Compile CSS files (only for Slow)
331+
- name: Compile CSS files (only for Chrome Slow)
330332
if: matrix.type == 'Chrome Slow'
331333
run: |
332334
lessc public/css/agileui.less public/css/agileui.min.css --clean-css="--s1 --advanced" --source-map
333335
334-
- name: Compile JS files (only for coverage or Slow)
336+
- name: Compile JS files (only for coverage or Chrome Slow)
335337
if: env.LOG_COVERAGE || matrix.type == 'Chrome Slow'
336338
run: |
337339
if [ -n "$LOG_COVERAGE" ]; then
@@ -341,7 +343,7 @@ jobs:
341343
(cd js && npm run build)
342344
fi
343345
344-
- name: Diff compiled files (only for Slow)
346+
- name: Diff compiled files (only for Chrome Slow)
345347
if: matrix.type == 'Chrome Slow'
346348
run: |
347349
diff -ru public.orig public
@@ -372,8 +374,8 @@ jobs:
372374
ci_wait_until '[ -e /tmp/.X11-unix/X99 ]'
373375
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 &'
374376
ci_wait_until 'nc -w 1 127.0.0.1 4444'
375-
if [ "${{ matrix.type }}" = "Firefox" ]; then sed -i "s~chrome~firefox~" behat.yml.dist; fi
376-
if [ "${{ matrix.type }}" = "Chrome Slow" ]; then echo 'sleep(1);' >> demos/init-app.php; fi
377+
if [ "${{ matrix.type }}" = "Firefox" ] || [ "${{ matrix.type }}" = "Firefox Slow" ]; then sed -i "s~chrome~firefox~" behat.yml.dist; fi
378+
if [ "${{ matrix.type }}" = "Chrome Slow" ] || [ "${{ matrix.type }}" = "Firefox Slow" ]; then echo 'usleep(500_000);' >> demos/init-app.php; fi
377379
378380
- name: "Run tests: SQLite"
379381
run: |
@@ -463,7 +465,7 @@ jobs:
463465
image: ghcr.io/mvorisek/image-php:latest
464466
steps:
465467
- name: Checkout
466-
uses: actions/checkout@v3
468+
uses: actions/checkout@v4
467469

468470
- name: Install Python and dependencies
469471
run: |

src/App.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public function caughtException(\Throwable $exception): void
299299
// remove header
300300
$this->layout->template->tryDel('Header');
301301

302-
if (($this->isJsUrlRequest() || ($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '') === 'XMLHttpRequest')
302+
if (($this->isJsUrlRequest() || $this->getRequest()->getHeaderLine('X-Requested-With') === 'XMLHttpRequest')
303303
&& !isset($_GET['__atk_tab'])) {
304304
$this->outputResponseJson([
305305
'success' => false,

src/Behat/Context.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,12 @@ protected function disableAnimations(): void
148148
]);
149149

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

@@ -353,6 +355,26 @@ public function iClickUsingSelector(string $selector): void
353355
$element->click();
354356
}
355357

358+
/**
359+
* \Behat\Mink\Driver\Selenium2Driver::clickOnElement() does not wait until AJAX is completed after scroll.
360+
*
361+
* One solution can be waiting for AJAX after each \WebDriver\AbstractWebDriver::curl() call.
362+
*
363+
* @Then PATCH DRIVER I click using selector :selector
364+
*/
365+
public function iClickPatchedUsingSelector(string $selector): void
366+
{
367+
$element = $this->findElement(null, $selector);
368+
369+
$driver = $this->getSession()->getDriver();
370+
\Closure::bind(static function () use ($driver, $element) {
371+
$driver->mouseOverElement($driver->findElement($element->getXpath()));
372+
}, null, MinkSeleniumDriver::class)();
373+
$this->jqueryWait();
374+
375+
$element->click();
376+
}
377+
356378
/**
357379
* @Then I click paginator page :arg1
358380
*/

tests-behat/scroll.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ Feature: Dynamic scroll
4545
Given I am on "interactive/scroll-grid-container.php"
4646
Then I should see "Brazil"
4747
Then I should not see "Canada"
48-
When I click using selector "//table//tr/td[text()='Brazil']"
48+
When PATCH DRIVER I click using selector "//table//tr/td[text()='Brazil']"
4949
Then I should see "Brazil"
5050
Then I should see "Canada"

0 commit comments

Comments
 (0)