From 87ad5e9f50d75db820708ea8c638c7ff240c2b15 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Sun, 8 Nov 2015 23:13:27 +0200 Subject: [PATCH] Add code blocks to the ch12 --- knpu/login-scenario.md | 49 ++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/knpu/login-scenario.md b/knpu/login-scenario.md index 13d8909..e2d7939 100644 --- a/knpu/login-scenario.md +++ b/knpu/login-scenario.md @@ -3,14 +3,20 @@ Open up `authentication.feature`, because, you can't do much until you login. Let's add a scenario: - Scenario: Logging in +[[[ code('82516911da') ]]] -We remember from running `behat -dl` that we have a lot of built in language -already. Let's save some effort and describe the login process using these. +We remember from running `behat -dl`: - Given I am on +```bash +./vendor/bin/behat -dl +``` + +That we have a lot of built in language already. Let's save some effort and describe +the login process using these: -We want to start on the homepage. PhpStorm tries to help by autocompleting this +[[[ code('486cd08e9d') ]]] + +We want to start on the homepage. PhpStorm tries to help by auto-completing this step, but when I hit tab, it prints it with extra stuff. When you use the `-dl` option, the "Given I am on" ends with a bunch of crazy regex. Anytime you see regex like this, it's just forming a wildcard: something where you can pass any @@ -18,42 +24,41 @@ value, surrounded by quotes. Oh, and one other thing: even though each line starts with `Given`, `When` and `Then` in the definition list, that first word doesn't matter. We could actually -say, +say: Then I am on "/" It doesn't sound right in English, but technically, it would still run. -Alright! Given I am on "/". Next, I will click 'Login'. The built-in definition for -that is "I follow". There's no built-in definition for 'I click' but we'll add one +Alright! Given I am on "/". Next, I will click "Login". The built-in definition for +that is "I follow". There's no built-in definition for "I click" but we'll add one later since that's how most people actually talk. -But for now let's add, +But for now let's add: - When I follow "Login" +[[[ code('1506ced3d2') ]]] -Remember, these all use the named selector, so we're using 'Login' because that's the +Remember, these all use the named selector, so we're using "Login" because that's the text of the link. On the login page, we need to fill in these two fields. Again, because of the named selector, we'll target these by the labels "Username" and "Password". There are a few -definitions for fields, byt the one I like is "When I fill in field with value". So, +definitions for fields, byt the one I like is "When I fill in field with value". So: - And I fill in "Username" with "admin" - And I fill in "Password" with "adminpass" +[[[ code('578445fea9') ]]] Yes I know, that isn't the right password - this won't work yet. It's cool though. -Finally, press the login button with +Finally, press the login button with: - And I press "Login" +[[[ code('af59a089e0') ]]] Notice that you *follow* a link but you *press* a button. Then we need to find something to assert - some sign that this worked. Login on the browser. Hmm, nothing says "Congratulations, you're in!"... but our login button *did* change to "Logout". Let's look for that with: - Then I should see "Logout" +[[[ code('c88d3499f5') ]]] Good work team. Let's run this! @@ -73,7 +78,7 @@ is going on. Debugging tip number 1: right before the failing step, use a step definition called: - And print last response +[[[ code('eb92324591') ]]] Now run this again. It still fails, but first it prints out the entire page's code. Yes, this *is* ugly - I have another debugging tip later. There are two important things: first, @@ -95,7 +100,13 @@ on failures. *** Let's remove our debug line and update this to the correct password which is -"admin". And now let's rerun it! It's alive! +"admin". And now let's rerun it: + +```bash +./vendor/bin/behat features/web/authentication.feature +``` + +It's alive! But we have a *big* problem: We're assuming that there will *always* be an `admin` user in the database with password `admin`. What if there isn't? What if the intern