Code Monkey home page Code Monkey logo

contexts's Introduction

Behatch contexts

Build status Scrutinizer Code Quality Code Coverage SensioLabsInsight

Behatch contexts provide most common Behat tests.

Installation

This extension requires:

  • Behat 3+
  • Mink
  • Mink extension

Project dependency

  1. Install Composer
  2. Require the package with Composer:
$ composer require --dev behatch/contexts
  1. Activate extension by specifying its class in your behat.yml:
# behat.yml
default:
    # ...
    extensions:
        Behatch\Extension: ~

Project bootstraping

  1. Download the Behatch skeleton with composer:
$ php composer.phar create-project behatch/skeleton

Browser, json, table and rest step need a mink configuration, see Mink extension for more information.

Usage

In behat.yml, enable desired contexts:

default:
    suites:
        default:
            contexts:
                - behatch:context:browser
                - behatch:context:debug
                - behatch:context:system
                - behatch:context:json
                - behatch:context:table
                - behatch:context:rest
                - behatch:context:xml

Examples

This project is self-tested, you can explore the features directory to find some examples.

Configuration

  • browser - more browser related steps (like mink)
    • timeout - default timeout
  • debug - helper steps for debugging
    • screenshotDir - the directory where store screenshots
  • system - shell related steps
    • root - the root directory of the filesystem
  • json - JSON related steps
    • evaluationMode - javascript "foo.bar" or php "foo->bar"
  • table - play with HTML the tables
  • rest - send GET, POST, ... requests and test the HTTP headers
  • xml - XML related steps

Configuration Example

For example, if you want to change default directory to screenshots - you can do it this way:

default:
    suites:
        default:
            contexts:
                - behatch:context:debug:
                    screenshotDir: "var"

Translation

See more information on Transifex.com

contexts's People

Contributors

alanpoulain avatar areyt avatar badaz avatar bendavies avatar blazarecki avatar bocharsky-bw avatar chorry avatar davialexandre avatar dunglas avatar emmanuelvella avatar gabrielcw avatar gimler avatar gpenverne avatar iamluc avatar ilovemistakes avatar jdecool avatar jdeniau avatar kbsali avatar matts2cant avatar nicoosh avatar pborreli avatar razbakov avatar ricoli avatar sanpii avatar stephpy avatar stof avatar tekante avatar tophsic avatar tyx avatar wadjei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

contexts's Issues

Make Contexts extandable

Could it be possible to pass private properties and methods from private to protected so that we can inherit of those contexts?

Require php 5.4

Php 5.4 allow some improvements:

  • New array syntax
  • Share methods via traits (ie: HtmlTrait for countElements and AsssertTrait for assertions)

Impossible to use context behatch:json or rest without triggering an error

Hi,

When I use contexts : behatch:json or behatch:rest I got :

[Symfony\Component\Debug\Exception\ContextErrorException]             
  Warning: preg_match() expects parameter 2 to be string, object given 

As soon as I remove them, the error disappear.
Has the documentation some step missing ?

Using Behat 3+ :

        "behat/behat": "3.0.*@dev",
        "behat/symfony2-extension": "dev-master",
        "behat/mink-extension": "2.0.*@dev",
        "behat/common-contexts": "1.2.*@dev",
        "sensiolabs/behat-page-object-extension": "2.0.*@dev",
        "vipsoft/doctrine-data-fixtures-extension": "3.0.*@dev",
        "behatch/contexts": "dev-master",
        "behat/mink": "dev-master",
        "behat/mink-browserkit-driver": "dev-master",
        "behat/mink-goutte-driver": "dev-master",
        "behat/mink-selenium2-driver": "1.2.*@dev",
        "behat/web-api-extension": "1.0.*@dev"

with configuration :

