WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:01.166 --> 00:00:04.646 align:middle
Pretend for a few minutes
that the Blackfire profiler

00:00:04.926 --> 00:00:06.966 align:middle
that we've been learning so much about...

00:00:07.276 --> 00:00:08.526 align:middle
doesn't exist...

00:00:08.816 --> 00:00:10.676 align:middle
at all. Why?

00:00:11.166 --> 00:00:16.076 align:middle
Because we're now going to talk about
something that has the word "Blackfire" in it...

00:00:16.466 --> 00:00:20.956 align:middle
but has absolutely nothing to
do with the Blackfire profiler.

00:00:21.336 --> 00:00:22.806 align:middle
At least, not yet.

00:00:23.766 --> 00:00:25.336 align:middle
Google for "Blackfire player".

00:00:26.666 --> 00:00:31.696 align:middle
The Blackfire Player is an open source library
that makes it really easy to write a few lines

00:00:31.696 --> 00:00:38.666 align:middle
of code that will then be executed to crawl
a site: clicking on links, filling out forms,

00:00:38.946 --> 00:00:40.456 align:middle
and doing things with the result.

00:00:41.396 --> 00:00:44.236 align:middle
It's basically a simple language
for surfing the web

00:00:44.476 --> 00:00:48.226 align:middle
and a tool that's able to
read that language and...

00:00:48.266 --> 00:00:49.246 align:middle
actually do it!

00:00:50.346 --> 00:00:55.626 align:middle
To install it, copy the curl command,
find your terminal, and paste.

00:00:55.796 --> 00:01:01.516 align:middle
If you're on Windows, you can just
download the blackfire-player.phar file

00:01:01.516 --> 00:01:04.206 align:middle
from that URL and put it into your project.

00:01:05.376 --> 00:01:07.666 align:middle
Now go back and copy the other two commands.

00:01:09.336 --> 00:01:10.376 align:middle
Paste and...

00:01:10.766 --> 00:01:11.306 align:middle
that's it!

00:01:11.886 --> 00:01:14.116 align:middle
For Windows users, skip this step.

00:01:14.116 --> 00:01:15.866 align:middle
Let's see if it works.

00:01:16.126 --> 00:01:21.486 align:middle
Run: blackfire-player Nice!

00:01:22.396 --> 00:01:28.346 align:middle
So here's the idea: we create a file
that contains one or more scenarios.

00:01:30.116 --> 00:01:36.976 align:middle
Inside each scenario, we write code that says:
go visit this URL, expect a 200 status code,

00:01:37.256 --> 00:01:39.356 align:middle
then click on this link, and so on.

00:01:40.046 --> 00:01:42.736 align:middle
It can get fancier, but that's the gist of it.

00:01:43.756 --> 00:01:46.966 align:middle
Let's create a our first
Blackfire player file at the root

00:01:46.966 --> 00:01:49.236 align:middle
of the project, though it could live anywhere.

00:01:50.676 --> 00:01:54.766 align:middle
Call it, how about, scenario.bkf.

00:01:54.906 --> 00:01:56.626 align:middle
That's pure creativity.

00:01:57.886 --> 00:02:02.036 align:middle
At the top, I'll put a name -
though it's not very important -

00:02:04.606 --> 00:02:08.096 align:middle
then endpoint set to our server's URL.

00:02:08.096 --> 00:02:12.866 align:middle
So https://localhost:8000.

00:02:13.926 --> 00:02:19.126 align:middle
You can override this when you execute
this file by passing a -- endpoint option.

00:02:20.516 --> 00:02:24.576 align:middle
Notice that this kind of
looks like YAML, but it's not:

00:02:24.846 --> 00:02:27.556 align:middle
there is no : between the key and value.

00:02:28.386 --> 00:02:31.056 align:middle
This is a custom Blackfire player language,

00:02:31.316 --> 00:02:33.976 align:middle
which is friendly, but takes
some getting used to.

00:02:35.066 --> 00:02:41.206 align:middle
At the bottom, add our first
scenario - call it "Basic Visit".

00:02:42.196 --> 00:02:47.316 align:middle
Inside, let's do two things:
first, visit url("/").

00:02:47.576 --> 00:02:52.086 align:middle
We can also give this page
a name - it helps debugging.

00:02:52.086 --> 00:02:54.926 align:middle
And second...

00:02:55.286 --> 00:02:59.566 align:middle
once we're on the homepage,
let's "click" this "Log In" link.

00:03:01.806 --> 00:03:07.176 align:middle
Do that with click link() and
then use that exact text: Log In.

00:03:09.036 --> 00:03:10.826 align:middle
Give this page a name too.

00:03:12.246 --> 00:03:13.666 align:middle
That's enough to start.

00:03:14.096 --> 00:03:17.836 align:middle
We should be able to use the
blackfire-player tool to...

00:03:18.056 --> 00:03:20.636 align:middle
actually do this stuff!.

00:03:20.716 --> 00:03:27.296 align:middle
Let's try it: blackfire-player
run scenario.bkf And...

00:03:27.296 --> 00:03:30.126 align:middle
it fails: curl error 60.

00:03:30.126 --> 00:03:37.516 align:middle
If you Google'd this, you find out that
this is an SSL problem - it's caused because

00:03:37.516 --> 00:03:43.446 align:middle
or Symfony dev server uses a,
sort of, self-signed certificate

00:03:43.556 --> 00:03:45.536 align:middle
that blackfire-player doesn't like.

00:03:46.366 --> 00:03:50.396 align:middle
The simplest solution, which is ok
since we're just testing locally -

00:03:50.716 --> 00:03:56.646 align:middle
is to pass -- ssl-no-verify And...

00:03:57.046 --> 00:03:58.726 align:middle
hey! It worked!

00:03:59.126 --> 00:04:01.366 align:middle
Scenarios 1, steps 2.

00:04:01.836 --> 00:04:06.626 align:middle
It truly made a request to the
homepage then clicked on that link!

00:04:07.346 --> 00:04:11.056 align:middle
By the way, the requests
aren't using a real browser.

00:04:11.206 --> 00:04:14.826 align:middle
And so, any JavaScript code
on your page won't run.

00:04:15.506 --> 00:04:18.206 align:middle
That might change in the
future - but I'm not sure.

00:04:19.186 --> 00:04:25.926 align:middle
Anyways, to see more fun output,
use the -v flag: Very cool!

00:04:26.806 --> 00:04:32.146 align:middle
Blackfire player is now making two
real HTTP requests to our site...

00:04:32.516 --> 00:04:35.376 align:middle
but it's not doing anything with that data.

00:04:36.456 --> 00:04:43.826 align:middle
Next, let's add some tests to our scenario
- like expecting that the status code is 200

00:04:44.056 --> 00:04:46.026 align:middle
and checking for elements in the DOM.

