Given I try to log in as "Bob"If I see a message "User not recognised"Then I create a user "Bob"And I try to log in as "Bob"If I see a message "User not authenticated"Then I authenticate as "Bob"And I try to log in as "Bob"If I can see "Welcome Bob"Then .....
You appear to be approaching this as a pure standalone test environment, the stage or UAT scenario where you know a given account exists - 'Given I am a registered user'.
I am trying to develop a sanity checker to quickly run through on our live system, after deploying the latest updates. I do not know the exact status of my account, and I cannot just dive into the database to delete it - I must use my test process to see if the account exists, and to react accordingly.
Having scenarios which fail is not acceptable as we want to build this in to Jenkins to automatically roll back if the sanity test fails, so the 'given I am a registered user' approach will not work.
I would not expect a customer to understand the examples like this. My ideal is to keep as much as possible in pseudo-english, so something like:Given I am on the home pageIf I can see the login buttonThen I fill in 'username' with 'bob'And I fill in 'password' with '12345'And I press 'login'And I see 'login successful'...The only difference here between 'Given' or 'When' and 'If' is that Given and When break out with an error, while if breaks out without an error.I can easily do this in a step, using PHP, but I want to do it in 'english' so the customer can see what is happening, and adjust it if they change the field names or response message.RegardsJohn
On Wednesday, October 10, 2012 11:55:25 AM UTC+1, Marijn wrote:
How are your customers? I'm fairly confident that no customer will understand the examples as you've shown them.Can't you run those assertions in your step definitions? I would argue they don't belong in your scenario's.Your features and scenarios are about business value, not about technical implementation details.Cheers
You appear to be approaching this as a pure standalone test environment, the stage or UAT scenario where you know a given account exists - 'Given I am a registered user'.I am trying to develop a sanity checker to quickly run through on our live system, after deploying the latest updates. I do not know the exact status of my account, and I cannot just dive into the database to delete it - I must use my test process to see if the account exists, and to react accordingly.Having scenarios which fail is not acceptable as we want to build this in to Jenkins to automatically roll back if the sanity test fails, so the 'given I am a registered user' approach will not work.If there was some way to break out of a scenario, we could do...Scenario 1Given I set global status to 'loggedout'And I break out if I am not logged inThen I set global status to 'loggedin'And I can do things knowing I am logged inAnd I will not get a failureScenario 2Given I break out if global status is not 'loggedout'Then I can do things knowing I am logged outAnd I will not get a failure(yes, I know scenarios are supposed to be independent, but I already have status passing working)Perhaps Behat / Gherkin is the wrong language to be writing these tests, but it is important that the customer can manage them for himself (ie they need to be in 'pseudo-english') and they need to be structured in such a way that the customer can follow them.RegardsJohn
On Wednesday, October 10, 2012 9:44:13 AM UTC+1, Jakub Zalas wrote:
Hi John,I'm sorry but you're doing it wrong.Instead of "trying" to do something you should either "do it" or "make an assertion". Your scenario is completely not readable, I don't really see what you're trying to achieve. Consider following scenarios:Scenario: Successful loginGiven I am a registered userAnd I visit the homepageWhen I fill in my login detailsAnd I press "Log in"Then I should be logged inAnd I should see "You've been successfully logged in"Scenario: Failed loginGiven I am a registered userAnd I visit the homepageWhen I fill in my login details incorrectlyAnd I press "Log in"Then I should not be logged inAnd I should see "Incorrect e-mail or password"There's no need for what you called "flow of control". Gherkin is not a programming language. Its purpose is to have a readable acceptance criteria (requirements) that can be executed to automatically verify your application's behaviour. You're not suppose to code your login in Gherkin.Go through behat docs, they're not long: http://docs.behat.org/Gherkin docs might be a good start to see what it has to offer: http://docs.behat.org/guides/1.gherkin.htmlI also recommend reading the RSpec book. It's a great introduction to BDD (don't be scared by the tools used there, it's not about the tools).
On Tuesday, October 9, 2012 3:30:43 PM UTC+1, John Brookes wrote:
Am I missing something?I want to model a scenario:
I can write the individual steps quite easily, but neither Gherkin nor Behat appear to have any flow control or conditional operators. I want as much written in 'English' as possible, so it can be maintained by my customers - when they change the wording of the messages for instance.Is this possible?If this is a question that's answered elsewhere, please point me there - I have looked but found nothing.RegardsJohn
Hi John,
Feature: User account functionality is tested after deployment
In order to verify that a deployment is successful
As a system administrator
I need to verify that a user can create an account, login, update the account and delete the account
Scenario: A user can create an account
Given the user "notreg...@test.com" is not registered
And I am on the homepage
And I visit "Account/NewUser"
And I enter my details
When I press "Create Account"
Then I should see "Your account has been created"
Scenario: A user can login
Given the user "regis...@test.com" is registered with the password "foobar"
And I am on the homepage
And I visit "Login"
When I press "Login"
Then I should see "You have logged in"
Scenario: A registered user can delete their account
Given the user "regis...@test.com" is registered with password "foobar"
And I login as "regis...@test.com" with the password "foobar"
And I am on the account page
And I press "Close this Account"
When I press "Confirm Deletion"
Then I should be logged out
And the user "regis...@test.com" should not be registered
And I should see "Your account has been closed
Hi John,I think it's impossible to test this scenario, or extract any meaning out of it. Whenever something is wrong it always can be explained very logically so you still have to figure out if something really went wrong. And I think that was the purpose of writing the test :)Why don't you create a test account and put the credentials in the test, you have to know the password of at least one account in order to test if you can login, you can't get around that one..Cheers,
Jelle
Op vrijdag 12 oktober 2012 18:33:05 UTC+2 schreef John Brookes het volgende:
Hi Jelle, thanks for getting back to me.The problem I have is that I am trying to test a service based structure where the database access layer is somewhere behind a Soap server, and the backend boys will not expose any functionality to let me directly access the database.This imposes some restrictions:The only way I can tell if an account exists is to try to create a duplicate. If I succeed, the account exists. If I fail, the account already exists and I just have to hope it has the correct password.The only way I can tell if the password is correct is to try to log in; if I succeed, then the password is correct, otherwise - I am stuck.So, I cannot just assert that the account exists, I have to try to create it, but a failure to create it does not mean there is a fault in the system, just in the test.Incidentally, I have found a way round the initial problem, by returning PendingException from a step which has 'soft failed'. This in effect breaks out of the running scenario without flagging a failure - it shows in the logs as 'todo', which we can set Jenkins to ignore. When I get this fully tested and working, I will submit it through this group so others can see my solution.
RegardsJohn
On Friday, October 12, 2012 4:15:25 PM UTC+1, Jelle Munk wrote:
Hi John,I think you're at the right spot for your problem. I'm also new to BDD and behat so I'm no expert but I do the following to solve you're problem.One of the most important things with BDD/Behat is that all information is in the test. This way you never have to check if a specific resource or user exists in the application because you state in your test that it does.You can use background for this.Background: Given The following users are registered| username | password || foo | bar |Then you create your scenario using the variables.Scenario: Given I am on Login pageWhen I fill foo in usernameAnd I fill bar in passwordAnd I click loginThen I should see 'welcome'
Backgrounds are run before a scenario so there you make sure you insert the user in the db. Then you use hooks to delete it after all tests are run.Does that make sense?Cheers, JelleOp donderdag 11 oktober 2012 09:38:39 UTC+2 schreef John Brookes het volgende: