Execute complete test scenarios with Blackfire Player

By Grégoire Pineau, on Jan 16, 2017

Time for a birthday cake: we Open Sourced Blackfire Player a year ago! And the cake is no lie: we’re proud to release a new version, still as Alpha.

This is a complete rewrite of the player to make it much easier, intuitive, and powerful to use. That also means that it’s not compatible with previous alpha versions, but you can still access the old versions if needed.

What’s Blackfire Player?

Let’s step back for a minute; you might not know yet about the Player.

Blackfire Player is a powerful Web Crawling, Web Testing, and Web Scraper application. It provides a nice DSL to crawl HTTP services, assert responses, and extract data from HTML/XML/JSON responses.

It basically enables you to execute any scenario you’d need to run tests on your application. And of course, it enables you to run Blackfire performance tests.

An easy way to test performance with Blackfire is to start with a simple .blackfire.yml file that includes tests and scenarios. But this has limits, especially as soon as you’d need a scenario to cope with sessions, cookies, or to get a value from a request and pass it on to the next. Blackfire Player does all of that. And a lot more.

What’s new in Blackfire Player?

Forget that the Player is written in PHP. We’ve created a DSL, inspired by YAML to provide a more intuitive and descriptive way of writing scenarios. You can now run a simple .bkf file, which will execute your scenarios, from a crawling/scraping use case to integration or unit testing.

Here’s an example of how easy it is to let Blackfire Player automatically browse through your website. We use it on the symfony.com:

group http_cache_check
    visit url(url)
        name "Loading " ~ url
        blackfire false
        expect status_code() == 200
        wait 1000
    reload
        name "Checking " ~ url
        blackfire false
        expect status_code() == 200
        expect header('Age') > 0
        expect header('X-Varnish') matches '/\\d+ \\d+/'

scenario
    name "HTTP Cache"
    endpoint "http://symfony.com/"
    set env "dev"
    set urls [ \
            # what-is-symfony
            'at-a-glance', 'components', 'distributions', 'download', \
            'elevator-pitches', 'in-five-minutes', 'license', 'projects', \
            # what-is-symfony/in-five-minutes
            'six-good-reasons', 'six-good-technical-reasons', \
            'ten-criteria', 'when-use-a-framework', \
            'why-use-a-framework', \
        ]
    when "prod" == env
        with url in urls
            include http_cache_check

And then we launch it with the following:

blackfire-player run scenario.bkf --variable env=prod

Blackfire Player and Performance builds

The great part about this is that any scenario run with Blackfire can automatically become a performance build, where each request will be profiled and run against your assertions.

Do you want to have the overview on your payment tunnel’s code performance? Go create a payment-tunnel.bfk scenario!

Are you using the Player for other purposes than performance testing? You can also disable Blackfire for some or all of the requests.

Alpha, and then?

There are still some Player features which we’re working on, before we can move it to Beta, and then on to the final version.

But as this represents quite some changes already, we wanted to gather your feedback. Blackfire Player is licensed under the MIT Open-Source license. Its source code is hosted on Github. Go ahead, try it and let us know in GitHub what you think!

Happy birthday, Player!

 

 

Grégoire Pineau

Grégoire worked as a (Symfony-certified!) developer at Blackfire.io. He's also involved in Symfony development and several other Open Source projects, and is the Swiss Army Knife of DevOps. It would only be him, most of the projects he worked on would be named after savanna animals.