public function VarbaseContext::iAmloggedInUserWithTheUser in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 9.0.x
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()
- 8.7 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 74
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();
}
$this
->getSession()
->visit($this
->locatePath('/user/login'));
$page = $this
->getSession()
->getPage();
if ($this
->matchingElementAfterWait('css', '[data-drupal-selector="edit-name"]', 6000)) {
$page
->fillField('name', $username);
$page
->fillField('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.");
}
}