I have the Email Registration module enabled in Drupal 8.

When I try

"Given I am logged in as a user with the "authenticated user" role

Then I get the following error:
Form field with id|name|label|value|placeholder "Username" not found. (Behat\Mink\Exception\ElementNotFoundException)

This is because the username field is hidden when the Email Registration module is enabled. So I need to override this to not look for a username field if Email Registration is enabled, but I'm not sure how to go about this. Any pointers would be much appreciated.

CommentFileSizeAuthor
#9 2671646-9.patch1.69 KBrolki
#8 2671646-8.patch1.46 KBabh.ai
#7 2671646-7.patch1.25 KBdremy

Comments

ptmkenny created an issue. See original summary.

generalconsensus’s picture

You should be able to locally patch your system with this commit: https://github.com/jhedstrom/drupalextension/pull/237.

This patch allows you to set class selectors to help make sure that the assertion for checking if a user is logged in is working correctly

samgao’s picture

Please see: https://www.drupal.org/node/2145691#comment-9946699
Just add username_field: "E-mail" in behat.yml, it could be "E-mail or username" or "Email" depending on what label it is on your login page.

willhallonline’s picture

I would agree with @samgao #3. This can probably be closed as "works as designed"?

pfrenssen’s picture

Changing the selector of the username field will not be enough, this will cause the field to be found, but the username will still be filled in instead of the e-mail address. This will fail form validation.

There is a solution in progress for the upcoming 4.x release of DrupalExtension which will allow to swap out the authentication mechanism with custom code. This will allow Email Registration to work, but also any other non-standard authentication such as SSO, CAS or Facebook Connect.

See issue #339 on Github to follow the progress.

pfrenssen’s picture

Status: Active » Needs review

There is an initial version available of the PR on Github I linked in my previous comment.

I've now also made an issue in Email Registration to provide their part of the integration: #2843505: [2.x] Add support for Behat tests. An initial version is also available but it still needs test coverage.

You can try this out by applying the patch for Email Registration and checking out the PR for BDE.

dremy’s picture

Related issues: +#2843505: [2.x] Add support for Behat tests
StatusFileSize
new1.25 KB

Adding a minor temporary patch to fix for email registration.

abh.ai’s picture

StatusFileSize
new1.46 KB

Temporary patch for only Email ID placeholder.

rolki’s picture

StatusFileSize
new1.69 KB

Please, follow this flow:
Paste this into the `composer.json` file

"drupal/drupal": {
    "'Given I am logged in' does not work with Email Registration enabled": "PATH TO THIS PAGE"
},

Into your behat.yml file paste this one:

default:
  extensions:
    Drupal\DrupalExtension:
      text:
        username_field: "Email address"
rolki’s picture

greggles’s picture

For what it's worth, I think this is a duplicate of #2843505: [2.x] Add support for Behat tests.

pfrenssen’s picture

Status: Needs review » Closed (duplicate)

Yes this is a duplicate of #2843505: [2.x] Add support for Behat tests which has a patch. On the DrupalExtension side this has been fixed in the 4.0 release where we provide the AuthenticationManager service which can be swapped out for custom implementations (as demonstrated in the patch for the other issue).