Behat @javascript scenarios can’t be logged as admin


Hi there,

I lately got my hands on Behat and of course took Sylius as my playground !

As I was trying to understand how to work with mink and selenium, I encounter an UnxpectedPageException while running @javascript scenarios which needed admin authentication (eg. in ui_managing_countries suite), Selenium is running correctly except that the request is always redirected to the admin login page which throws the exception. I’m always trying to sort things on my own but this time I really can’t figure out why the AdminSecurityContext is not doing his job here !

I must have done something wrong while setting up my local environnement for tests. Here are the main steps I follow:

  • Install latest Selenium & chromedriver
  • Clone the Sylius repo & run composer install, sylius:install, gulp & sylius:assets:install for test environnement
  • Setting up the database for test environnement
  • Running php server on port 8080 & running selenium
  • Then running behat

Does anyone already saw this or could help me with it ? Let me know if you need more informations to help me get through this.

Thanks a lot, it’s really great to have a nice forum for the Sylius community !


Could you post the commands that you use to run PHP server and Selenium? Have you changed the Behat or security configuration?


Thanks for your answer @pamil. I didn’t change anything in the security or behat config. I follow the steps of the testing-behat-with-js travis script & ran the following commands to run Chromedriver, Selenium & PHP server (I made sure to create the $SYLIUS_CACHE_DIR, export the variable, download & move both selenium & chromedriver into it) :

  • $SYLIUS_CACHE_DIR/chromedriver
  • java$SYLIUS_CACHE_DIR/chromedriver -jar $SYLIUS_CACHE_DIR/selenium.jar
  • bin/console server:run -d public --env=test --no-debug
  • and then ran behat with: vendor/bin/behat --strict --no-interaction --tags="@javascript && ~@todo && ~@cli"

I really don’t know where it could come from, I’m running it on OSX, so I thought it could be my machine setup, but I also created a docker environnement (I can create a repo with it if you want) and found the same issue with the browser redirected to the login page when it needs to access some secure area.

Do you have any clue ? I’m a bit desperate here !


Hello, I have the same problem, did you resolve it?
I run it from a composer create-project sylius/sylius-standard

  • Installed selenium stand alone server 3.141.59 with latest chromedriver
  • Run: java -jar selenium-server-standalone-3.141.59.jar
  • Run: vendor/bin/behat vendor/sylius/sylius/features/account/customer_account/address_book/adding_address_validation.feature

Element named "first_name" with parameters matching xpath "descendant-or-self::*[@id = 'sylius_address_firstName']" not found. (Behat\Mink\Exception\ElementNotFoundException)

This happens only with the @javascript tagged scenario …


[solved] Ok found the problem, silly …
I was in dev with redirects: true.
Be sure to be in test environment with intercept_redirects: false

1311 scenarios (1304 passed, 6 failed, 1 undefined)
I’m impressed ! Sylius rocks !


Hey @nils-m , thanks for your feedback ! I didn’t had the time to put my hands into it, but your comments gave me the motivation to do it and I finally managed to make it work, but I really don’t know what the problem was… I guess sometimes you just need to let things go and come back to it later !