How to test your Sylius plugins with Selenium?
Behat is an open source Behavior-Driven Development framework for PHP. BDD is a methodology for developing software through continuous example-based communication between developers and a business, which this application supports. Scenarii are written in a special format called Gherkin.
Through this blog post, you will learn how to configure your Sylius Plugin project to use Selenium. I consider that you are using the Sylius plugin skeleton.
Adding Selenium to our docker-compose configuration
First, we need to a chrome-node (or firefox) to work. We will use two containers. One for the Hub and one for the node. The Hub is the machine where all the tests will run but the code be executed on different nodes as stated on the Selenium documentation.
# docker-compose.yaml version: '3.7' services: plugin: # Your app configuration. This is not the subject here hub: image: selenium/hub:3.11.0 ports: - 4444:4444 links: - plugin chrome: image: selenium/node-chrome:3.11.0 # You can also use this image and open the container port to one of your host port to be able to use a VNC viewer # image: selenium/node-chrome-debug:3.11.0 depends_on: - hub links: - plugin environment: - HUB_HOST=hub - HUB_PORT=4444 # ports: # - 5900:5900
With this configuration, you will be able to run
docker-compose up -d and use it easily with your
What do you need to change in behat.yml to be able to run Selenium
The changes in your Behat configuration are really simple.
First, your may change the
base_url of the
Behat\MinkExtension depending on what you set earlier for the app. For me, in could simply be
"http://plugin:80/" to target my container on the (not secure 😅) port 80.
Secondly, you have to add your Hub host to your chrome session. Simple add a key
wd_host in the
selenium2configuration of your chrome session.
Thirdly, you can set
true in capabilities.
Follow the example configuration below.
🎉🎉🎉 Your configuration is now ready 🎉🎉🎉
I hope this blog post helped you configure your project for admin or shop scenarii within a Sylius plugin. And I wish to be able to talk about running those tests inside a Gitlab CI job in a future article. 💪