Skip to content

Commit

Permalink
Add a helper for the getting of the login submit element
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Nov 22, 2022
1 parent af159e0 commit 9d781dc
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 9d781dc

Please sign in to comment.