You are here

public function VarbaseContext::iAmloggedInUserWithTheUser in Varbase: The Ultimate Drupal CMS Starter Kit (Bootstrap Ready) 8.7

Same name and namespace in other branches
  1. 8.8 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iAmloggedInUserWithTheUser()
  2. 8.4 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iAmloggedInUserWithTheUser()
  3. 8.5 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iAmloggedInUserWithTheUser()
  4. 8.6 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iAmloggedInUserWithTheUser()
  5. 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();
}