default:
    autoload: %paths.base%/features/Context
    extensions:
        Behat\MinkExtension:
            base_url:   http://xxx.xxxx.dev/app_test.php/
            files_path: app/features/files
            default_session:    goutte
            javascript_session: selenium2
            goutte:    ~
            selenium2: ~
        Behat\Symfony2Extension:
            kernel:
                env:   test
                debug: true
        VIPSoft\DoctrineDataFixturesExtension\Extension:
            lifetime:    feature
            autoload:    false
            directories:
                - app/features/Context/Fixtures
            fixtures:    ~
            migrations: ~
        Behat\WebApiExtension:
            base_url: http://xxx.xxx.dev/app_test.php/
        Sanpi\Behatch\Extension: ~
    suites:
        default:
            contexts:
                - Context\FeatureContext
                - Behat\WebApiExtension\Context\WebApiContext
                - behatch:table
                - behatch:json
                - behatch:rest

    translation:
        locale: en

Adding headers: Unable to access the response before visiting a page

Attempting to run this scenario:

Feature: Creating new sports
  Scenario: Successful creation
    Given I add "Accept" header equal to "application/json"

With no other steps, I get this exception:

Feature: Creating new sports

  Scenario: Successful creation                                  # features/functional/sports/store.feature:3
    Given I add "Accept" header equal to "application/json"      # Sanpi\Behatch\Context\RestContext::iAddHeaderEqualTo()



  [Behat\Mink\Exception\DriverException]
  Unable to access the response before visiting a page

So for some reason I'm getting an exception when trying to set up headers prior to sending the request - it seems like its trying to access the response for some reason. I've been scratching my head over this for a while, can't see what I'm doing wrong.

Move the contexts configuration into the context constructors and make it easier to use them (3.0)

You can simplify things even further in 3.0:

  • You can move away from custom configuration with Behat/Behat#446
  • Also, by implementing your own custom ClassResolver, you can simplify contexts referencing

Basically, those things put together will allow you to do something like this:

default:
    suites:
        core:
            contexts:
                behatch:debug:
                    screenshotDir: '/tmp'

behatch:debug will be resolved to Sanpi\Behatch\Context\DebugContext via your custom ClassResolver. Then screenshotDir will be passed to it as a simple constructor argument (matching by name).

Improper use of Driver

I've encountered a problem that rises when Behatch is used with drivers other than Goutte.
Namely, when in e.g. RestContext there's a call:

$this->getSession()->getDriver()->getClient()
the problem here is that getDriver() returns an instance of a DriverInterface. But DriverInterface does not specify getClient() method. Actually, getClient() method is defined in BrowserKitDriver. Thus, Behatch doesn't mind working with Selenium2, Zombie etc., but it actually can't properly work with them, as they only extend CoreDriver, while it works ok with Goutte (which is instance of BrowserKit).

I guess you should either define that you expect $this->getSession()->getDriver() returns instance of BrowserKit, or add support for true DriverInterface.

TableContext: make the "Testing rows" step work with a subset of columns

During testing some CRUD listing pages, I only want to test some cells, not all of them.
I want to test only the data cells.

Because most of the time the last cell is a list of action links.

From the original fixtures/www/table/index.html fixture file, I want the following scenario to be valid.

Scenario: Partial Testing rows
        Given I am on "/table/index.html"

        And the data in the 1st row of the "table" table should match:
            | col1   |
            | Lorem  |

Stopping the session in a hard way at the end of the scenario should be opt-in

Currently, using the BrowserContext will always force stopping the session at the end of the scenario because of https://github.com/sanpii/behatch-contexts/blob/67de9a82d08e7355628b8d1a707bddec13f945f2/src/Context/BrowserContext.php#L21

But this is a bad idea:

  • given that the logic is not written in a smart way, if the session is already stopped, it will start it and close it immediately. This is wasting time (especially when using Selenium2 and this involves launching Firefox and closing it)
  • Mink is able to reset the session without closing it entirely (and btw, the Mink 1.6 release ensures a consistent behavior across drivers for that, allowing us to fix a few bugs in drivers). This allows running much faster than stopping the session entirely, especially when using Selenium (as it avoids closing Firefox and relaunching it). I already got many complaints about this from people requesting to reuse the firefox window, while Mink already supports it since years when your context is not registered.

