<?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>Christopher Bird &#187; selenium</title>
	<atom:link href="http://www.christopherbird.co.uk/tag/selenium/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.christopherbird.co.uk</link>
	<description>Personal and professional blog</description>
	<lastBuildDate>Mon, 21 Jun 2010 15:32:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Lessons learnt from acceptance testing&#8230; again</title>
		<link>http://www.christopherbird.co.uk/2009/12/lessons-learnt-from-acceptance-testing-again/</link>
		<comments>http://www.christopherbird.co.uk/2009/12/lessons-learnt-from-acceptance-testing-again/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 22:26:48 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[acceptance testing]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://www.christopherbird.co.uk/?p=49</guid>
		<description><![CDATA[After writing my last post i&#8217;ve been thinking more about the question of &#8220;How should i organise my tests?&#8221;. The answer i gave last time seemed to work for fixing existing tests but didn&#8217;t seem to fix the cause of the problem that all the tests were still too much like unit tests. Oh yeah, [...]]]></description>
			<content:encoded><![CDATA[<p>After writing my last post i&#8217;ve been thinking more about the question of &#8220;How should i organise my tests?&#8221;. The answer i gave last time seemed to work for fixing existing tests but didn&#8217;t seem to fix the cause of the problem that all the tests were still too much like unit tests. Oh yeah, at this point i&#8217;d like to point out i reserve the right to contradict myself.</p>
<p>While working on a separate RoR project I&#8217;ve used <a href="http://cukes.info/">Cucumber</a> to drive acceptance tests. If you&#8217;ve not tried it already, it&#8217;s great give it a go! Also on a side note i also discovered the guys who wrote selenium-client put a great deal more thought into the API than the .NET counterpart. Lots of extensions for waits and JQuery/Prototype integration are included by default. Anyway back to the problem at had, Cucumber forces you to write plain text stories (or features) and one or more scenarios for that story. Scenarios are written with each line start with &#8220;Given&#8221;, &#8220;When&#8221; and &#8220;Then&#8221; (and optionally And). Each line of the scenario corresponds to an executable &#8220;Step&#8221; that in my case performed a selenium action (or it could also quite easily perform an action against an API).</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Feature: Manage blog posts<br />
&nbsp; In order to manage my blog posts<br />
&nbsp; As a writer of poor blog posts<br />
&nbsp; I want to be able to create blog posts<br />
<br />
&nbsp; Scenario: Create a blog post <br />
&nbsp; &nbsp; Given i have clicked add blog post<br />
&nbsp; &nbsp; And i have written &quot;My first post&quot; with content &quot;My first post&quot;<br />
&nbsp; &nbsp; When i click publish<br />
&nbsp; &nbsp; Then i should see the post &quot;My first entry&quot; in the list of posts</div></div>
<p>Anyway this method of writing test with the emphasis on the behaviour of the user (not surprising for a BDD tool) meant i ended up with less focus on one bit of functionality on a single page and more on the overall journey of the users actions through the application. Each scenario taking a different path or journey through that story.</p>
<p>Overall cucumber forced me to stay true to testing behaviour, avoiding the pitfalls of the test written in a plain unit testing framework. So, try cucumber, even if you don&#8217;t use it in your project i hope it makes you think differently about how you write the same tests in your native language.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christopherbird.co.uk/2009/12/lessons-learnt-from-acceptance-testing-again/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Lessons learnt from acceptance testing (with Selenium)</title>
		<link>http://www.christopherbird.co.uk/2009/11/lessons-learnt-from-acceptance-testing-with-selenium/</link>
		<comments>http://www.christopherbird.co.uk/2009/11/lessons-learnt-from-acceptance-testing-with-selenium/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 22:34:32 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[acceptance testing]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://www.christopherbird.co.uk/?p=38</guid>
		<description><![CDATA[While recently working with automated acceptance tests I noticed two major problems. The tests had started to intermittently fail and were taking longer and longer to run. With a loss in confidence of the tests they started to fall into disrepair. This post tries to cover some of the root causes of our problems and [...]]]></description>
			<content:encoded><![CDATA[<p>While recently working with automated acceptance tests I noticed two major problems. The tests had started to intermittently fail and were taking longer and longer to run. With a loss in confidence of the tests they started to fall into disrepair.</p>
<p>This post tries to cover some of the root causes of our problems and try to suggest practices to help avoid these problem in the future. While I talk about Selenium most of these practices in theory could be applied to any automation package&#8230;</p>
<h3>What should I test with Selenium?</h3>
<p>Actually this should really be where are my tests best placed? A lot of acceptance tests seemed to delve too deeply into the functionality of a story which partially leads to the problem of too many/long running acceptance test. Try to keep acceptance tests at a high level. Anything of the story that you can test in unit tests, test it there &#8211; don&#8217;t repeat yourself in the acceptance tests.</p>
<p>Try not to use Selenium as a tool to unit test Javascript, this again dramatically increases the number of tests you have and can become very brittle when waiting for expected DOM changes. Use an appropriate Javascript unit testing tool like JsTestDriver.</p>
<h3>How should I organise my tests?</h3>
<p>One of the key problems to organising tests as if they are single unit tests is they tend to navigate to a page, change something, assert something happened then the close page. Now write 25 tests for one page and for every tests you have to wait for the page to load, which as you many expect seriously increases the time taken to run the tests. This is especially a problem testing functionality based entirely in Javascript which is relatively quick to test.</p>
<p>Where possible group all tests for a page and browse to the page once. This does leave the problem of tests effecting each other but if you remember to follow a pattern of, change something, assert something and then reset the page you shouldn&#8217;t have any problems.</p>
<p>Something else that I came across was when testing functionality on a page that was in a sequence after others, you always ended up completing the first page and then moving to the second before starting your tests. Now think about organising your tests where for each test you are completing the first page to get to the second before performing your test, they start to take a very very long time to run. This leads to organising the tests into journeys through the system (or groups of related stories that can be run in sequence) allowing us to tests each criteria as we navigate through the system.</p>
<h3>How should I organise the code that interacts with my web application?</h3>
<p>Use a page model. Construct classes that represent pages or popup windows in your application that have an interface that reflects the user interface. For example a form page that takes a name may have a page model with properties for title, first name and surname that when set or got perform the relevant selenium actions on the browser to get or set the value. This has a couple of benefits, you can reuse these page models across tests and they can be easily replaced if a better automated testing tool comes along. Another point to note is to make sure your page model interface follows a single semantic, e.g. use properties to get/set values and methods to perform actions like clicking a button. Tests tend to become very confused and actions tend to get repeated if there is no common way of defining the interface.</p>
<h3>How do I know when something has happened on the page?</h3>
<p>It&#8217;s very important to know when something has happened on the page (especially on Javascript heavy pages), if you don&#8217;t, expectations become very brittle when they check to early or to late. Hopefully your first reaction is not to start putting Thread.Sleep()&#8217;s all throughout your tests, what happens when something takes longer than you expected? The best way to solve this problem in Selenium is to use the built-in WaitForCondition(condition, timeout) method. You can give a condition in Javascript which has access to the client side Selenium object. For example you can do things like this&#8230; </p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">selenium<span style="color: #008000;">.</span><span style="color: #0000FF;">WaitForCondition</span><span style="color: #008000;">&#40;</span><br />
&nbsp; <span style="color: #666666;">&quot;selenium.isElementPresent('result-div')&quot;</span>, <br />
&nbsp; <span style="color: #666666;">&quot;1000&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p>The important difference between this and Thread.Sleep() is that you can give longer timeout periods. A Thread.Sleep() will always make your tests wait for that period of time where as WaitForCondition will move on once the condition is met. This allow you to account for differences in the speed tests run without making your tests take longer and longer to run when increasing Thread.Sleep times.</p>
<h3>Summary</h3>
<ul>
<li>Test where it is most appropriate.</li>
<li>Group tests into journeys where possible.</li>
<li>Hide selenium browser interactions behind page models.</li>
<li>Don&#8217;t Sleep just WaitForCondition&#8217;s to happen.</li>
<ul>
]]></content:encoded>
			<wfw:commentRss>http://www.christopherbird.co.uk/2009/11/lessons-learnt-from-acceptance-testing-with-selenium/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
