Skip to content

Commit

Permalink
Merge pull request #407 from smildev/feature/panther
Browse files Browse the repository at this point in the history
Add support for panther extension
  • Loading branch information
loic425 committed Mar 25, 2022
2 parents b1447be + fbaf88e commit 2661b99
Show file tree
Hide file tree
Showing 13 changed files with 195 additions and 20 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
test-application:
runs-on: ubuntu-18.04

name: "Test application (PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, MySQL ${{ matrix.mysql }})"
name: "Test application (PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, Behat driver ${{ matrix.behat_driver }}), MySQL ${{ matrix.mysql }})"

timeout-minutes: 25

Expand All @@ -116,6 +116,7 @@ jobs:
symfony: ["5.4.*"]
node: ["14.x"]
mysql: ["5.7"]
behat_driver: ["panther", "chrome", "chrome_headless"]

env:
APP_ENV: test
Expand Down Expand Up @@ -157,6 +158,11 @@ jobs:
name: Install certificates
run: symfony server:ca:install

-
name: Configure Behat driver
run: |
sed -i -e 's/javascript_session: panther/javascript_session: ${{ matrix.behat_driver }}/g' behat.yml.dist
-
name: Run Chrome Headless
run: google-chrome-stable --enable-automation --disable-background-networking --no-default-browser-check --no-first-run --disable-popup-blocking --disable-default-apps --disable-translate --disable-extensions --no-sandbox --enable-features=Metal --headless --remote-debugging-port=9222 --window-size=2880,1800 --proxy-server='direct://' --proxy-bypass-list='*' https://127.0.0.1 > /dev/null 2>&1 &
Expand All @@ -179,6 +185,16 @@ jobs:
name: Install PHP dependencies
run: composer update --no-interaction --no-scripts

-
name: Run Selenium
if: matrix.behat_driver == 'chrome'
run: vendor/bin/selenium-server-standalone -Dwebdriver.chrome.driver=drivers/chromedriver > /dev/null 2>&1 &

-
name: Install Behat driver
if: matrix.behat_driver != 'chrome_headless'
run: vendor/bin/bdi detect drivers

-
name: Setup Node
uses: actions/setup-node@v1
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
/behat.yml
/phpspec.yml

/drivers/

###> symfony/framework-bundle ###
/.env.*.local
/.env.local
Expand Down
44 changes: 37 additions & 7 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ default:
snippets: false

extensions:
DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension: ~
DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension: null
Robertfausk\Behat\PantherExtension: null

