I cannot seem to figure this one out.
I defined the following feature:
Feature: Login
Scenario: Test Basic Login
Given I am on "/account"
And I login successfully as "demo@demo.de" with password "demodemo"
Then I should see "Abmelden"
The feature context looks the following:
/**
* @Given I login successfully as :arg1 with password :arg2
*/
public function iLoginSuccessfullyAsWithPassword($arg1, $arg2)
{
$page = $this->getSession()->getPage();
$page->fillField('email', $arg1);
$page->fillField('password', $arg2);
$page->pressButton('Anmelden');
}
And to give a complete picture here my behat.yml:
default:
extensions:
Behat\MinkExtension:
base_url: "http://192.168.33.10/s5224"
default_session: 'goutte'
javascript_session: 'selenium2'
goutte: ~
selenium2: ~
Now The scenario runs well until I should see "Abmelden". Then I get
The text "Abmelden" was not found anywhere in the text of the current page. (Behat\Mink\Exception\ResponseTextException)
This is very frustrating since I actually should be seeing "Abmelden"...
I have tried this with multiple versions and configurations of behat / mink. I have also tried looking for other text content on the user dashboard. But it seems I am missing a very fundamental piece of information here.
Edit:
I have dumped the page after I let the routine click on "Anmelden". What I get is the following xdebug dump:
Fatal error: Uncaught Shopware\Components\CSRFTokenValidationException: The provided X-CSRF-Token for path "/s5224/account/login/sTarget/account/sTargetAction/index" is invalid. Please go back, reload the page and try again. in /home/vagrant/www/s5224/engine/Shopware/Components/CSRFTokenValidator.php on line
I assumed that the goutte driver just cannot handle this kind of behaviour so annotated the scenario with @javascript.
The scenario now looks like:
@javascript
Scenario: Test Basic Login
Given I am on "/account"
And I login successfully as "demo@demo.de" with password "demodemo"
Then I should see "Abmelden"
That now gave me the option to use something like (as suggested by lauda here: https://stackoverflow.com/a/38207434/2815176)
$this->getSession()->wait(10000, "document.readyState === 'complete'");
Interestingly though, the scenario now no longer seems to be able to get on the account page. When I dump the page it is completely empty. Even when I wait for up to 60 seconds.
So now the problem seems to be either to get the selenium2 driver to actually access the account page, or to get the goutte driver to handle the X-CSRF-Token problem.