WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:00.036 --> 00:00:05.656 align:middle
A few chapters ago, we created
this scenario.bkf file.

00:00:06.636 --> 00:00:11.806 align:middle
It's written in a special
blackfire-player language where we write one

00:00:11.806 --> 00:00:16.366 align:middle
or more "scenarios" that, sort of,
"crawl" a webpage, asserting things,

00:00:16.536 --> 00:00:19.096 align:middle
clicking on links and even submitting forms.

00:00:19.836 --> 00:00:22.916 align:middle
This a simple scenario: the
tool can do a lot more.

00:00:23.826 --> 00:00:27.836 align:middle
On the surface, apart from its
name, this has nothing to do

00:00:27.836 --> 00:00:32.436 align:middle
with the Blackfire profiler system:
blackfire-player is just a tool

00:00:32.436 --> 00:00:35.076 align:middle
that can read these scenarios
and do what they say.

00:00:36.176 --> 00:00:42.986 align:middle
At your terminal, run this file:
blackfire-player run scenario.bkf --

00:00:43.126 --> 00:00:49.866 align:middle
ssl-no-verify That last flag avoids an
SSL problem with our local web server.

00:00:50.646 --> 00:00:51.856 align:middle
When we hit enter...

00:00:52.246 --> 00:00:55.466 align:middle
it goes to the homepage,
clicks the "Log In" link and...

00:00:55.566 --> 00:00:56.636 align:middle
it passes.

00:00:57.946 --> 00:00:58.626 align:middle
This is cool...

00:00:58.626 --> 00:01:02.246 align:middle
but we can do something way more interesting.

00:01:02.976 --> 00:01:08.396 align:middle
Copy the entire scenario from this file,
close it, and open .blackfire.yaml.

00:01:09.226 --> 00:01:16.076 align:middle
Add a new key called scenarios set
to a | - that's a YAML way of saying

00:01:16.206 --> 00:01:19.206 align:middle
that we will use multiple lines to set this.

00:01:20.556 --> 00:01:28.186 align:middle
Below, indent, then say #!blackfire-player
- that tells Blackfire that we're

00:01:28.186 --> 00:01:31.506 align:middle
about to use the blackfire-player syntax...

00:01:31.576 --> 00:01:34.476 align:middle
which is the only format supported here...

00:01:34.476 --> 00:01:36.256 align:middle
but it's needed anyways.

00:01:37.516 --> 00:01:39.096 align:middle
Below, paste the scenario.

00:01:40.146 --> 00:01:42.526 align:middle
Make sure it's indented 4 spaces.

00:01:43.506 --> 00:01:47.576 align:middle
The cool thing is that we can
still execute the scenario locally:

00:01:47.966 --> 00:01:52.756 align:middle
just replace scenario.bkf with .blackfire.yaml.

00:01:53.876 --> 00:01:59.216 align:middle
The player is smart enough to know that it can
look under the scenarios key for our scenarios.

00:01:59.836 --> 00:02:01.116 align:middle
But if you run this...

00:02:01.656 --> 00:02:09.226 align:middle
error! Unable to crawl a non-absolute URI
/. Did you forget to set an endpoint Duh!

00:02:09.776 --> 00:02:13.176 align:middle
Our scenario.bkf file had an endpoint config.

00:02:13.806 --> 00:02:17.186 align:middle
You can copy this into your
.blackfire.yaml file.

00:02:17.626 --> 00:02:28.106 align:middle
Or you can define the endpoint by adding
-- endpoint=https://localhost:8000 Now...

00:02:28.106 --> 00:02:29.816 align:middle
it works! So...

00:02:29.886 --> 00:02:32.996 align:middle
why did we move the scenario into this file?

00:02:33.946 --> 00:02:36.056 align:middle
To find out, add this change to git...

00:02:36.056 --> 00:02:39.456 align:middle
and commit it.

00:02:39.456 --> 00:02:49.126 align:middle
Then deploy: symfony deploy --
bypass-checks Once that finishes...

00:02:49.466 --> 00:02:51.106 align:middle
let's go see what changed.

00:02:52.476 --> 00:02:58.396 align:middle
First, if we simply went to our site
and manually created a profile -

00:02:58.616 --> 00:03:05.006 align:middle
like for the homepage - the new scenarios
config would have absolutely no effect.

00:03:05.776 --> 00:03:10.006 align:middle
Scenarios don't do anything
to an individual profile.

00:03:10.806 --> 00:03:14.136 align:middle
Instead, scenarios affect builds.

00:03:15.316 --> 00:03:19.766 align:middle
Let's start a new one: I'll give this
one a title: "With custom scenarios".

00:03:21.336 --> 00:03:25.426 align:middle
Go! Awesome!!

00:03:25.776 --> 00:03:31.956 align:middle
Now, instead of that "Untitled Scenario"
that tested the two URLs we configured,

00:03:32.546 --> 00:03:35.386 align:middle
it's using our "Basic visit" scenario!

00:03:36.096 --> 00:03:40.486 align:middle
It goes to the homepage, then
clicks "Log In" to go to that page.

00:03:41.426 --> 00:03:49.486 align:middle
Yep, as soon as we add this scenarios key to
.blackfire.yaml, it no longer tests these URLs.

00:03:50.286 --> 00:03:52.546 align:middle
In fact, these are now meaningless.

00:03:53.326 --> 00:03:58.276 align:middle
Instead, we're now in the driver's
seat: we control the scenario

00:03:58.456 --> 00:04:01.436 align:middle
or scenarios that a build will execute.

00:04:02.216 --> 00:04:08.816 align:middle
Even better, we have a lot more control
now over the assertions - or "tests"...

00:04:08.816 --> 00:04:12.976 align:middle
Blackfire uses both words -
that make a build pass or fail.

00:04:12.976 --> 00:04:19.756 align:middle
For example, the "HTTP requests should
be limited to one per page" will be run

00:04:19.756 --> 00:04:24.046 align:middle
against all pages in the scenarios
- that's 2 pages right now.

00:04:24.956 --> 00:04:29.936 align:middle
But the homepage also has its
own assert: that the SQL queries

00:04:29.936 --> 00:04:32.296 align:middle
on this page should be less than 30.

00:04:32.296 --> 00:04:34.876 align:middle
If you look back at the build...

00:04:35.276 --> 00:04:37.386 align:middle
we can see that assertion!

00:04:38.186 --> 00:04:46.056 align:middle
We can even click into the profile, click
on "Assertions", and see both there.

00:04:46.976 --> 00:04:51.916 align:middle
So not only do we have a lot of control
over which pages we want to test -

00:04:52.156 --> 00:04:56.716 align:middle
even including filling out forms -
but we can also do custom assertions

00:04:56.716 --> 00:05:01.566 align:middle
on a page-by-page basis in
addition to having global tests.

00:05:02.436 --> 00:05:03.686 align:middle
I love that.

00:05:04.176 --> 00:05:09.386 align:middle
And now I can remove the comment I put earlier
above assert: now that we're running this

00:05:09.386 --> 00:05:12.516 align:middle
from inside an environment, this does work.

00:05:13.556 --> 00:05:20.566 align:middle
Next, let's use our power to carefully add more
time-based assertions on a page-by-page basis.

00:05:21.416 --> 00:05:26.166 align:middle
We'll also learn how you can add
your own metrics in order to, well,

00:05:26.456 --> 00:05:30.916 align:middle
write performance assertions about
pretty much anything you can dream up.