FriendsOfBehat\MinkDebugExtension:
directory: etc/build
Expand All @@ -19,11 +20,37 @@ default:
Behat\MinkExtension:
files_path: "%paths.base%/src/Monofony/MetaPack/CoreMeta/.recipe/tests/Resources/"
base_url: "https://127.0.0.1:8080/"
javascript_session: panther
default_session: symfony
javascript_session: chrome_headless
sessions:
symfony:
symfony: ~
panther:
panther:
options:
browser: 'chrome'
webServerDir: '%paths.base%/public' # your custom public dir
external_base_uri: 'https://127.0.0.1:8080'
kernel_options:
APP_ENV: test
APP_DEBUG: false
manager_options:
connection_timeout_in_ms: 5000
request_timeout_in_ms: 120000
capabilities:
browserName: chrome
browser: chrome
extra_capabilities:
chromeOptions:
args:
- "--window-size=2880,1800"
- "--headless"
- "start-fullscreen"
- "start-maximized"
- "no-sandbox"
acceptSslCerts: true
acceptInsecureCerts: true
unexpectedAlertBehaviour: accept
chrome_headless:
chrome:
api_url: http://127.0.0.1:9222
Expand All @@ -35,12 +62,15 @@ default:
browserName: chrome
browser: chrome
version: ""
chrome:
switches:
- "start-fullscreen"
- "start-maximized"
- "no-sandbox"
extra_capabilities:
chromeOptions:
args:
- "start-fullscreen"
- "start-maximized"
- "no-sandbox"
- "--headless"
- "--window-size=1920,1080"
- "--disable-gpu"
acceptSslCerts: true
acceptInsecureCerts: true
unexpectedAlertBehaviour: accept
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@
"require-dev": {
"behat/behat": "^3.2",
"behat/mink-selenium2-driver": "^1.3",
"dbrekelmans/bdi": "^1.0",
"dmore/behat-chrome-extension": "^1.3",
"dmore/chrome-mink-driver": "^2.7",
"friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev",
"friends-of-behat/mink": "^1.8",
"friends-of-behat/mink-browserkit-driver": "^1.4",
"friends-of-behat/mink-debug-extension": "^2.0",
Expand All @@ -124,6 +124,7 @@
"friends-of-behat/symfony-extension": "^2.0",
"friends-of-behat/variadic-extension": "^1.1",
"friendsofphp/php-cs-fixer": "^3.0",
"friendsofsymfony/oauth-server-bundle": "^1.6 || >2.0.0-alpha.0 ^2.0@dev",
"lchrusciel/api-test-case": "^5.1",
"matthiasnoback/symfony-dependency-injection-test": "^4.3",
"phpspec/phpspec": "^7.0",
Expand All @@ -133,7 +134,8 @@
"phpstan/phpstan-webmozart-assert": "^0.12",
"psr/event-dispatcher": "^1.0",
"rector/rector": "^0.11",
"se/selenium-server-standalone": "^3.141",
"robertfausk/behat-panther-extension": "^1.1",
"se/selenium-server-standalone": "2.*",
"symfony/debug-bundle": "5.4.*",
"symfony/maker-bundle": "^1.36",
"symfony/web-profiler-bundle": "5.4.*",
Expand Down
2 changes: 2 additions & 0 deletions src/Monofony/Bridge/Behat/Crud/AbstractIndexPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Behat\Mink\Session;
use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage;
use Monofony\Bridge\Behat\Service\Accessor\TableAccessorInterface;
use Monofony\Bridge\Behat\Service\JQueryHelper;
use Symfony\Component\Routing\RouterInterface;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -154,6 +155,7 @@ public function filter(): void
public function bulkDelete(): void
{
$this->getElement('bulk_actions')->pressButton('Delete');
JQueryHelper::waitForAsynchronousActionsToFinish($this->getSession());
$this->getElement('confirmation_button')->click();
}

Expand Down
31 changes: 31 additions & 0 deletions src/Monofony/Bridge/Behat/Service/DriverHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the Monofony package.
*
* (c) Monofony
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Monofony\Bridge\Behat\Service;

use Behat\Mink\Driver\DriverInterface;
use Behat\Mink\Driver\PantherDriver;
use Behat\Mink\Driver\Selenium2Driver;
use DMore\ChromeDriver\ChromeDriver;

final class DriverHelper
{
public static function isJavascriptSession(DriverInterface $driver): bool
{
return
$driver instanceof Selenium2Driver
|| $driver instanceof ChromeDriver
|| $driver instanceof PantherDriver
;
}
}
33 changes: 33 additions & 0 deletions src/Monofony/Bridge/Behat/Service/JQueryHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the Monofony package.
*
* (c) Monofony
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Monofony\Bridge\Behat\Service;

use Behat\Mink\Element\DocumentElement;
use Behat\Mink\Session;

abstract class JQueryHelper
{
public static function waitForAsynchronousActionsToFinish(Session $session): void
{
$session->wait(1000, 'typeof jQuery !== "undefined" && 0 === jQuery.active');
}

public static function waitForFormToStopLoading(DocumentElement $document, int $timeout = 10): void
{
$form = $document->find('css', 'form');
$document->waitFor($timeout, function () use ($form) {
return !$form->hasClass('loading');
});
}
}
12 changes: 6 additions & 6 deletions src/Monofony/Bridge/Behat/Service/Setter/CookieSetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Monofony\Bridge\Behat\Service\Setter;

use Behat\Mink\Driver\PantherDriver;
use Behat\Mink\Driver\Selenium2Driver;
use Behat\Mink\Session;
use DMore\ChromeDriver\ChromeDriver;
Expand Down Expand Up @@ -40,7 +41,7 @@ public function setCookie($name, $value)

$driver = $this->minkSession->getDriver();

if ($driver instanceof ChromeDriver) {
if ($driver instanceof PantherDriver || $driver instanceof ChromeDriver) {
if (!$driver->isStarted()) {
$driver->start();
}
Expand Down Expand Up @@ -72,11 +73,10 @@ private function shouldMinkSessionBePrepared(Session $session): bool
return false;
}

if ($driver instanceof Selenium2Driver) {
return true;
}

if ($driver instanceof ChromeDriver) {
if (
$driver instanceof Selenium2Driver
|| $driver instanceof ChromeDriver
|| $driver instanceof PantherDriver) {
return true;
}

Expand Down
7 changes: 4 additions & 3 deletions src/Monofony/Bridge/Behat/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"license": "MIT",
"require": {
"php": "^8.0",
"dmore/behat-chrome-extension": "^1.3",
"dmore/chrome-mink-driver": "^2.7",
"behat/behat": "^3.2",
"behat/mink-selenium2-driver": "^1.3",
"friends-of-behat/mink-browserkit-driver": "^1.4",
Expand All @@ -22,7 +20,10 @@
"webmozart/assert": "^1.9"
},
"require-dev": {
"phpstan/phpstan": "^0.12"
"phpstan/phpstan": "^0.12",
"dmore/behat-chrome-extension": "^1.3",
"dmore/chrome-mink-driver": "^2.7",
"robertfausk/behat-panther-extension": "^1.1"
},
"autoload": {
"psr-4": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public function iShouldNotBeAbleToLogInAsAuthenticatedByPassword($username, $pas
Assert::false($this->dashboardPage->isOpen());
}

/**
* @Then I visit login page
*/
public function iVisitLoginPage()
{
$this->loginPage->open();
}

private function logInAgain(string $username, string $password): void
{
$this->dashboardPage->open();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends "@!SyliusUi/Macro/table.html.twig" %}

{% macro row(grid, definition, row) %}
<tr class="item" {{ sylius_test_html_attribute('row') }}>
{% if definition.actionGroups.bulk is defined and definition.getEnabledActions('bulk')|length > 0 %}
<td class="center aligned"><input class="bulk-select-checkbox" name="bulk-select-checkbox-{{ row.id }}" type="checkbox" value="{{ row.id }}" /></td>
{% endif %}
{% for field in definition.enabledFields|sort_by('position') %}
<td>{{ sylius_grid_render_field(grid, field, row) }}</td>
{% endfor %}
{% if definition.actionGroups.item is defined and definition.getEnabledActions('item')|length > 0 %}
<td {{ sylius_test_html_attribute('actions') }}>
<div class="ui buttons">
{% for action in definition.getEnabledActions('item')|sort_by('position') %}
{{ sylius_grid_render_action(grid, action, row) }}
{% endfor %}
</div>
{% if definition.actionGroups.subitem is defined and definition.getEnabledActions('subitem')|length > 0 %}
<div class="ui divider"></div>
<div class="ui buttons">
{% for action in definition.getEnabledActions('subitem')|sort_by('position') %}
{{ sylius_grid_render_action(grid, action, row) }}
{% endfor %}
</div>
{% endif %}
</td>
{% endif %}
</tr>
{% endmacro %}
2 changes: 1 addition & 1 deletion src/Monofony/Pack/TestPack/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"phpstan/phpstan-symfony": "^0.12",
"phpstan/phpstan-webmozart-assert": "^0.12",
"psr/event-dispatcher": "^1.0",
"se/selenium-server-standalone": "^3.141",
"se/selenium-server-standalone": "2.*",
"symfony/debug-bundle": "5.4.*",
"symfony/web-profiler-bundle": "5.4.*",
"vimeo/psalm": "^4.3"
Expand Down
21 changes: 21 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
"composer/xdebug-handler": {
"version": "1.3.0"
},
"dbrekelmans/bdi": {
"version": "1.0"
},
"dmore/behat-chrome-extension": {
"version": "1.3.0"
},
Expand Down Expand Up @@ -358,6 +361,9 @@
"php-cs-fixer/diff": {
"version": "v2.0.2"
},
"php-webdriver/webdriver": {
"version": "1.12.0"
},
"phpdocumentor/reflection-common": {
"version": "1.0.1"
},
Expand Down Expand Up @@ -433,6 +439,12 @@
"rector/rector": {
"version": "0.11.60"
},
"robertfausk/behat-panther-extension": {
"version": "v1.1.0"
},
"robertfausk/mink-panther-driver": {
"version": "v1.0.8"
},
"se/selenium-server-standalone": {
"version": "v2.53.1"
},
Expand Down Expand Up @@ -712,6 +724,15 @@
"symfony/options-resolver": {
"version": "v4.2.0"
},
"symfony/panther": {
"version": "1.1",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "1.0",
"ref": "877d853a05c6713665a2f4b954734592680abff6"
}
},
"symfony/password-hasher": {
"version": "v5.3.0"
},
Expand Down

0 comments on commit 2661b99

Please sign in to comment.