Skip to content

Commit 358e29a

Browse files
committed
[CI] Fix and refactor behat tests
1 parent 90b76ec commit 358e29a

5 files changed

Lines changed: 86 additions & 56 deletions

File tree

.github/workflows/ci_e2e-mysql.yaml

Lines changed: 77 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,6 @@ jobs:
5555
DATABASE_URL: "mysql://root:root@127.0.0.1/sylius?charset=utf8mb4&serverVersion=${{ matrix.mysql }}"
5656

5757
steps:
58-
- name: Set variables
59-
shell: bash
60-
env:
61-
BRANCH: ${{ inputs.branch }}
62-
run: |
63-
if [ "$BRANCH" == "1.12" ]; then
64-
echo "USE_LEGACY_POSTGRES_SETUP=yes" >> $GITHUB_ENV
65-
else
66-
echo "USE_LEGACY_POSTGRES_SETUP=no" >> $GITHUB_ENV
67-
fi
68-
6958
- name: "Checkout (With Branch)"
7059
if: "${{ inputs.branch != '' }}"
7160
uses: actions/checkout@v4
@@ -76,10 +65,6 @@ jobs:
7665
if: "${{ inputs.branch == '' }}"
7766
uses: actions/checkout@v4
7867

79-
- name: Restrict Twig
80-
if: matrix.twig == '^2.12'
81-
run: composer require --no-update --no-scripts --no-interaction "twig/twig:${{ matrix.twig }}"
82-
8368
- name: Prepare manifest.json files
8469
run: |
8570
mkdir -p public/build/admin
@@ -99,11 +84,10 @@ jobs:
9984
cache_restore_key: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-symfony-${{ matrix.symfony }}"
10085
e2e: "yes"
10186
database_version: ${{ matrix.mysql }}
102-
legacy_postgresql_setup: ${{ env.USE_LEGACY_POSTGRES_SETUP }}
87+
legacy_postgresql_setup: "no"
10388
php_version: ${{ matrix.php }}
10489
symfony_version: ${{ matrix.symfony }}
10590
node_version: "20.x"
106-
chrome_version: stable
10791

10892
- name: Test installer
10993
run: bin/console sylius:install --no-interaction -vvv
@@ -131,10 +115,10 @@ jobs:
131115
if-no-files-found: ignore
132116
overwrite: true
133117

134-
behat-ui-js-chromedriver:
118+
shop-behat-ui-js-chromedriver:
135119
needs: get-matrix
136120
runs-on: ubuntu-latest
137-
name: "JS with Chromedriver, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }} (${{ matrix.env || 'test_cached' }}), MySQL ${{ matrix.mysql }}, Twig ${{ matrix.twig }}"
121+
name: "Shop JS with Chromedriver, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }} (${{ matrix.env || 'test_cached' }}), MySQL ${{ matrix.mysql }}, Twig ${{ matrix.twig }}"
138122
timeout-minutes: 45
139123
strategy:
140124
fail-fast: false
@@ -149,12 +133,6 @@ jobs:
149133
shell: bash
150134
env:
151135
BRANCH: ${{ inputs.branch }}
152-
run: |
153-
if [ "$BRANCH" == "1.12" ]; then
154-
echo "USE_LEGACY_POSTGRES_SETUP=yes" >> $GITHUB_ENV
155-
else
156-
echo "USE_LEGACY_POSTGRES_SETUP=no" >> $GITHUB_ENV
157-
fi
158136

159137
- name: "Checkout (With Branch)"
160138
if: "${{ inputs.branch != '' }}"
@@ -177,10 +155,6 @@ jobs:
177155
key: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-symfony-${{ matrix.symfony }}"
178156
restore-keys: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-symfony-${{ matrix.symfony }}"
179157

180-
- name: Restrict Twig
181-
if: matrix.twig == '^2.12'
182-
run: composer require --no-update --no-scripts --no-interaction "twig/twig:${{ matrix.twig }}"
183-
184158
- name: Build application
185159
uses: SyliusLabs/BuildTestAppAction@v2.3
186160
with:
@@ -190,13 +164,13 @@ jobs:
190164
e2e: "yes"
191165
e2e_js: "yes"
192166
database_version: ${{ matrix.mysql }}
193-
legacy_postgresql_setup: ${{ env.USE_LEGACY_POSTGRES_SETUP }}
167+
legacy_postgresql_setup: "no"
194168
php_version: ${{ matrix.php }}
195169
symfony_version: ${{ matrix.symfony }}
196170
node_version: "20.x"
197171

198172
- name: Run Behat (Chromedriver)
199-
run: vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&~@failing" --suite-tags="@hybrid,@ui" || vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&~@failing" --suite-tags="@hybrid,@ui" --rerun || vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&~@failing" --suite-tags="@hybrid,@ui" --rerun
173+
run: vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&~@failing" --suite-tags="@hybrid,@ui" features/shop || vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&~@failing" --suite-tags="@hybrid,@ui" features/shop --rerun || vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&~@failing" --suite-tags="@hybrid,@ui" --rerun features/shop
200174

