I recently began learnign Behat and performed some basic tests successfully. Now I was to perform test more suffisticated tests such as determining the current page url but I get the following error when I execute behat:
When I visit the drupal user registration page "https://ift.tt/3bvN94W" # FeatureContext::iVisitTheDrupalUserRegistrationPage() Mink instance has not been set on Mink context class. Have you enabled the Mink Extension? (RuntimeException)
Feature: Testing Test site
Testing pages etc on the Test site
Scenario:
Given I an an anonymous user
When I visit the drupal user registration page "https://test.server.co.uk/store/user/register"
And I press "Create new account"
Then I should see "Username field is required" in page output.
Then I should see "E-mail address field is required" in page output.
Then I should see "Password field is required" in page output.
Then I should see "Surname field is required" in page output.
Then I should see "Address Line 1 field is required" in page output.
Then I should see "County / State field is required" in page output.
Then I should see "First name field is required" in page output.
Then I should see "Postcode field is required" in page output.
Then I should see "Telephone field is required" in page output.
Then I should see "Town field is required" in page output.
For which I have the following php code :
<?php
use Behat\Behat\Context\Context;
use Behat\Behat\Tester\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\RawMinkContext;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends RawMinkContext implements Context
{
private $client;
private $response;
public function checkContent($needle='', $haystack='') {
return strpos($haystack, $needle);
}
/**
* 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->client = new \GuzzleHttp\Client(['base_uri' => 'https://test.server.co.uk/']);
}
/**
* @Given I an an anonymous user
*/
public function iAnAnAnonymousUser()
{
$this->response = $this->client->get('/');
$responseCode = $this->response->getStatusCode();
if( $responseCode != 200 )
throw new Exception('Cannot reach site');
return true;
}
/**
* @When I visit the drupal user registration page :registrationUrl
*/
public function iVisitTheDrupalUserRegistrationPage($registrationUrl)
{
print "--------------------TESTING---------------------- : " . $this->getSession()->getCurrentUrl();
}
/**
* @When I press :arg1
*/
public function iPress($arg1)
{
return true;
// $this->getSession()->getPage()->find('css', '#edit-submit')->submit();
}
/**
* @Then I should see :errors in page output.
*/
public function iShouldSeeInPageOutput($errors)
{
}
}
In the iVisitTheDrupalUserRegistrationPage function I am trying to get the current url which results in the error I indicated above.
I am not sure what the source of the error is. This post suggests the issue is to do with my behat.yml setup, included below, but the issue still persists after I made corrections :
default:
suites:
default:
contexts:
- FeatureContext
- AnotherContext
extensions:
Behat\MinkExtension:
base_url: https://test.server.co.uk
sessions:
default:
goutte: ~
And, I am using the following composer.json configuration :
{
"require-dev": {
"behat/behat": "~3.8",
"behat/mink-extension": "~2.3",
"behat/mink-goutte-driver": "~1.2",
"behat/mink-selenium2-driver": "~1.4",
"guzzlehttp/guzzle" : "~6.0",
"drupal/drupal-extension" : "~4.1"
},
"config": {
"bin-dir": "bin/"
}
}
Can anyone help me understand what I'm missing or doing wrong, please ?
Aucun commentaire:
Enregistrer un commentaire