I don't know why you force isolating each scenario entirely (MinkExtension already provides a way to do it for scenarios needing it to work btw), but it should not be forced by default for anyone using your context (it is not even documented)

Are 'stale element reference: element is not attached to the page document' issues still reported?

On some older code I've noticed that 'stale element reference: element is not attached to the page document' exceptions were raised by iWaitSecondsUntilISeeInTheElement.

Was there any work done recently for this issue?

My solution to this problem was to overwrite iWaitSecondsUntilISeeInTheElement with this implementation. But if this is not a current issue then I'm not going to commit it:

   /**
     * Checks, that the element contains specified text after timeout
     * Overwrites base class to try to fix "stale element reference: element is not attached to the page document" errors
     *
     * Parent method was caching the element
     */
    public function iWaitSecondsUntilISeeInTheElement($seconds, $text, $element)
    {
        $expected = str_replace('\\"', '"', $text);
        $startTime = time();
        do {
            $now = time();

            if (is_string($element)) {
                $node = $this->getSession()->getPage()->find('css', $element);
            }
            else {
                $node = $element;
            }

            $exception = null;

            try {
                $actual   = $node->getText();
                $this->assertContains($expected, $actual);
            }
            catch (Exception $e) {
                $exception = $e;
                if ($now - $startTime >= $seconds) {
                    $message = sprintf('The text "%s" was not found after a %s seconds timeout', $expected, $seconds);
                    throw new ResponseTextException($message, $this->getSession(), $e);
                }
            }

            if ($exception == null) {
                break;
            }
            usleep(200);

        } while ($now - $startTime < $seconds);
    }

Catchable Fatal Error: Object of class stdClass could not be converted to string

Hello, I get this error
Catchable Fatal Error: Object of class stdClass could not be converted to string in vendor\sanpi\behatch-contexts\src\Sanpi\Behatch\Context\JsonContext.php line 129
when I try to parse JSON responce with
And the JSON node "root.errors" should not exist
My JSON response looks like
{
"code":400,
"message":"Validation Failed",
"errors":
{"children":
{"id":[],"firstName":[],"lastName":[],"username":[],"email":{"errors":["..."]}
}
}
}
So, by this code
try {
$actual = $this->evaluateJson($json, $node);
}
catch (\Exception $e) {
}

    if ($e === null) {
        throw new \Exception(sprintf("The node '%s' exists and contains '%s'.", $node , $actual));
    }

we got at $actual var node tree "errors", and later you try to convert stdClass to string at Exception text.
so the simplest way to fix this is wrap $actual with print_r like this print_r($actual,true)

This exception appear at some other rows.
Thank you, and excuse me for my english.

Can't get XML elements with default namespace

Hi,
When there is an element with default namespace that doesn't have a prefix, XMLContext.php can not find it. This is a bug in xpath itself when there is no prefix. Check the first answer:
XPath in SimpleXML for default namespaces

So I have xml similar to the the following:

<?xml version="1.0" encoding="UTF-8"?>
<University>
      <ContactInformation>
            <Name>University Name</Name>
            <Address>University Address</Address>
      </ContactInformation>
      <body>
            <Colleges xmlns="http://ws.someuni.com/ver1">
                  <Entries countEntries="4">
                        <college name="college1"/>
                        <college name="college2"/>
                        <college name="college3"/>
                        <college name="college4"/>
                  </Entries>
            </Colleges>
      </body>
</University>

If I try to get countEntries attribute or Entries element using behatch context, it will not return anything.
I have tried to use rootns as default namespace but that didn't work either.

I made a fix to this issue by adding namespace(s) with counters inside getNamesapces method.

// file = Sanpi\Behatch\Context\XmlContext
private function getNamespaces(\DOMDocument $dom = null)
    {
        $xml = $this->getSimpleXml($dom);
        $namespaces = $xml->getNamespaces(true);
        // fix
        $counter = 0;
        foreach($namespaces as $key => $value ){
            if(empty($key)) {
                $counter++;
                $correctedNamespaces['ns'.$counter] = $value;
            } else {
                $correctedNamespaces[$key] = $value;
            }
        }
        return $correctedNamespaces;
    }

