mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 15:05:32 +00:00
Support multiple login forms on a page
Thanks to Jeffrey Guo for contributing.
This commit is contained in:
parent
3928c6ecfe
commit
6f0cc7f68e
@ -123,15 +123,22 @@ class LoginContext extends BehatContext
|
|||||||
*/
|
*/
|
||||||
public function stepILogInWith($email, $password)
|
public function stepILogInWith($email, $password)
|
||||||
{
|
{
|
||||||
|
$page = $this->getSession()->getPage();
|
||||||
|
$forms = $page->findAll('css', 'form[action="Security/LoginForm"]');
|
||||||
|
assertNotNull($forms, 'Login form not found');
|
||||||
|
|
||||||
|
// If no login form, go to /security/login page
|
||||||
|
if(count($forms) <= 0 ) {
|
||||||
$c = $this->getMainContext();
|
$c = $this->getMainContext();
|
||||||
$loginUrl = $c->joinUrlParts($c->getBaseUrl(), $c->getLoginUrl());
|
$loginUrl = $c->joinUrlParts($c->getBaseUrl(), $c->getLoginUrl());
|
||||||
|
|
||||||
$this->getSession()->visit($loginUrl);
|
$this->getSession()->visit($loginUrl);
|
||||||
|
|
||||||
$page = $this->getSession()->getPage();
|
$page = $this->getSession()->getPage();
|
||||||
|
$forms = $page->findAll('css', 'form[action="Security/LoginForm"]');
|
||||||
|
}
|
||||||
|
|
||||||
$form = $page->find('css', 'form[action="Security/LoginForm"]');
|
$foundForm = false;
|
||||||
assertNotNull($form, 'Login form not found');
|
foreach($forms as $form) {
|
||||||
|
if(!$form->isVisible()) continue;
|
||||||
|
|
||||||
$emailField = $form->find('css', '[name=Email]');
|
$emailField = $form->find('css', '[name=Email]');
|
||||||
$passwordField = $form->find('css', '[name=Password]');
|
$passwordField = $form->find('css', '[name=Password]');
|
||||||
@ -144,6 +151,12 @@ class LoginContext extends BehatContext
|
|||||||
$emailField->setValue($email);
|
$emailField->setValue($email);
|
||||||
$passwordField->setValue($password);
|
$passwordField->setValue($password);
|
||||||
$submitButton->press();
|
$submitButton->press();
|
||||||
|
|
||||||
|
$foundForm = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue($foundForm, 'Found login form');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user