Jibé Barth

🇫🇷 Web developer

[Sylius] Get ready to add a behat feature that use javascript

Published Dec 9, 2023

While contributing on Sylius, I had to add a test for a fix.

There was already some behat test regarding the feature, but I had trouble to get ready to launch them in my own environment, and Makefile provided by Sylius didn't help me.

Here is how I proceed.

1. Launching Sylius in test mode

First, you need to be able to launch the sylius, but in Test mode.

In the docker-compose.yml provided, I commented everything except the mysql container. In my case, I have all php tools installed on my host, no need for others containers.

Once started, change the .env to use it (ie adding password 😅)

DATABASE_URL=mysql://root:mysql@127.0.0.1/sylius_%kernel.environment%?charset=utf8mb4

And enable the test mode

APP_ENV=test

Then, initialize correctly the database.

php bin/console doctrine:database:create
php bin/console doctrine:migration:migrate
php bin/console sylius:fixture:load -n

And finally, start the webserver thanks to Symfony binary.

symfony local:server:start -d

You can specify the port to start :

symfony local:server:start -d --port=8080

[!IMPORTANT] If the port is not on 8080, you'll have to modify the behat.yml.dist file

2. Running a chrome in headless mode

I found this on the dmore/chrome-mink-driver readme.

Open a new terminal and start a new chrome headless :

google-chrome --disable-gpu --headless --remote-debugging-address=0.0.0.0 --remote-debugging-port=9222

Adjust binary to google-chrome-stable or google-chrome-unstable if needed.

3. Launch behat

Finally, you can launch behat

vendor/bin/behat

You can target directly the feature file you are editing, to avoid launching the huge test suite.

vendor/bin/behat features/checkout/addressing_order/sign_in_during_addressing_step.feature  -n

If a test failed, you can find a screenshot and the html page in etc/build directory.

If you have any Timeout like this,

image

It's probably the port is not the same in the behat.yml.dist and the server you started.

You can change the port in the behat.yml.dist :

default:
    # ...
    extensions:
        #...
        Behat\MinkExtension:
            files_path: "%paths.base%/src/Sylius/Behat/Resources/fixtures/"
            base_url: "https://127.0.0.1:8000/" # <-- HERE
            #...