Then to get countEntries you can use the following phrase:

 Then the XML attribute "countEntries" on element "//University/body/ns1:Colleges/ns1:Entries" should be equal to "4"

Bug on RestContext

On the RestContext, we need to add quotes on the following to steps around the method name:

  • @given /^I send a (?P[A-Z]+) request on "(?P[^"]*)"$/
  • @given /^I send a (?P[A-Z]+) request on "(?P[^"]*)" with parameters:$/

If we do not do it, behat does not catch it is a parameter. Correct me if I am wrong.

It would be nice to have a step to assert the reason phrase, like we have for status code. When I get 200 response, I would like also to check the reason phrase is "OK".

Bug in BrowserContext::iShouldSeeTheParameter()

I tried to use the following step definition:

/^(?:|I )shoud see the "(?P[^"]*)" parameter$/

  Scenario:
    Given I am on "/browser/auth.php?logout"
    Then I shoud see the "logout" parameter

And I get a fatal error:

Fatal error: Call to undefined method FeatureContext::getParameter() in ./tests/behat/vendor/sanpi/behatch-contexts/src/Sanpi/Behatch/Context/BrowserContext.php on line 272

Call Stack:
    0.0032     639416   1. {main}() ./tests/behat/vendor/behat/behat/bin/behat:0
    0.0393    2461432   2. Symfony\Component\Console\Application->run() ./tests/behat/vendor/behat/behat/bin/behat:32
    0.0540    3087808   3. Behat\Behat\Console\BehatApplication->doRun() ./tests/behat/vendor/symfony/console/Symfony/Component/Console/Application.php:106
    0.8009   15976472   4. Symfony\Component\Console\Application->doRun() ./tests/behat/vendor/behat/behat/src/Behat/Behat/Console/BehatApplication.php:68
    0.8015   15976608   5. Symfony\Component\Console\Command\Command->run() ./tests/behat/vendor/symfony/console/Symfony/Component/Console/Application.php:193
    1.1383   21343000   6. Behat\Behat\Console\Command\BehatCommand->execute() ./tests/behat/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:240
    1.1396   21361776   7. Behat\Behat\Console\Command\BehatCommand->runFeatures() ./tests/behat/vendor/behat/behat/src/Behat/Behat/Console/Command/BehatCommand.php:128
    1.1761   21776368   8. Behat\Gherkin\Node\AbstractNode->accept() ./tests/behat/vendor/behat/behat/src/Behat/Behat/Console/Command/BehatCommand.php:150
    1.1761   21776368   9. Behat\Behat\Tester\FeatureTester->visit() ./tests/behat/vendor/behat/gherkin/src/Behat/Gherkin/Node/AbstractNode.php:42
    1.1848   21925904  10. Behat\Gherkin\Node\AbstractNode->accept() ./tests/behat/vendor/behat/behat/src/Behat/Behat/Tester/FeatureTester.php:88
    1.1848   21925904  11. Behat\Behat\Tester\ScenarioTester->visit() ./tests/behat/vendor/behat/gherkin/src/Behat/Gherkin/Node/AbstractNode.php:42
   10.9499   22973640  12. Behat\Behat\Tester\ScenarioTester->visitStep() ./tests/behat/vendor/behat/behat/src/Behat/Behat/Tester/ScenarioTester.php:87
   10.9518   22975320  13. Behat\Gherkin\Node\AbstractNode->accept() ./tests/behat/vendor/behat/behat/src/Behat/Behat/Tester/ScenarioTester.php:148
   10.9518   22975320  14. Behat\Behat\Tester\StepTester->visit() ./tests/behat/vendor/behat/gherkin/src/Behat/Gherkin/Node/AbstractNode.php:42
   10.9521   22975320  15. Behat\Behat\Tester\StepTester->executeStep() ./tests/behat/vendor/behat/behat/src/Behat/Behat/Tester/StepTester.php:95
   10.9688   22976136  16. Behat\Behat\Tester\StepTester->executeStepDefinition() ./tests/behat/vendor/behat/behat/src/Behat/Behat/Tester/StepTester.php:126
   10.9689   22976136  17. Behat\Behat\Definition\Annotation\Definition->run() ./tests/behat/vendor/behat/behat/src/Behat/Behat/Tester/StepTester.php:157
   10.9691   22977544  18. call_user_func_array() ./tests/behat/vendor/behat/behat/src/Behat/Behat/Definition/Annotation/Definition.php:155
   10.9691   22978032  19. Sanpi\Behatch\Context\BrowserContext->iShouldSeeTheParameter() ./tests/behat/vendor/behat/behat/src/Behat/Behat/Definition/Annotation/Definition.php:0

The step is defined in Sanpi\Behatch\Context\BrowserContext::iShouldSeeTheParameter() and the error comes from this line:

$this->getMainContext()->getParameter($parameter)

Screenshots

Hello,
As some driver can take remote sceenshots (eg webdriver with firefox) it would be cool to get screenshots from remote servers (I may use it when I test my projects against a selenium grid)
Maybe a settingun behat.yml under debug like "remote: true"?
Cheers

Only use SystemContext

To test command lines tool, I do not need http_call services required in Extension::load method.

Do you think it is a good idea to add a parameter to allow to skip http_call loading?

PR is coming if so.

Case sensitive when it should be case insensitive

From feature/rest.feature

the header "Content-Type" should be equal to "text/html; charset=utf-8"

The above results in:

And the header "Content-Type" should be equal to "text/html; charset=utf-8" # Sanpi\Behatch\Context\RestContext::theHeaderShouldBeEqualTo()
  The header "Content-Type" is equal to "text/html; charset=UTF-8" (Behat\Mink\Exception\ExpectationException)

Removed tags?

It seems that some tags have been silently removed (2.3 and recently 2.2). It breaks our projects requiring Behatch (errors like The requested package behatch/contexts could not be found in any version, there may be a typo in the package name. while running composer update), it breaks semver and it is against best practices.

RSS2 validity checks are not compliant with the RSS2.0 specification

Having looked through the source, I found this within the RSS2.0 XSD being used:

      <xs:element name="item" type="RssItem" minOccurs="1" maxOccurs="unbounded">
         <!-- 
           HACK: According to the RSS 2.0 spec, it should strictly be possible to have zero item elements, 
                 but this makes the schema non-deterministic with regard to extensibility elements
                 so for the moment we undid bug-fix 10231 and set minOccurs=1 to work around this problem. 
         -->
      </xs:element>

The minOccurs=1 is causing some of my tests to fail when they should not.

Tag 2.3

Did I miss something or tag 2.3 was removed ? I miss it 😒

Debug failed tests in SystemContext

Do you think it is a good idea to display output if a test fail using SystemContext? I have trouble to debug un Travis build because I just have this log:

    Then command should succeed                                                   # Sanpi\Behatch\Context\SystemContext::commandShouldSucceed()
      exception 'Exception' with message 'Command should succeed 1' in vendor/behatch/contexts/src/Context/SystemContext.php:73

I can implement also a debug output action.

What do you think?

possible bug in AssertTrue and AssertFalse

In the BaseContext.php we have:

protected function assertTrue($value, $message = null)
{
    if ($value) {
        if (is_null($message)) {
            $message = sprintf('The value is true');
        }
        throw new ExpectationException($message, $this->getSession());
    }
}

protected function assertFalse($value, $message = null)
{
    if (!$value) {
        if (is_null($message)) {
            $message = sprintf('The value is false');
        }
        throw new ExpectationException($message, $this->getSession());
    }
}

I think there is a bug, the first if condition should be true !== $value for assertTrue and false !== $value in the assertFalse method. Take for instance the assertFalse when $value is false, !$value will be true and the exception will be thrown.

RestContext headers doesn't work

Behat\Mink\Driver\BrowserKitDriver.php is only passing headers to the client in the visit() method on line 158. When RestContext is bypassing the visit() method (in order to set POST method for instance), then the headers are never passed to the client, thus submitting POST with default headers.

