Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

behat testing setup


Go to End


5 Posts   5547 Views

Avatar
BlueO

Community Member, 52 Posts

16 June 2013 at 4:34pm

I've been playing around with the behat testing module from here with reasonable success. I'm not too bad with SS but a total newbie when it comes to testing - but I'm aware its the "right thing" to do so I'm keen to figure it out!

I've got it generally up and running - test db creates just fine, successfully collects to selenium and runs features that use the 'out of the box' definitions work perfectly.

However, now I want to write my own definitions and I'm really struggling to get behat to recognise my custom featurecontext file. I'm using the behat.yml from the installer (in the root next to framework etc) with these additions:

default:
  paths:
    features: mysite/tests/behat
    bootstrap: mysite/tests/behat/features/bootstrap
  context:
    class: TestFeatureContext
  extensions:

    SilverStripe\BehatExtension\MinkExtension:
      # Adjust "base_url" to your own website URL.
      # Can be set via environment variables or _ss_environment.php/$_FILE_TO_URL_MAPPING as well.
      #
      #base_url:  http://localhost:8888/piemrak/

      # TODO Dynamically set through LocatorProcessor
      files_path: %behat.paths.base%/framework/tests/behat/features/files/
      default_session: selenium2
      javascript_session: selenium2
      goutte: ~
      selenium2:
        browser: chrome

    SilverStripe\BehatExtension\Extension ~

But the TestFeatureContext.php which lives in mysite/tests/behat/features/bootstrap/ fails to load and I get:

[RuntimeException]
Context class "TestFeatureContext" not found and can not be instantiated.

on running

 vendor/bin/behat mysite/tests/behat/features/home.feature 

The TestFeatureContext file is taken from the example on github - a class that extends SilverStripeContext.

So if you got through the lengthy post I'd appreciate some pointers as to where i'm going wrong!
cheers

bernard

Avatar
dead_salt

Community Member, 2 Posts

18 June 2013 at 11:23am

Hey Bernard,
I was having the same problem and it was driving me crazy but then my colleague pointed out that I needed to put a _config.php file in the features folder. Solved the issue all together. Give a try and see if it helps you!

Avatar
BlueO

Community Member, 52 Posts

19 June 2013 at 9:36pm

Hey cheers for that but unfortunately it doesn't seem to help.
some progress... I ran

 vendor/bin/behat --init 
and it successfully created a FeatureContext.php file for me. However when I run behat after putting a definition in that file it doesn't seem to recognise it - its as though the file isn't loaded at all. Hmm will keep plugging at it.

Avatar
BlueO

Community Member, 52 Posts

23 June 2013 at 1:46pm

OK, so after some investigation I've solved this

Probably those using this module have more experience with composer/testing that I do so the docs on github skip this point as it is a simple little thing...

The behat extension uses the composer autoloader to bootstrap the files and this can't be configured through the behat.yml file, instead you do it in composer.json autoload section like so:

{
"autoload": {
            "classmap": ["mysite/tests/behat/"]
        }
}

with the path being the location of the files you want auto-loaded like your FeatureContext.php
I figured it out from looking at composer.json and the test files in the CMS and framework dirs so they've got some good examples.

So now its up in action - its pretty fun to watch selenium run through the tests like magic

Avatar
Rob Clarkson

Community Member, 26 Posts

28 June 2016 at 1:34pm

BlueO you bloody legend, was stuck on this shizzle!! Thanks, send me your Bitcoin address and a beer is on me