Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPWebDriver: Wait for login form elements #65

Merged
merged 1 commit into from
Mar 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/Codeception/Module/WPWebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,47 @@ protected function configBackCompat()
}
}

/**
* Goes to the login page and logs in as the site admin.
*
* @param int $time
*
* @return array An array of login credentials and auth cookies.
*/
public function loginAsAdmin($time = 10)
{
return $this->loginAs($this->config['adminUsername'], $this->config['adminPassword'], $time);
}

/**
* Goes to the login page, wait for the login form and logs in using the given credentials.
*
* @param string $username
* @param string $password
* @param int $time
*
* @return array An array of login credentials and auth cookies.
*/
public function loginAs($username, $password, $time = 10)
{
$this->amOnPage($this->loginUrl);

$this->waitForElement('#user_login', $time);
$this->waitForElement('#user_pass', $time);
$this->waitForElement('#wp-submit', $time);

$this->fillField('#user_login', $username);
$this->fillField('#user_pass', $password);
$this->click('#wp-submit');

return [
'username' => $username,
'password' => $password,
'authCookie' => $this->grabWordPressAuthCookie(),
'loginCookie' => $this->grabWordPressLoginCookie()
];
}

/**
* Returns all the cookies whose name matches a regex pattern.
*
Expand Down