You are here

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

Same name and namespace in other branches
  1. 8.8 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iAmLoggedInUserWithTheUsernameAndPassword()
  2. 8.4 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iAmLoggedInUserWithTheUsernameAndPassword()
  3. 8.6 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iAmLoggedInUserWithTheUsernameAndPassword()
  4. 8.7 tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iAmLoggedInUserWithTheUsernameAndPassword()
  5. 9.0.x tests/features/bootstrap/VarbaseContext.php \VarbaseContext::iAmLoggedInUserWithTheUsernameAndPassword()

#varbase : To authenticate a user with a gavin username and password on the spot.

Example: I am a logged in user with the username "testing" and password "testing user password"

@Given /^I am a logged in user with (?:|the )username "(?P<username>[^"]*)" and password "(?P<password>[^"]*)"$/

File

tests/features/bootstrap/VarbaseContext.php, line 87

Class

VarbaseContext
Defines application features from the specific context.

Code

public function iAmLoggedInUserWithTheUsernameAndPassword($username, $password) {

  // Logout if I am logged in.
  if ($this
    ->loggedIn()) {
    $this
      ->logout();
  }

  // Login with the
  $element = $this
    ->getSession()
    ->getPage();
  $this
    ->getSession()
    ->visit($this
    ->locatePath('/user'));
  $element
    ->fillField('Username', $username);
  $element
    ->fillField('Password', $password);
  $submit = $element
    ->findButton('Log in');
  $submit
    ->click();
}