Example: iSendARequestToWithBody

Given I add "Content-Type" header equal to "application/json"
When I send a "POST" request to "api.json" with body:

Actual sent header in this scenario:

Content-Type: application/x-www-form-urlencoded

The `httpCallResultPool` causes error when there is a javascript alert or confirm!

     When I follow "Delete"
     Then I should see "Are you sure?" in popup
     When I confirm the popup

It causes an UnexpectedAlertOpen exception after the When I follow "Delete"! The patch of @madalinoprea is causes error ( #94 ):

No alert is present (WARNING: The server did not provide any stacktrace information)

The whole httpCallResultPool concept seems wrong, the source call (get the content) to Selenium causes error some cases (like javascript alert or confirm)!

Impossible to use context behatch:json or rest without triggering an error

Hi,

When I use contexts : behatch:json or behatch:rest I got :

[Symfony\Component\Debug\Exception\ContextErrorException]             
  Warning: preg_match() expects parameter 2 to be string, object given 

As soon as I remove them, the error disappear.
Has the documentation some step missing ?

Using Behat 3+, tried with SF 2.6.3 and 2.6.1 :

        "behat/behat": "3.0.*@dev",
        "behat/symfony2-extension": "dev-master",
        "behat/mink-extension": "2.0.*@dev",
        "behat/common-contexts": "1.2.*@dev",
        "sensiolabs/behat-page-object-extension": "2.0.*@dev",
        "vipsoft/doctrine-data-fixtures-extension": "3.0.*@dev",
        "behatch/contexts": "dev-master",
        "behat/mink": "dev-master",
        "behat/mink-browserkit-driver": "dev-master",
        "behat/mink-goutte-driver": "dev-master",
        "behat/mink-selenium2-driver": "1.2.*@dev",
        "behat/web-api-extension": "1.0.*@dev"

with configuration :

default:
    autoload: %paths.base%/features/Context
    extensions:
        Behat\MinkExtension:
            base_url:   http://xxx.xxxx.dev/app_test.php/
            files_path: app/features/files
            default_session:    goutte
            javascript_session: selenium2
            goutte:    ~
            selenium2: ~
        Behat\Symfony2Extension:
            kernel:
                env:   test
                debug: true
        VIPSoft\DoctrineDataFixturesExtension\Extension:
            lifetime:    feature
            autoload:    false
            directories:
                - app/features/Context/Fixtures
            fixtures:    ~
            migrations: ~
        Behat\WebApiExtension:
            base_url: http://xxx.xxx.dev/app_test.php/
        Sanpi\Behatch\Extension: ~
    suites:
        default:
            contexts:
                - Context\FeatureContext
                - Behat\WebApiExtension\Context\WebApiContext
                - behatch:json
                - behatch:rest

    translation:
        locale: en

Need to test values for JSON object inside an array, without knowing the index

I need to test that a JSON array contains an object node with a particular ID and that that object node has a particular value in one of its fields.

This could be worded as such:

@Then the JSON object :node_path in the JSON array :array_path having a member node :lookup_node equal to :lookup_value has another member :expected_name equal to :expected_value

Fatal error when printing curl command

PHP Fatal error: Call to undefined method Symfony\Component\HttpFoundation\Request::getServer() in vendor/sanpi/behatch-contexts/src/Context/RestContext.php on line 224

Feature: "print the corresponding curl command"

Print cURL command generates an error

[RuntimeException]                                                                                                                                                                                              
  Error Output: PHP Fatal error:  Call to undefined method Symfony\Component\HttpFoundation\Request::getServer() in /Users/Theo/Sites/CDJE/Incipio/vendor/behatch/contexts/src/Context/RestContext.php on line 2  
  24

Tested with Symfony 2.7 BETA.

wrong implementation of "Add an header element in a request"

this function in RestContext
public function iAddHeaderEqualTo($name, $value)
{
$this->getSession()->getDriver()->getClient()->setServerParameter($name, $value);
}

sets the server parameters not request headers, so you have to write
I add "CONTENT_TYPE" header equal to "application/json"
instead of
I add "Content-Type" header equal to "application/json"

Using Mink::assertSession

Looks like behatch uses its own assert functions (assertContains, assertNotContains), would it be possible for it to be refactored to use the WebAssert versions? I have overridden these to do exact matching and need the behatch steps to use the same logic.

Symfony2 extension compatibility

Ok, travis back to green, now we can work on the big issue with Behat/Symfony2Extension (#55, #98, #101, #110 and #118).

All issues is in the rest context, this confirms @stof’s comment:

The rest-context is a huge mistake altogether. Mink is not a REST client (browsers are not REST clients either). There is no point using the Mink driver to perform the REST API calls. It is the wrong tool for the job.

Any idea?

behatch json with drupal extension

Hello,

Im trying to make a scenario where I first have to do some drupal things (with the drupal extension for behat) and after that check the output of a json call.

The problem is that I need a browser for the drupal things and then the call doesnt get validated as correct json in the browser (ff, chrome, ie,...)

Anybody a solution?

$ref not working

This is my documents.json file content:

{
    "$schema": "http://json-schema.org/draft-04/schema",
    "type": "array",
    "required": true,
    "items": {
        "$ref": "document.json",
        "required": true
    }
}

And this is my document.json file content:

{
    "$schema": "http://json-schema.org/draft-04/schema",
    "type": "object",
    "required": true,
    "additionalProperties": false,
    "properties": {
        "id": {
            "type": "string",
            "required": true
        },
        "inexistent_property": {
            "type": "string",
            "required": true
        }
    }
}

When I pass this json response:

[
{
    "id": "an_id"
}
]

It passes the tests.

I'm doing something wrong?

Fatal error when using RestContext

Hi,

a recent RawMinkContext have break RestContext

Fatal error: Access level to Sanpi\Behatch\Context\RestContext::locatePath() must be public (as in class Behat\MinkExtension\Con\Context\RawMinkContext) in vendor/sanpi/behatch-contexts/src/Sanpi/Behatch/Context/RestContext\RawMinkContext) in /home/jenkins/jobs/Trinity/workspace/vendor/sanpi/behatch-contexts/src/Sanpi/Behatch/Context/RestContexntext.php on line 164

Changing visibility correct the problem.

Thanks

Xavier

The way you use TableNodes breaks step argument transformations

According to http://docs.behat.org/guides/2.definitions.html#transforming-tables table nodes are matched like so /^table:name,followers$/

Problem is because behatch uses tables the 'wrong' way round (rows are columns and columns are rows) in steps such as fill in the following, you get row data in the match string instead of field names.

Guess there is not much option but to use tables correctly although I do prefer the way it looks in a story when using the current way...

Wrong (current) way:

And fill in the following:
  | New Password     | newpassword  |
  | Confirm Password | newpassword  |

Right way:

And fill in the following:
  | New Password     | Confirm Password  |
  | newpassword      | newpassword       |

iFollowTheNthLink function does not work for behat 3/php 5.5

//Follows XPath element
//TODO: Fix this function

/**
 * THIS FUNCTION IS CURRENTLY DEPRECATED AND NEEDS TLC
 * Click on the nth specified link
 * Example: When I click on 1st "ul li a" link
 * Example: And I click on 6th "ul li a" link
 *
 * @When (I )follow the :index :link link
 */
public function iFollowTheNthLink($index, $link)
{
    $page = $this->getSession()->getPage();

    $links = $page->findAll('named', [
        'link', $this->getSession()->getSelectorsHandler()->xpathLiteral($link)
    ]);

    if (!isset($links[$index - 1])) {
        throw new \Exception("The $index element '$link' was not found anywhere in the page");
    }

    $links[$index - 1]->click();
}

The above function doesnt work. To reproduce use the step definition in any test. Error suggests not using xpathLiteral as it is deprecated.

Opening contributions

I want to open contribution for behatch, there is no reason I am the only one who can approve contributions.

Planned actions:

  • Create a behatch organisation
  • Transfert sanpi/behatch-skeleton to behatch/skeleton
  • Write contribution guideline
  • Transfert sanpi/behatch-contexts to behatch/contexts
  • Change namespace: Sanpi\Behatch\Context -> Behatch\Context (in 3.x branch)
  • Find a logo

Headers do not get added to requests

Using the following feature:

Feature: Listing sports

  Scenario: Successful listing of seeded sports                    # features/functional/sports/index.feature:3
    Given I add "Accept" header equal to "application/json"        # Sanpi\Behatch\Context\RestContext::iAddHeaderEqualTo()
    And I add "Content-type" header equal to "application/json"    # Sanpi\Behatch\Context\RestContext::iAddHeaderEqualTo()
    When I send a GET request to "/sports"

Using TCPdump to see what is actually being sent:

GET /sports HTTP/1.1
Host: test.apisportsdata.sportlobster.dev
User-Agent: Symfony2 BrowserKit

None of the headers I have specified are actually sent.

Composer:

    "require-dev": {
        "behat/behat": "~3.0",
        "behat/mink-goutte-driver": "~1.1",
        "behatch/contexts": "dev-master",
        "phpspec/phpspec": "~2.0",
        "phpunit/phpunit": "~4.1",
        "way/generators": "2.*"
    },

Behat.yml:

default:
    extensions:
        Behat\MinkExtension:
            base_url: 'http://localhost'
            default_session: goutte
            goutte: ~
        Sanpi\Behatch\Extension: ~
    suites:
        functional:
            paths: [ %paths.base%/features/functional ]
            contexts:
                - LaravelFeatureContext
                - Behat\MinkExtension\Context\MinkContext
                - behatch:browser
                - behatch:debug
                - behatch:system
                - behatch:json:
                    evaluationMode: javascript
                - behatch:table
                - behatch:rest
                - behatch:xml

Invalid detection of false value in JSON

There is a bug in detection of false value.

I have a step: And the JSON node "is_completed" should be equal to "false"
and I'm getting this error: The node value is 'false' (Exception)

I tried And the JSON node "is_completed" should contain "false" as well but it is not working either.

True value works fine.

Taking screenshot gives undefined method Behat\Mink\Session::getScreenshot()

Hi,

I cloned dev-master however when I use step "I save a screenshot in "index.png"", I get the error below

Fatal error: Call to undefined method Behat\Mink\Session::getScreenshot() in C:\
htdocs\myproject\vendor\behat\mink-extension\src\Behat\MinkExtension\Context\RawM
inkContext.php on line 125

My composer looks like:

    "behat/behat": "2.4.*@stable",
    "behat/mink": "1.4@stable",
    "behat/mink-selenium2-driver": "*",
    "behat/mink-extension": "*",
    "sanpi/behatch-contexts": "dev-master"

Am I missing something? or Is it bug? I am using selenium2-driver

Call to undefined method Symfony\Component\HttpKernel\Client::setHeader

I'm trying to set a header before sending a request and an exception is thrown.

PHP Fatal error:  Call to undefined method Symfony\Component\HttpKernel\Client::setHeader() in /Users/richard/…/vendor/behatch/contexts/src/HttpCall/Request.php on line 51

Heres a snippet from the scenario:

And I add "Content-Type" header equal to "application/json"
When I send a POST request to "/path" with body:
…

Fatal error when updating package

I am updating my composer packages but I get the following error when I get to behatch-context package:

- Updating sanpi/behatch-contexts dev-master (044ce4d => 876e1c8)
Checking out 876e1c8e86a7dc4dadb54fcdbd821a1ce9846741

[RuntimeException]                                                                                                                        
Failed to execute git checkout '876e1c8e86a7dc4dadb54fcdbd821a1ce9846741' && git reset --hard '876e1c8e86a7dc4dadb54fcdbd821a1ce9846741'                 

fatal: reference is not a tree: 876e1c8e86a7dc4dadb54fcdbd821a1ce9846741 

Any idea what might be the reason?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.