Skip to content

Commit

Permalink
Merge pull request jhedstrom#631 from eiriksm/feat/helper-for-submit
Browse files Browse the repository at this point in the history
Add a helper for the getting of the login submit element
  • Loading branch information
jhedstrom authored Jan 5, 2023
2 parents 5ee222f + 9d781dc commit 5deb56c
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\DrupalExtension\Manager;

use Behat\Mink\Element\DocumentElement;
use Behat\Mink\Exception\DriverException;
use Behat\Mink\Mink;
use Drupal\Driver\AuthenticationDriverInterface;
Expand Down Expand Up @@ -52,6 +53,14 @@ public function __construct(Mink $mink, DrupalUserManagerInterface $drupalUserMa
$this->setDrupalParameters($drupalParameters);
}

/**
* Helper to get the element we want to use for submitting the login form.
*/
protected function getLoginSubmitElement(DocumentElement $element)
{
return $element->findButton($this->getDrupalText('log_in'));
}

/**
* {@inheritdoc}
*/
Expand All @@ -64,7 +73,7 @@ public function logIn(\stdClass $user)
$element = $this->getSession()->getPage();
$element->fillField($this->getDrupalText('username_field'), $user->name);
$element->fillField($this->getDrupalText('password_field'), $user->pass);
$submit = $element->findButton($this->getDrupalText('log_in'));
$submit = $this->getLoginSubmitElement($element);
if (empty($submit)) {
throw new \Exception(sprintf("No submit button at %s", $this->getSession()->getCurrentUrl()));
}
Expand Down

0 comments on commit 5deb56c

Please sign in to comment.