public function VarbaseContext::iAmloggedInUserWithTheUser in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.8
Same name and namespace in other branches
- 8.4 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iAmloggedInUserWithTheUser()
- 8.5 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iAmloggedInUserWithTheUser()
- 8.6 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iAmloggedInUserWithTheUser()
- 8.7 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iAmloggedInUserWithTheUser()
- 9.0.x tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iAmloggedInUserWithTheUser()
Authenticate a user with password from varbase configuration.
Varbase Context #varbase. If you want to see the list of users or add yours you can go and edit the behat.varbase.yml file under the varbase_users list.
Example: I am a logged in user with the username "test_content_admin"
@Given /^I am a logged in user with (?:|the )"(?P<username>[^"]*)"(?:| user)$/ @Then /^I login with (?:|the )"(?P<username>[^"]*)"(?:| user)$/
File
- tests/
features/ bootstrap/ VarbaseContext.php, line 73
Class
- VarbaseContext
- Defines application features from the specific context.
Code
public function iAmloggedInUserWithTheUser($username) {
if (isset($this->users[$username])) {
try {
$password = $this->users[$username];
} catch (Exception $e) {
throw new \Exception("Password not found for '{$username}'.");
}
if ($this
->loggedIn()) {
$this
->logout();
}
$page = $this
->getSession()
->getPage();
$this
->getSession()
->visit($this
->locatePath('/user/login'));
$page
->fillField('edit-name', $username);
$page
->fillField('edit-pass', $password);
$submit = $page
->findButton('op');
$submit
->click();
}
else {
throw new \Exception("The '{$username}' user name is wrong or it was not listed in the list of default testing users.");
}
}