Created
March 20, 2019 19:20
-
-
Save luukverhoeven/3e1a3c3c76bf08a2fc91aad9c318781b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Behat\Behat\Context\Context; | |
use Behat\Behat\Hook\Scope\AfterScenarioScope; | |
use Behat\Behat\Hook\Scope\BeforeScenarioScope; | |
use Behat\Behat\Tester\Exception\PendingException; | |
use Behat\Gherkin\Node\PyStringNode; | |
use Behat\Gherkin\Node\TableNode; | |
use Facebook\WebDriver\Remote\DesiredCapabilities; | |
use Facebook\WebDriver\Remote\RemoteWebDriver; | |
use Facebook\WebDriver\WebDriverBy; | |
use Facebook\WebDriver\WebDriverExpectedCondition; | |
use Facebook\WebDriver\Exception\NoAlertOpenException; | |
/** | |
* Defines application features from the specific context. | |
*/ | |
class FeatureContext extends MainContext implements Context { | |
/** | |
* Initializes context. | |
* | |
* Every scenario gets its own context instance. | |
* You can also pass arbitrary arguments to the | |
* context constructor through behat.yml. | |
*/ | |
public function __construct() { | |
$this->baseUrl = 'http://somedomain.com'; | |
// Load the main construct. | |
parent::__construct(); | |
} | |
/** | |
* @Then There should be no debug traces | |
*/ | |
public function thereShouldBeNoDebugTraces() { | |
$this->iShouldNotSee('xdebug-error'); | |
$this->iShouldNotSee('Call Stack'); | |
$this->iShouldNotSee('Debug info'); | |
$this->iShouldNotSee('debugging()'); | |
} | |
/** | |
* @Given I login as :username with password :password | |
* | |
* @param string $username | |
* @param string $password | |
* | |
* @throws Exception | |
* @throws \Facebook\WebDriver\Exception\NoSuchElementException | |
* @throws \Facebook\WebDriver\Exception\TimeOutException | |
*/ | |
public function iLoginAsWithPassword($username = '', $password = '') { | |
if (!empty($this->webDriver)) { | |
/** @var RemoteWebDriver $webDriver */ | |
foreach ($this->webDriver as $browser => $webDriver) { | |
$webDriver->get($this->baseUrl . '/login/'); | |
$this->thereShouldBeNoDebugTraces(); | |
$usernameElement = $webDriver->findElement(WebDriverBy::name('username')); | |
if ($usernameElement) { | |
$usernameElement->sendKeys($username); | |
} | |
$passwordElement = $webDriver->findElement(WebDriverBy::name('password')); | |
if ($passwordElement) { | |
$passwordElement->sendKeys($password); | |
$passwordElement->submit(); | |
} | |
$webDriver->wait(30, 250)->until( | |
WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::name('code')) | |
); | |
$this->makeScreenShot('-LoginAsWithPassword-after', $browser, $webDriver); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment