Support multiple login forms on a page

Thanks to Jeffrey Guo for contributing.
This commit is contained in:
Ingo Schommer 2014-04-07 13:03:40 +12:00
parent 3928c6ecfe
commit 6f0cc7f68e

View File

@ -123,15 +123,22 @@ class LoginContext extends BehatContext
*/
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();
$loginUrl = $c->joinUrlParts($c->getBaseUrl(), $c->getLoginUrl());
$this->getSession()->visit($loginUrl);
$page = $this->getSession()->getPage();
$forms = $page->findAll('css', 'form[action="Security/LoginForm"]');
}
$form = $page->find('css', 'form[action="Security/LoginForm"]');
assertNotNull($form, 'Login form not found');
$foundForm = false;
foreach($forms as $form) {
if(!$form->isVisible()) continue;
$emailField = $form->find('css', '[name=Email]');
$passwordField = $form->find('css', '[name=Password]');
@ -144,6 +151,12 @@ class LoginContext extends BehatContext
$emailField->setValue($email);
$passwordField->setValue($password);
$submitButton->press();
$foundForm = true;
break;
}
assertTrue($foundForm, 'Found login form');
}
/**