<?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>Sarah Mei &#187; selenium</title>
	<atom:link href="http://www.sarahmei.com/blog/tag/selenium/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sarahmei.com/blog</link>
	<description></description>
	<lastBuildDate>Sun, 22 Jan 2012 20:16:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Running Cucumber Features Without a Display</title>
		<link>http://www.sarahmei.com/blog/2010/12/17/cucumber-without-a-display/</link>
		<comments>http://www.sarahmei.com/blog/2010/12/17/cucumber-without-a-display/#comments</comments>
		<pubDate>Fri, 17 Dec 2010 07:41:30 +0000</pubDate>
		<dc:creator>sarahmei</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[ci]]></category>
		<category><![CDATA[cucumber]]></category>
		<category><![CDATA[diaspora]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://www.sarahmei.com/blog/?p=764</guid>
		<description><![CDATA[I&#8217;ve been helping out with the Diaspora project, an open source social network that gives you control over your own data. When I first started poking around the codebase a few months ago, they&#8217;d just started writing a few cucumber selenium integration tests &#8211; which of course I want to encourage! &#8211; but they weren&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been helping out with <a href="http://joindiaspora.com" target="_blank">the Diaspora project</a>, an <a href="http://github.com/diaspora/diaspora" target="_blank">open source</a> <a href="http://www.sarahmei.com/blog/2010/07/25/safe-facebooking/" target="_blank">social network</a> that gives you control over your own data.</p>
<p>When I first started poking around the codebase a few months ago, they&#8217;d just started writing a few <a href="http://cukes.info" target="_blank">cucumber</a><a></a> <a href="http://seleniumhq.org" target="_blank">selenium</a> integration tests &#8211; which of course <a href="http://www.sarahmei.com/blog/2010/05/29/outside-in-bdd/" target="_blank">I want to encourage!</a> &#8211; but they weren&#8217;t running them on their <a href="http://ci.joindiaspora.com" target="_blank">continuous integration box</a>.  And if you aren&#8217;t running them on CI, you can&#8217;t really call them tests&#8230;</p>
<p>It&#8217;s not that the developers were lazy; it&#8217;s just that Diaspora&#8217;s CI box is an ubuntu server instance that doesn&#8217;t even have xwindows. There&#8217;s no way to attach a display, and without a display, a browser won&#8217;t run. So how can you run selenium features that have to actually open a browser window and click on stuff?<br />
<span id="more-764"></span><br />
<strong>I&#8217;m glad you asked!</strong></p>
<p>You set up a virtual framebuffer &#8211; essentially a simulated display &#8211; and run your features in there. Here&#8217;s how I got this going.</p>
<h3>Step 1: Install Crap</h3>
<p>Yeah, you need xwindows, and a bunch of other stuff. I&#8217;m not a frequent linux user, so I was surprised that a lot of these commands appeared to fail, with extremely lengthy output about how such-and-such dependency could not be installed, or compiled, or resolved, or kafloozled, or whatever. But then when I ran the programs that supposedly weren&#8217;t installed, they worked fine. &#8230;thanks, ubuntu?</p>
<p><code> </code></p>
<pre><code>sudo aptitude install xubuntu-desktop
sudo aptitude install exaile
sudo aptitude install gconf2
sudo aptitude install xvfb
sudo aptitude install firefox
</code></pre>
<p><code> </code></p>
<h3>Step 2: Verify Your Virtual Framebuffer</h3>
<p>I like the phrase &#8220;virtual framebuffer.&#8221; It&#8217;s very computer science, and using it makes me feel smart. But really, it&#8217;s just a display that gets rendered in memory, but not output to any monitor. Programs that require the ability to create windows, such as Firefox, need a display to run in &#8211; but they&#8217;ll take any old display. If you give Firefox a virtual framebuffer, it&#8217;s perfectly happy and treats it like any other display, even though no one can see it.</p>
<p>So let&#8217;s verify we have everything set up to run one. This magic incantation starts one on display port :99.</p>
<p><code> </code></p>
<pre><code> Xvfb :99 -ac -screen 0 1024x768x16
</code></pre>
<p><code> </code></p>
<p>In another shell, run this one, which opens Firefox to example.org inside the virtual display you&#8217;re running in the original shell.</p>
<p><code> </code></p>
<pre><code>DISPLAY=:99.0 firefox http://example.org
</code></pre>
<p><code> </code></p>
<p>Firefox is now open to example.org, the world&#8217;s most boring webpage. Really! Let&#8217;s prove it by taking a screenshot in a third shell.</p>
<p><code> </code></p>
<pre><code>xwd -root -display :99.0 -out xwdout
</code></pre>
<p><code> </code></p>
<p>Your screenshot is now in a file called xwdout. Sadly, this is not an image format that normal image viewers can see, so let&#8217;s convert it to a jpeg.</p>
<p><code> </code></p>
<pre><code>convert xwdout screenshot.jpg
</code></pre>
<p><code> </code></p>
<p>Using your favorite sftp program, retrieve screenshot.jpg and have a look at it. It should look something like this:</p>
<div id="attachment_894" class="wp-caption aligncenter" style="width: 1003px"><a href="http://www.sarahmei.com/blog/wp-content/uploads/2010/12/screenshot1.jpg"><img class="size-full wp-image-894" title="screenshot" src="http://www.sarahmei.com/blog/wp-content/uploads/2010/12/screenshot1.jpg" alt="Yup, a screenshot." width="993" height="282" /></a><p class="wp-caption-text">That boxy UI, those icons from 1995...it could only be linux.</p></div>
<p>Ta-da! You have evidence of this so-called &#8220;virtual&#8221; framebuffer. Now all we have to do is set it up so to start before we run the tests, and stop once the tests are done.</p>
<h3>Step 3: Adventures in Shell Scripting</h3>
<p>This goes in your /etc/init.d, and will give you ULTIMATE POWER, if ultimate means you can start and stop a virtual framebuffer on display port :99.</p>
<p><script src="https://gist.github.com/744561.js"></script> </p>
<p>Now you just need a rake task that starts the display, passes the port info to the tests, and then stops it.  </p>
<p><script src="https://gist.github.com/744607.js?file=gistfile1.rb"></script></p>
<p>And just in case you have to get this running with <a href="http://rvm.beginrescueend.com" target="_blank">rvm</a>, here&#8217;s the shell script that <a href="http://cruisecontrolrb.thoughtworks.com/" target="_blank">cc.rb</a> calls to kick off a Diaspora build on ruby 1.8.7.</p>
<p><script src="https://gist.github.com/744612.js?file=gistfile1.txt"></script></p>
<p>I&#8217;ve had to set this up twice, now, but there are a lot of moving parts. If you try this and notice something I forgot, please let me know.</p>
<p>Enjoy your headless cucumbers&#8230;</p>
<p><span style="color: #b2b2b2;">(I wonder what kind of google search results <strong>that</strong> will get me.)</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sarahmei.com/blog/2010/12/17/cucumber-without-a-display/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>GoGaRuCo, Day 2</title>
		<link>http://www.sarahmei.com/blog/2009/04/26/gogaruco-day-2/</link>
		<comments>http://www.sarahmei.com/blog/2009/04/26/gogaruco-day-2/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 07:21:39 +0000</pubDate>
		<dc:creator>sarahmei</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[ghana]]></category>
		<category><![CDATA[gogaruco]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[webrat]]></category>

		<guid isPermaLink="false">http://www.sarahmei.com/blog/?p=44</guid>
		<description><![CDATA[Well, I was totally gung-ho about writing up GoGaRuCo Day 1, but it&#8217;s taken me a week to get day 2 done. Part of that was exhaustion &#8211; between the conference on Friday and Saturday, the hackathon on Sunday, and, uh, working the five days after that, it&#8217;s kind of been full-speed until today. Part [...]]]></description>
			<content:encoded><![CDATA[<p>Well, I was totally gung-ho about writing up <a href="http://www.sarahmei.com/blog/?p=6">GoGaRuCo Day 1</a>, but it&#8217;s taken me a week to get day 2 done.</p>
<p>Part of that was exhaustion &#8211; between the conference on Friday and Saturday, the hackathon on Sunday, and, uh, working the five days after that, it&#8217;s kind of been full-speed until today. Part of it, though, was also that the second day <a href="http://www.sarahmei.com/blog/?p=46">wasn&#8217;t as positive an experience</a> for me. It&#8217;s taken me some time to collect my thoughts.</p>
<p>Rather than touching on every presentation, I just want to note a few of them that I really liked.</p>
<p>First, there was Jacqui Maher&#8217;s presentation on the work she&#8217;s been doing with Baobab in Malawi. Back in 2000, I spent three months in Ghana helping a software company in Accra go from Delphi/C++/Windows to an open source stack based on linux and Java. It was an incredible experience, but since then I haven&#8217;t been able to reconcile my desire to help with my actual skills. I mean, the Peace Corps is awesome and good for you if you want to do it, but they&#8217;d have had me teaching math or something. I want to code.</p>
<p>So I&#8217;m thankful Jacqui came and talked about this project. I don&#8217;t think any of my code has ever had a measurable life-saving effect. Perhaps that should change.</p>
<p>The Webrat talk from Bryan Helmkamp was also really interesting. At Looksmart we have a huge Selenium test suite, and I&#8217;m not at all happy with it. I will likely gravitate towards talks on different methods of acceptance testing at Railsconf &#8211; Webrat looks interesting. It doesn&#8217;t actually fire up a browser, so it&#8217;s faster, and you can drop down into Selenium when you need to test Javascript.</p>
<p>By the end of the day, my brain was full. People tell me the last talk was great, but I have very little memory of it. Hopefully the justin.tv folks who were filming the talks will have it up soon so I can see it when I&#8217;m in a state to appreciate it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sarahmei.com/blog/2009/04/26/gogaruco-day-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

