<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Alexandre Martins &#187; Acceptance Tests</title>
	<atom:link href="http://blog.m.artins.net/tag/acceptance-tests/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.m.artins.net</link>
	<description>On Agile Software Development</description>
	<lastBuildDate>Thu, 12 Aug 2010 20:09:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Black Cards (a.k.a. Evil Stories)</title>
		<link>http://blog.m.artins.net/black-cards-aka-evil-stories/</link>
		<comments>http://blog.m.artins.net/black-cards-aka-evil-stories/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 08:34:57 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Acceptance Tests]]></category>
		<category><![CDATA[Cards]]></category>
		<category><![CDATA[Iteration Management]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=124</guid>
		<description><![CDATA[Are defined as tasks or features that represents something that needs to be fixed, because it represents a risk to the system in production (or going to). Generally they represent acceptance criteria that was not defined during development. They should have higher priority over the other stories to be implemented.]]></description>
			<content:encoded><![CDATA[<p>Are defined as tasks or features that represents something that needs to be fixed, because it represents a risk to the system in production (or going to).<br />
Generally they represent acceptance criteria that was not defined during development. They should have higher priority over the other stories to be implemented.</p>
<p><br/><img src="http://blog.m.artins.net/wp-content/uploads/2008/12/picture-2.png" style="border-width: 0px;" width="520" height="180" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/black-cards-aka-evil-stories/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Acceptance Tests With JBehave, Selenium &amp; Page Objects</title>
		<link>http://blog.m.artins.net/acceptance-tests-with-jbehave-selenium-page-objects/</link>
		<comments>http://blog.m.artins.net/acceptance-tests-with-jbehave-selenium-page-objects/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 00:30:54 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Acceptance Tests]]></category>
		<category><![CDATA[Behaviour-Driven Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JBehave]]></category>
		<category><![CDATA[Page Objects]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=117</guid>
		<description><![CDATA[Since JBehave 2.0 was released in September, I've been using it on my current project to verify the acceptance criteria for the features we are implementing, ensuring that the web interface is following the right workflow, and is displaying the data as expected, as well as some other important elements. What is JBehave? JBehave is [...]]]></description>
			<content:encoded><![CDATA[<p>Since <a href="http://jbehave.org/">JBehave 2.0</a> was released in September, I've been using it on my current project to verify the acceptance criteria for the features we are implementing, ensuring that the web interface is following the right workflow, and is displaying the data as expected, as well as some other important elements.</p>
<h3>What is JBehave?</h3>
<p>JBehave is a framework for <a href="http://behaviour-driven.org/">Behaviour-Driven Development</a>, that allows customers and developers to work together more closely on features for the system. They get together to discuss and define a set of executable criteria (scenarios) for each of the features that will be used to determine if they are fully implemented or not. The cool thing is that the scenario execution produces an easy-to-read output, so that customers can keep track of the implementation status.</p>
<h3>An Example</h3>
<p>In this example, I'm not covering all the bits and pieces about writing and running acceptance tests with JBehave. If you want to see it in details, there's a very good introduction article <a href="http://www.ryangreenhall.com/articles/bdd-by-example.html">here</a>. The intention is to show how we are doing it on my project, integrating with <a href="http://selenium.openqa.org/">Selenium</a> and using the <a href="http://code.google.com/p/webdriver/wiki/PageObjects">Page Objects</a> pattern.</p>
<h4>New Feature</h4>
<p>Suppose the customer wanted to provide exclusive content for the user of the website. For that, we would have to implement an authentication framework, so that we could guarantee that only registered users would access that content. So the story looks like this:</p>
<pre style="border: solid gray 1px; width: 80%; padding: 10px; margin:10px;">
As an user
I want to login into the website
So that I can view the exclusive contents
</pre>
<h4>Defining Scenarios</h4>
<pre style="border: solid gray 1px; width: 80%; padding: 10px; margin:10px;">
<strong>Scenario: Invalid Username</strong>
Given the user is on the login page
 When the user types username <em>wrong!</em>
  And the user types password <em>123456</em>
  And clicks the login button
 Then the page should display <em>Invalid Authentication</em> message

<strong>Scenario: Successful Login</strong>
Given the user is on the login page
 When the user types username <em>alexandre</em>
  And the user types password <em>123456</em>
  And clicks the login button
 Then the user should be redirected to home page
  And the page should display welcome message to <em>alexandre</em>
</pre>
<p>Each scenario needs its own implementation, providing the necessary steps to be verified, in our case the LoginSteps class. Another improvement on version 2.0 is that it allows you to define multiple scenarios in a single file.</p>
<pre name="code" class="java">
public class LoginScenarios extends Scenario {
	public LoginScenarios() {
		super(new LoginSteps());
	}
}
</pre>
<p><strong>Defining Steps (Integrating Selenium)</strong></p>
<p>After defining the scenarios on the text file, it's time to map each scenario step to its implementation. Once you start mapping them you will come across ones that are already mapped, and will realise that defining new scenarios is just a matter of combining existing steps.</p>
<p>Initially, for each step, we were extracting the code sniped from Selenium IDE record and placing into it. But it felt a bit clumsy, with code duplication in some spots. It quickly reminded me how hard it is to maintain a suite of tests when it starts evolve and there is not enough effort on refactoring. We wanted to avoid duplication and come up with a more elegant and reusable solution. </p>
<p>One day my friend Uday Rayala came up with the idea of using the Page Objects pattern for writing our acceptance tests, so that we could encapsulate the logic to interact and verify page state into these objects. The first time I heard about it was from <a href="http://pubbitch.org/blog/">Simon Stewart</a>, when he was in Sydney for the JAOO conference. He said that they implemented <a href="http://code.google.com/p/webdriver/">WebDriver</a> based on this pattern, and showed me some examples. Here is a definition, extracted from the WebDriver wikipage:</p>
<p><cite><br />
<blockquote>Within your web app's UI there are areas that your tests interact with. A Page Object simply models these as objects within the test code. This reduces the amount of duplicated code and means that if the UI changes, the fix need only be applied in one place.</p></blockquote>
<p></cite></p>
<pre name="code" class="java">
public class LoginSteps extends Steps {

	@Given("the user is on the login page")
	public void theUserIsOnTheLoginPage() {
		LoginPage loginPage = new LoginPage();
		loginPage.verifyPresenceOfUsernameAndPasswordFields();
		loginPage.verifyPresenceOfLoginButton();
	}

	@When("the user types username $username")
	public void theUserTypesUsername(String username) {
		loginPage().typeUsername(username);
	}

	@When("the user types password $password")
	public void theUserTypesPassword(String password) {
		loginPage().typePassword(password);
	}

	@When("clicks the login button")
	public void clicksTheLoginButton() {
		loginPage().login();
	}

	@Then("the page should display $errorMessage message")
	public void thePageShouldDisplayErrorMessage(String errorMessage) {
		loginPage().verifyPresenceOfErrorMessage(errorMessage);
	}

	@Then("the user should be redirected to home page")
	public void theUserShouldBeRedirectedToHomePage() {
		HomePage homePage = new HomePage();
		homePage.verifyPage();
	}

	@Then("the page should display welcome message to $user")
	public void thePageShouldDisplayWelcomeMessage(String user) {
		homePage().verifyPresenceOfWelcomeMessageTo(user);
	}

	private LoginPage loginPage() {
		return (LoginPage) Page.current();
	}

	private HomePage homePage() {
		return (HomePage) Page.current();
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/acceptance-tests-with-jbehave-selenium-page-objects/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
