These are chat archives for Behat/Behat

4th
Jul 2017
SamyOteroGlez
@SamyOteroGlez
Jul 04 2017 13:38
@toscanoX
Can you share your ContextClass?
also, try to run ir without the browser, (remove @javascript tag from your feature file)
SamyOteroGlez
@SamyOteroGlez
Jul 04 2017 13:52
it*
Jesús Toscano Del Río
@toscanoX
Jul 04 2017 15:30

This is all I have

behat.yml

default:
  suites:
    default:
      contexts:
        - Drupal\DrupalExtension\Context\DrupalContext
        - Drupal\DrupalExtension\Context\MarkupContext
        - Drupal\DrupalExtension\Context\MessageContext
        - Drupal\DrupalExtension\Context\DrushContext
        - Drupal\FeatureContext
  extensions:
    Behat\MinkExtension:
      goutte: ~
      default_session: selenium2
      selenium2: 
        wd_host: http://127.0.0.1:4444/wd/hub
      base_url: http://127.0.0.1:8081
    Drupal\DrupalExtension:
      blackbox: ~

Examples.feature

@example
Feature: Login test
in order to test the proper login
Scenario: Login Test
Given I am on the homepage
Then I should see the text "Welcome to drupal"

FeatureContext.php

<?php

namespace Drupal;

use Drupal\DrupalExtension\Context\RawDrupalContext;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Tester\Exception\PendingException;
use Behat\Mink\Driver\Selenium2Driver;
use Behat\MinkExtension\ServiceContainer\Driver;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;

/**
 * FeatureContext class defines custom step definitions for Behat.
 */
class FeatureContext extends RawDrupalContext implements SnippetAcceptingContext {

  /**
   * Every scenario gets its own context instance.
   *
   * You can also pass arbitrary arguments to the
   * context constructor through behat.yml.
   */
  public function __construct() {

  }
  /**
     * @Given I am on the homepage
     */
    public function iAmOnTheHomepage()
    {
        throw new PendingException();
    }

    /**
     * @Then I should see the text :arg1
     */
    public function iShouldSeeTheText($arg1)
    {
        throw new PendingException();
    }
}

result:

$ ../../vendor/bin/behat
@example
Feature: Login test
in order to test the proper login
Scenario: Login Test # features/Examples.feature:5
Given I am on the homepage # Drupal\FeatureContext::iAmOnTheHomepage()
TODO: write pending definition
Then I should see the text "Welcome to drupal" # Drupal\FeatureContext::iShouldSeeTheText()
SamyOteroGlez
@SamyOteroGlez
Jul 04 2017 21:05
@toscanoX I believe you dont have any error, that is expected behaviour.
try to write something like this

public function iAmOnTheHomepage()
    {
        return true;
    }
you need to implement the test
SamyOteroGlez
@SamyOteroGlez
Jul 04 2017 21:12
/**
     * @Given I am on the homepage
     */
    public function iAmOnTheHomepage()
    {
        $this->visit('your-url');
    }

    /**
     * @Then I should see the text :arg1
     */
    public function iShouldSeeTheText($arg1)
    {
        $this->assertPageContainsText($arg1);
    }
something like this
I would recommend to change $arg1 to $message or $text, to be more human readable
/**
     * @Then I should see the text :text
     */
    public function iShouldSeeTheText($text)
    {
        $this->assertPageContainsText($text);
    }
that's old but could help, also the behat official documentation should help too