201175
- name: Run Behat (Chromedriver) for randomly failing scenarios (@failing)
202176
run: vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&@failing" --suite-tags="@hybrid,@ui" || vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&@failing" --suite-tags="@hybrid,@ui" --rerun || vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&@failing" --suite-tags="@hybrid,@ui" --rerun
@@ -213,10 +187,10 @@ jobs:
213187
if-no-files-found: ignore
214188
overwrite: true
215189

216-
behat-ui-js-panther:
190+
admin-behat-ui-js-chromedriver:
217191
needs: get-matrix
218192
runs-on: ubuntu-latest
219-
name: "JS with Panther, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }} (${{ matrix.env || 'test_cached' }}), MySQL ${{ matrix.mysql }}, Twig ${{ matrix.twig }}"
193+
name: "Admin JS with Chromedriver, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }} (${{ matrix.env || 'test_cached' }}), MySQL ${{ matrix.mysql }}, Twig ${{ matrix.twig }}"
220194
timeout-minutes: 45
221195
strategy:
222196
fail-fast: false
@@ -227,17 +201,6 @@ jobs:
227201
DATABASE_URL: "mysql://root:root@127.0.0.1/sylius?charset=utf8mb4&serverVersion=${{ matrix.mysql }}"
228202

229203
steps:
230-
- name: Set variables
231-
shell: bash
232-
env:
233-
BRANCH: ${{ inputs.branch }}
234-
run: |
235-
if [ "$BRANCH" == "1.12" ]; then
236-
echo "USE_LEGACY_POSTGRES_SETUP=yes" >> $GITHUB_ENV
237-
else
238-
echo "USE_LEGACY_POSTGRES_SETUP=no" >> $GITHUB_ENV
239-
fi
240-
241204
- name: "Checkout (With Branch)"
242205
if: "${{ inputs.branch != '' }}"
243206
uses: actions/checkout@v4
@@ -272,13 +235,80 @@ jobs:
272235
e2e: "yes"
273236
e2e_js: "yes"
274237
database_version: ${{ matrix.mysql }}
275-
legacy_postgresql_setup: ${{ env.USE_LEGACY_POSTGRES_SETUP }}
238+
legacy_postgresql_setup: "no"
276239
php_version: ${{ matrix.php }}
277240
symfony_version: ${{ matrix.symfony }}
278241
node_version: "20.x"
279242

280-
- name: Install Behat driver
281-
run: vendor/bin/bdi detect drivers
243+
- name: Run Behat (Chromedriver)
244+
run: vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&~@failing" --suite-tags="@hybrid,@ui" features/admin || vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&~@failing" --suite-tags="@hybrid,@ui" features/admin --rerun || vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&~@failing" --suite-tags="@hybrid,@ui" --rerun features/admin
245+
246+
- name: Run Behat (Chromedriver)
247+
run: vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&~@failing" --suite-tags="@hybrid,@ui" features/hybrid || vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&~@failing" --suite-tags="@hybrid,@ui" features/hybrid --rerun || vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&~@failing" --suite-tags="@hybrid,@ui" --rerun features/hybrid
248+
249+
- name: Run Behat (Chromedriver) for randomly failing scenarios (@failing)
250+
run: vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&@failing" --suite-tags="@hybrid,@ui" || vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&@failing" --suite-tags="@hybrid,@ui" --rerun || vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@mink:chromedriver&&~@todo&&~@cli&&@failing" --suite-tags="@hybrid,@ui" --rerun
251+
continue-on-error: true
252+
253+
- name: Upload logs
254+
uses: actions/upload-artifact@v4
255+
if: failure()
256+
with:
257+
name: "Logs (JS with Chromedriver, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, Twig ${{ matrix.twig }}, MySQL ${{ matrix.mysql }}) - ${{ github.run_id }}-${{ github.run_number }}"
258+
path: |
259+
etc/build/
260+
var/log
261+
if-no-files-found: ignore
262+
overwrite: true
263+
264+
behat-ui-js-panther:
265+
needs: get-matrix
266+
runs-on: ubuntu-latest
267+
name: "JS with Panther, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }} (${{ matrix.env || 'test_cached' }}), MySQL ${{ matrix.mysql }}, Twig ${{ matrix.twig }}"
268+
timeout-minutes: 45
269+
strategy:
270+
fail-fast: false
271+
matrix: ${{ fromJson(needs.get-matrix.outputs.matrix) }}
272+
273+
env:
274+
APP_ENV: ${{ matrix.env || 'test_cached' }}
275+
DATABASE_URL: "mysql://root:root@127.0.0.1/sylius?charset=utf8mb4&serverVersion=${{ matrix.mysql }}"
276+
277+
steps:
278+
- name: "Checkout (With Branch)"
279+
if: "${{ inputs.branch != '' }}"
280+
uses: actions/checkout@v4
281+
with:
282+
ref: ${{ inputs.branch }}
283+
284+
- name: "Checkout"
285+
if: "${{ inputs.branch == '' }}"
286+
uses: actions/checkout@v4
287+
288+
- name: Get Composer cache directory
289+
id: composer-cache
290+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
291+
292+
- name: "Restore dependencies"
293+
uses: actions/cache@v4
294+
with:
295+
path: ${{ steps.composer-cache.outputs.dir }}
296+
key: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-symfony-${{ matrix.symfony }}"
297+
restore-keys: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-symfony-${{ matrix.symfony }}"
298+
299+
- name: Build application
300+
uses: SyliusLabs/BuildTestAppAction@v2.3
301+
with:
302+
build_type: "sylius"
303+
cache_key: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-symfony-${{ matrix.symfony }}"
304+
cache_restore_key: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-symfony-${{ matrix.symfony }}"
305+
e2e: "yes"
306+
e2e_js: "yes"
307+
database_version: ${{ matrix.mysql }}
308+
legacy_postgresql_setup: "no"
309+
php_version: ${{ matrix.php }}
310+
symfony_version: ${{ matrix.symfony }}
311+
node_version: "20.x"
282312

