public function VarbaseContext::iAmloggedInUserWithTheUser in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.7
Same name and namespace in other branches
- 8.8 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iAmloggedInUserWithTheUser()
- 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()
- 9.0.x tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iAmloggedInUserWithTheUser()
#varbase : To authenticate a user with password from varbase configuration. 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 61
Class
- VarbaseContext
- Defines application features from the specific context.
Code
public function iAmloggedInUserWithTheUser($username) {
try {
$password = $this->users[$username];
} catch (Exception $e) {
throw new Exception("Password not found for '{$username}'.");
}
if ($this
->loggedIn()) {
$this
->logout();
}
$element = $this
->getSession()
->getPage();
$this
->getSession()
->visit($this
->locatePath('/user'));
$element
->fillField('edit-name', $username);
$element
->fillField('edit-pass', $password);
$submit = $element
->findButton('op');
$submit
->click();
}