parameters = $parameters; if (isset($parameters['varbase_users'])) { $this->varbaseUsers = $parameters['varbase_users']; foreach ($parameters['varbase_users'] as $varbaseUsername => $varbaseUser) { $this->users[$varbaseUsername] = $varbaseUser['password']; } } else { throw new \Exception('behat.yml config files should include "varbase_users" property.'); } } /** * Clean users. */ public function cleanUsers() { } /** * 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 "Content admin" * * @Given /^I am a logged in user with (?:|the )"(?P[^"]*)"(?:| user)$/ * @Then /^I login with (?:|the )"(?P[^"]*)"(?:| user)$/ */ 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); $this->iScrollToBottom(); $this->iWaitForSeconds(2); $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."); } } /** * Authenticate a user with a given username and password on the spot. * * Varbase Context #varbase. * * 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[^"]*)" and password "(?P[^"]*)"$/ */ public function iAmLoggedInUserWithTheUsernameAndPassword($username, $password) { // Logout if I am logged in. if ($this->loggedIn()) { $this->logout(); } // Login with the. $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); $this->iScrollToBottom(); $this->iWaitForSeconds(2); $submit = $page->findButton('op'); $submit->click(); } } /** * Logout from the current session. * * Varbase Context #varbase. * * Example: When I logout. * * @When /^I logout$/ */ public function iLogout() { // Logout if I am logged in. if ($this->loggedIn()) { $this->logout(); } } /** * Navigate directly to an external web site. * * Varbase Context #varbase. * * Example: When I go to "https://www.google.com" website. * * @When /^I go to "(?P[^"]*)" website$/ */ public function iGoToWebsite($domain) { $this->getSession()->visit($domain); } /** * Wait for seconds before going to the next step. * * Varbase Context #varbase. * * Example 1: And wait for "1" second * Example 2: When I wait for "5" seconds * Example 3: And wait 1 second * Example 4: When I wait for 60 seconds * Example 5: And wait 1s * Example 6: When I wait for 60s. * * @When /^(?:|I )wait (?:|for )"(?P\d+)" second(?:|s)$/ * @When /^(?:|I )wait (?:|for )(?P\d+) second(?:|s)$/ * @When /^(?:|I )wait (?:|for )(?P\d+)s$/ */ public function iWaitForSeconds($seconds = 1) { $this->getSession()->wait($seconds * 1000); } /** * Wait for minutes before going to the next step. * * Varbase Context #varbase. * * Example 1: And I wait for "1" minute * Example 2: When I wait for "2" minutes * Example 3: And wait 1 minute * Example 4: When I wait for 3 minutes * Example 5: And wait 1m * Example 6: When I wait for 3m. * * @When /^(?:|I )wait (?:|for )"(?P\d+)" minute(?:|s)$/ * @When /^(?:|I )wait (?:|for )(?P\d+) minute(?:|s)$/ * @When /^(?:|I )wait (?:|for )(?P\d+)m$/ */ public function iWaitForMinutes($minutes = 1) { $this->getSession()->wait($minutes * 60 * 1000); } /** * Wait max of seconds for the page to be ready and loaded. * * Varbase Context #varbase. * * Example 1: And wait * Example 2: And I wait * Example 3: And wait for the page * Example 4: And I wait for the page * Example 5: And wait max of 5 seconds * Example 6: And wait max of 5s * Example 7: And I wait max of 5s * Example 8: And I wait max of "5" seconds * Example 9: And I wait max of "5" seconds for the page to be ready and loaded. * * @Given /^(?:|I )wait max of "(?P