283313
- name: Run Behat (Panther)
284314
run: vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@javascript&&~@todo&&~@cli" --suite-tags="@hybrid,@ui" || vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@javascript&&~@todo&&~@cli" --suite-tags="@hybrid,@ui" --rerun || vendor/bin/behat --colors --strict --no-interaction -vvv -f progress --tags="@javascript&&~@todo&&~@cli" --suite-tags="@hybrid,@ui" --rerun

src/Sylius/Behat/Context/Ui/Shop/ProductReviewContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public function iWantToReviewProduct(ProductInterface $product): void
4747
*/
4848
public function iLeaveACommentTitled(?string $comment = null, ?string $title = null, ?string $author = null): void
4949
{
50-
$this->createPage->titleReview($title);
51-
$this->createPage->setComment($comment);
50+
$this->createPage->titleReview($title ?? '');
51+
$this->createPage->setComment($comment ?? '');
5252

5353
if (null !== $author) {
5454
$this->createPage->setAuthor($author);

src/Sylius/Behat/Element/Shop/CartWidgetElement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CartWidgetElement extends Element implements CartWidgetElementInterface
1919
{
2020
public function getCartTotalQuantity(): int
2121
{
22-
$quantity = $this->getElement('cart_button')->getText();
22+
$quantity = $this->getElement('cart_button')->find('css', '.badge')->getText();
2323

2424
return (int) ($quantity ?? 0);
2525
}

src/Sylius/Behat/Page/Shop/Checkout/AddressPage.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,12 @@ protected function specifyAddress(AddressInterface $address, string $type): void
355355
{
356356
$this->assertAddressType($type);
357357

358-
$this->getElement(sprintf('%s_first_name', $type))->setValue($address->getFirstName());
359-
$this->getElement(sprintf('%s_last_name', $type))->setValue($address->getLastName());
360-
$this->getElement(sprintf('%s_street', $type))->setValue($address->getStreet());
358+
$this->getElement(sprintf('%s_first_name', $type))->setValue($address->getFirstName() ?? '');
359+
$this->getElement(sprintf('%s_last_name', $type))->setValue($address->getLastName() ?? '');
360+
$this->getElement(sprintf('%s_street', $type))->setValue($address->getStreet() ?? '');
361361
$this->getElement(sprintf('%s_country', $type))->selectOption($address->getCountryCode() ?: 'Select');
362-
$this->getElement(sprintf('%s_city', $type))->setValue($address->getCity());
363-
$this->getElement(sprintf('%s_postcode', $type))->setValue($address->getPostcode());
362+
$this->getElement(sprintf('%s_city', $type))->setValue($address->getCity() ?? '');
363+
$this->getElement(sprintf('%s_postcode', $type))->setValue($address->getPostcode() ?? '');
364364

365365
if (null !== $address->getProvinceName()) {
366366
$this->waitForElementUpdate('form');

src/Sylius/Behat/Page/Shop/Product/ShowPage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ protected function getDefinedElements(): array
385385
protected function waitForElementToBeReady(): void
386386
{
387387
if (DriverHelper::isJavascript($this->getDriver())) {
388-
$this->getDocument()->waitFor(1, fn (): bool => $this->summaryPage->isOpen());
388+
$this->getDocument()->waitFor(5, fn (): bool => $this->summaryPage->isOpen());
389389
}
390390
}
391391

0 commit comments

Comments
 (0)