Behatch contexts - Anyone used ??

570 views
Skip to first unread message

bin

unread,
Aug 20, 2014, 12:33:13 PM8/20/14
to be...@googlegroups.com
Hi everyone,

I just try Behat recently. I love it, I really want to dig on Behat

I have just found Behatch contexts ( https://github.com/sanpii/behatch-contexts ), that says Behatch contexts provide most common behat tests. It's very good conception :) but I don't really understand how to use. There isn't any documentation or example

Anyone used Behatch-contexts ? Please tell me how to use that

Thank you very much


Michael Seay

unread,
Aug 20, 2014, 1:02:14 PM8/20/14
to be...@googlegroups.com
I haven't seen this, but, it looks pretty cool.

I would....
  1.  install it to your project via composer
  2. Extend any one of the provided Context classes (https://github.com/sanpii/behatch-contexts/tree/master/src/Context) or specify them in a useContext() statement in the constructor of your context class
  3. Have a look at the provided features to see what you can do with it (https://github.com/sanpii/behatch-contexts/tree/master/features)
  4. You can also print out the available steps from whatever context you have available to your project (bin/behat -dl)
Looks pretty cool though, I've used this in the past (https://github.com/Behat/CommonContexts)

Good luck!
Mike


--
You received this message because you are subscribed to the Google Groups "Behat" group.
To unsubscribe from this group and stop receiving emails from it, send an email to behat+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nicolas

unread,
Aug 20, 2014, 4:32:56 PM8/20/14
to be...@googlegroups.com
Hello,

On 20/08/2014 18:33, bin wrote:
> There isn't any documentation or example

In addition of the project itself, you can checkout a minimalist project
bootstraping: https://github.com/sanpii/behatch-skeleton/

I have published some others real life applications:

* Another project bootstrap: https://github.com/sanpii/spore
* A REST API: https://github.com/sanpii/todo-rest
* The angularjs frontend: https://github.com/sanpii/todo-webapp

Best regards,
Nicolas.

signature.asc

bin

unread,
Aug 21, 2014, 5:26:05 AM8/21/14
to be...@googlegroups.com
Thank you for your response. It's very useful

I have a question ( sorry if that's stupid :) )

I read on the site of Behat, in the context suite section in behat.yml, that defines the classes Context like:

default:
    suites:
        core_features:
            paths:    [ %paths.base%/features/core ]
            contexts: [ CoreDomainContext ]
        user_features:
            paths:    [ %paths.base%/features/web ]
            filters:  { role: user }
            contexts: [ UserContext ]
        admin_features:
            paths:    [ %paths.base%/features/web ]
            filters:  { role: admin }
            contexts: [ AdminContext ]


But here you define:

default:
    suites:
       default:
           contexts:
               - Behat\MinkExtension\Context\MinkContext
               - behatch:browser:
                   timeout: 1
               - behatch:debug:
                   screenshotDir: "."
               - behatch:json:
                   evaluationMode: javascript
               - behatch:rest
               - behatch:system:
                   root: "."
               - behatch:table
               - behatch:xml

That means we can define by classes contexts and the files features ?

Thank you very much

Christophe COEVOET

unread,
Aug 21, 2014, 5:47:17 AM8/21/14
to be...@googlegroups.com
The syntax behatch:* for class names is actually also defining context classes. The BehatchExtension registers a resolver turning this notation into the actual class names used in Behatch (you can also use the real class names).
This example also shows how to pass some constructor arguments to the contexts (which is not used in the case of the MinkContext or in the example you saw in the doc).

for a given suite, you can configure 3 things (known in core. extensions can add more settings):

- paths: the paths to the features included in it
- filters: the filters applied on scenarios to restrict them
- contexts: the context classes being used.

the example found in the doc shows the 3 of them. The Behatch sample only configures contexts, expecting others to rely on the default values.
-- 
Christophe | Stof

bin

unread,
Aug 21, 2014, 11:49:09 AM8/21/14
to be...@googlegroups.com
Thank you for your response

I have still one question, I read the doc of Behat, normally the context classes are in the directory features/bootstrap. But in the behatch the context classes are in the directory src/Context. So now I want to write my context classes, Should I write in src/Context like the others or in features/bootstrap ? Where is the definition of the context directory ?

Thank you

Christophe COEVOET

unread,
Aug 21, 2014, 12:29:28 PM8/21/14
to be...@googlegroups.com
Le 21/08/2014 17:49, bin a écrit :
> Thank you for your response
>
> I have still one question, I read the doc of Behat, normally the
> context classes are in the directory features/bootstrap. But in the
> behatch the context classes are in the directory src/Context. So now I
> want to write my context classes, Should I write in src/Context like
> the others or in features/bootstrap ? Where is the definition of the
> context directory ?
>
> Thank you
>
There is no context directory. your context classes can be where you
want (even created dynamically with eval if your are a crazy coder) as
long as PHP can find them (i.e. your autoloader can load them)

--
Christophe | Stof

bin

unread,
Aug 22, 2014, 8:20:04 AM8/22/14
to be...@googlegroups.com
I understand, thank you very much
Reply all
Reply to author
Forward
0 new messages