What did they mean?

  • October 2, 2016
  • Agile, BDD, ...

iknowwhatyoumean

Let’s take the user story from previous post, and start with the granularity (i.e. the scenario steps). While specifying steps is an even better guide for developers to follow in their implementation, it’s important to remember anything we say can be misinterpreted!

 

Feature: As a online shopper,
I want to be able to add multiple items to my shopping cart,
in order to progress through payment process quickly

Scenario: Add single item to shopping cart
Scenario: Add multiple items to shopping cart
Scenario: Add multiple of same item to shopping cart
Scenario: Remove items from shopping cart



The first scenario is basic check that I am able to add a product to my shopping cart, so will use that as first example of how to make the scenario into an automated acceptance test.

Scenario: Add single item to shopping cart
# Let me know who you are
Given I am logged in as an online shopper
# Let me know where you are
And I am on page for Product A
# Let me know what you are doing
When I click the add to basket button
# Let me know what you are expecting
Then I should see 1 x Product A in my shopping cart

Resulting test code that makes your scenario executable. My assumption here is we are testing an AngularJS web application, so the natural test framework would be CucumberJS/Protractor.

this.Given(/^I am logged in as (.*)$/, function (userid, callback) {
browser.get('http://myshop.com/login')).then(function () {
getVariable.username.sendKeys('validshopper');
getVariable.password.sendKeys('Password1');
getVariable.login.click().then(function () {
// Check that I can see the Logout link, to verify I am logged in
expect(element(by.css('.logout-link')).isPresent())
.to.eventually.equal(true).notify(callback);
})
});
});
this.Given(/^I am on page for (.*)$/, function (productName) {
return browser.get('http://myshop.com/product/' + productName);
});
this.Given(/^I click the (.*) (button|filter|radio|tab|checkbox|link)$/, function (buttonName, buttonType) {
return getVariable[buttonName.replace(/\s+/g, '')].click();
});
this.Then(/^I should see (.*) x (.*) in in my shopping cart$/, function (quantity,productName, callback) {
browser.driver.get('http://myshop.com/shopping-cart).then(function () {
expect(element(by.cssContainingTest(productName)).by.css(.quantity).getText())
.to.eventually.equal(quantity).notify(callback);
});
});



No Comments


You can leave the first : )