You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?phpuseBehat\Behat\Context\SnippetAcceptingContext;
useBehat\Behat\Hook\Scope\AfterStepScope;
useBehat\Behat\Hook\Scope\AfterScenarioScope;
useBehat\Behat\Hook\Scope\BeforeScenarioScope;
useBehat\Gherkin\Node\TableNode;
useBehat\Mink\Exception\ExpectationException;
useDrupal\DrupalExtension\Context\DrupalContext;
useDrupal\DrupalExtension\Context\MinkContext;
useDrupal\DrupalExtension\Context\RawDrupalContext;
/** * Defines application features from the specific context. */classFeatureContextextendsRawDrupalContextimplementsSnippetAcceptingContext
{
/** @var String The directory to save screenshots and html to. */private$debug_dir;
/** * @var MinkContext */private$minkContext;
/** * @var DrupalContext */private$drupalContext;
/** * @var array of tid's for Forums created in tests. */private$forums = [];
/** * Initializes context. */publicfunction__construct()
{
$this->debug_dir = __DIR__ . '/../../debug/';
}
/** * @AfterStep * * @param \Behat\Behat\Hook\Scope\AfterStepScope $event */publicfunctionprintLastResponseOnError(AfterStepScope$event)
{
if (!$event->getTestResult()->isPassed()) {
$this->saveHtml();
}
}
/** * Grab the html of the page and save it. * * @Then save the html for the page * @Then save the html for the page with prefix :prefix * * @param string $prefix A string to prepend to the filename. */publicfunctionsaveHtml($prefix = 'html') {
$html_data = $this->getSession()->getDriver()->getContent();
$filename = $this->debug_dir . $prefix . '-' . time() . '.html';
file_put_contents($filename, $html_data);
}
/** * Grab a screenshot of the page and save it. * * @Then save a screenshot of the page * @Then save a screenshot of the page with prefix :prefix * * @param string $prefix A string to prepend to the filename. */publicfunctionsaveAScreenshot($prefix = 'screenshot')
{
$screenshot = $this->getSession()->getDriver()->getScreenshot();
$filename = $this->debug_dir . $prefix . '-' . time() . '.png';
file_put_contents($filename, $screenshot);
}
/** * @BeforeScenario */publicfunctiongatherContexts(BeforeScenarioScope$scope)
{
$environment = $scope->getEnvironment();
$this->drupalContext = $environment->getContext(DrupalContext::class);
$this->minkContext = $environment->getContext(MinkContext::class);
}
/** * Click on the element with the provided xpath query * * @When /^(?:|I )click on the element "([^"]*)"$/ */publicfunctioniClickOnTheElement($arg)
{
$session = $this->getSession(); // get the mink session$element = $session->getPage()->find('css', $arg); // runs the actual query and returns the element// errors must not pass silentlyif (null === $element) {
thrownew \InvalidArgumentException(sprintf('Could not evaluate CSS selector: "%s"', $arg));
}
// ok, let's click on it$element->click();
}
/** * Some forms do not have a Submit button just pass the ID * * @Given /^I submit the form with id "([^"]*)"$/ */publicfunctioniSubmitTheFormWithId($arg) {
$session = $this->getSession();
$element = $session->getPage()->find('css', $arg);
if($element) {
$element->submit();
} else {
thrownewException('Element not found');
}
}
/** * @param int $seconds * Amount of seconds when nothing to happens. * * @Given /^(?:|I )wait (\d+) seconds$/ */publicfunctionwaitSeconds($seconds)
{
sleep($seconds);
}
The text was updated successfully, but these errors were encountered:
Some of these things will be useful...
The text was updated successfully, but these errors were encountered: