<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><description>Jarmo Pertman is an enthusiastic developer using the Ruby programming language. He is one of the core developers of the popular automated testing framework Watir. He is also responsible for some other libraries like WatirSplash, RAutomation, Win32::Screenshot and require_all. IT Really Matters is his personal blog where he tries to write about stuff that really matter in IT.</description><title>IT Really Matters</title><generator>Tumblr (3.0; @itreallymatters)</generator><link>http://itreallymatters.net/</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ITReallyMatters" /><feedburner:info uri="itreallymatters" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://tumblr.superfeedr.com/" /><item><title>Real Life Photoshop</title><description>&lt;img src="http://25.media.tumblr.com/tumblr_lyv8lr0yNk1qa9b99o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;Real Life Photoshop&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/o6OXLYQ91pc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/o6OXLYQ91pc/17025098628</link><guid isPermaLink="false">http://itreallymatters.net/post/17025098628</guid><pubDate>Sat, 04 Feb 2012 13:15:27 +0200</pubDate><feedburner:origLink>http://itreallymatters.net/post/17025098628</feedburner:origLink></item><item><title>Browser Wars</title><description>&lt;img src="http://28.media.tumblr.com/tumblr_lxp20nt45l1qa9b99o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;Browser Wars&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/lk4YsT92IB8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/lk4YsT92IB8/15725987270</link><guid isPermaLink="false">http://itreallymatters.net/post/15725987270</guid><pubDate>Thu, 12 Jan 2012 18:33:59 +0200</pubDate><category>browser</category><feedburner:origLink>http://itreallymatters.net/post/15725987270</feedburner:origLink></item><item><title>Today’s Marriage</title><description>&lt;img src="http://30.media.tumblr.com/tumblr_luyn61HZir1qa9b99o1_400.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;Today’s Marriage&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/db1QH4LR2_k" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/db1QH4LR2_k/13873791902</link><guid isPermaLink="false">http://itreallymatters.net/post/13873791902</guid><pubDate>Wed, 07 Dec 2011 17:00:06 +0200</pubDate><feedburner:origLink>http://itreallymatters.net/post/13873791902</feedburner:origLink></item><item><title>Harmless Checkin</title><description>&lt;img src="http://27.media.tumblr.com/tumblr_luyn0ws8VS1qa9b99o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;Harmless Checkin&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/cMVxYBdrjOE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/cMVxYBdrjOE/13546762581</link><guid isPermaLink="false">http://itreallymatters.net/post/13546762581</guid><pubDate>Wed, 30 Nov 2011 17:02:05 +0200</pubDate><feedburner:origLink>http://itreallymatters.net/post/13546762581</feedburner:origLink></item><item><title>Freaky Wireless Technology</title><description>&lt;img src="http://28.media.tumblr.com/tumblr_luymwwHKwZ1qa9b99o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;Freaky Wireless Technology&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/PuHb6d8pc7U" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/PuHb6d8pc7U/13205113238</link><guid isPermaLink="false">http://itreallymatters.net/post/13205113238</guid><pubDate>Wed, 23 Nov 2011 17:01:05 +0200</pubDate><feedburner:origLink>http://itreallymatters.net/post/13205113238</feedburner:origLink></item><item><title>Speedup Ruby 1.9.3 On Windows</title><description>&lt;p&gt;
&lt;a href="http://ruby-lang.org" target="_blank"&gt;Ruby&lt;/a&gt; is a great programming language, but unfortunately it does have some problems when using on Windows. One of it’s biggest drawbacks is it’s slowness when loading files. This is also slower than it ought to be on Unix platforms, but not as slow as on Windows. Thankfully there is some work going on to make it faster in future versions. It’s already possible to make it faster yourself!
&lt;/p&gt;

&lt;h3&gt;Benchmarks&lt;/h3&gt;

&lt;p&gt;
I will conduct two types of benchmarks. Firstly i’m gonna create an empty Rails 3 project and see how much time would it boot up. Secondly there is a project called &lt;a href="https://github.com/jonforums/measurements" target="_blank"&gt;measurements&lt;/a&gt; which allows to perform some operations on your Ruby and one of these are benchmarks for loading files. Let’s see how it goes for Ruby 1.9.2, 1.9.3 from RubyInstaller and patched 1.9.3.
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
# ruby 1.9.2p136

C:\&gt;rails new empty-192 -d sqlite3
# ...
Using rails (3.1.1)

C:\empty-192&gt;timer ruby script\rails runner ""
      user     system      total        real
  0.000000   0.016000   0.016000 ( 28.808579)

C:\measurements&gt;rci bench core_require_empty &amp;&amp; rci bench core_require_nested
ruby 1.9.2p136 (2010-12-25) [i386-mingw32]
Rehearsal ------------------------------------------------------
core_require_empty   2.917000   7.722000  10.639000 ( 10.755556)
-------------------------------------------- total: 10.639000sec

                         user     system      total        real
core_require_empty   3.167000   7.815000  10.982000 ( 11.133547)
ruby 1.9.2p136 (2010-12-25) [i386-mingw32]
Rehearsal -------------------------------------------------------
core_require_nested   3.556000   8.736000  12.292000 ( 12.453693)
--------------------------------------------- total: 12.292000sec

                          user     system      total        real
core_require_nested   3.526000   9.188000  12.714000 ( 13.157714)


# ruby 1.9.3p0 from RubyInstaller

C:\&gt;rails new empty-193-p0 -d sqlite3
# ...
Using rails (3.1.1)

C:\empty-193-p0&gt;timer ruby script\rails runner ""
       user     system      total        real
   0.000000   0.000000   0.000000 ( 17.425940)

C:\measurements&gt;rci bench core_require_empty &amp;&amp; rci bench core_require_nested
ruby 1.9.3p0 (2011-10-30) [i386-mingw32]
Rehearsal ------------------------------------------------------
core_require_empty   3.120000   9.937000  13.057000 ( 13.278704)
-------------------------------------------- total: 13.057000sec

                         user     system      total        real
core_require_empty   3.167000   9.578000  12.745000 ( 13.231747)
ruby 1.9.3p0 (2011-10-30) [i386-mingw32]
Rehearsal -------------------------------------------------------
core_require_nested   3.822000  11.373000  15.195000 ( 15.853803)
--------------------------------------------- total: 15.195000sec

                          user     system      total        real
core_require_nested   3.822000  11.653000  15.475000 ( 16.779881)


# Ruby 1.9.3p0 patched

C:\&gt;rails new empty-193-faster -d sqlite3
# ...
Using rails (3.1.1)

C:\empty-193-faster&gt;timer ruby script\rails runner ""
       user     system      total        real
   0.000000   0.000000   0.000000 (  9.184323)

C:\measurements&gt;rci bench core_require_empty &amp;&amp; rci bench core_require_nested
ruby 1.9.3p0 (2011-11-08 revision 33661) [i386-mingw32]
Rehearsal ------------------------------------------------------
core_require_empty   2.620000   5.616000   8.236000 (  9.144510)
--------------------------------------------- total: 8.236000sec

                         user     system      total        real
core_require_empty   2.247000   5.179000   7.426000 (  7.930452)
ruby 1.9.3p0 (2011-11-08 revision 33661) [i386-mingw32]
Rehearsal -------------------------------------------------------
core_require_nested   2.496000   5.522000   8.018000 (  8.123630)
---------------------------------------------- total: 8.018000sec

                          user     system      total        real
core_require_nested   2.652000   5.960000   8.612000 (  8.861500)
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1360438.js?file=bench.txt"&gt;&lt;/script&gt;&lt;p&gt;
These benchmarks show that Ruby 1.9.2 is really slow and patched 1.9.3 got about 50% performance boost compared to regular 1.9.3. That’s something to be happy about! I’m using average laptop PC which means that if you have a more decent hardware then the results might be very different from me.
&lt;/p&gt;

&lt;h3&gt;Prerequisites&lt;/h3&gt;

&lt;p&gt;
The following components are needed to speedup your Ruby:
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Ruby 1.9.3 from &lt;a href="http://rubyinstaller.org/downloads/" target="_blank"&gt;RubyInstaller&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://rubyinstaller.org/downloads/" target="_blank"&gt;Devkit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://code.google.com/p/msysgit/" target="_blank"&gt;Git&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;
If you’d like to skip all that hassle of building all the things yourself then you can download already prebuilt patched Ruby versions too! Read the “Faster Way” part about that below.
&lt;/p&gt;

&lt;h3&gt;Get Fenix&lt;/h3&gt;

&lt;p&gt;
&lt;a href="https://github.com/luislavena/fenix" target="_blank"&gt;Fenix&lt;/a&gt; is a Ruby extension written by &lt;a href="http://twitter.com/luislavena" target="_blank"&gt;Luis Lavena&lt;/a&gt;. Luis is a really helpful and great guy, at least when it comes to Ruby on Windows. He is part of the Ruby core team, is the main man behind RubyInstaller and has created many nice libraries like &lt;a href="https://github.com/luislavena/rake-compiler" target="_blank"&gt;sqlite3-ruby&lt;/a&gt;, &lt;a href="https://github.com/luislavena/rake-compiler" target="_blank"&gt;rake-compiler&lt;/a&gt; and &lt;a href="https://github.com/luislavena" target="_blank"&gt;many others&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
Back to Fenix. It changes &lt;i&gt;File.expand_path&lt;/i&gt; method to be faster. All the 50% speedup seen from the benchmarks were coming from this change since this method is called more than once when loading files. Pretty impressive or rather sad bottleneck in Ruby. Get the Fenix extension, compile and benchmark it:
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
C:\&gt;git clone git://github.com/luislavena/fenix.git
Initialized empty Git repository in C:/fenix/.git/
# ...

C:\&gt;devkit\devkitvars.bat
Adding the DevKit to PATH...

C:\fenix&gt;rake compile
# ...
install -c tmp/i386-mingw32/fenix/1.9.3/fenix.so lib/fenix.so

C:\fenix&gt;rake bench
File.expand_path: 10000 times.
                                user     system      total        real
Ruby ''                     0.297000   0.593000   0.890000 (  0.884027)
Fenix ''                    0.062000   0.000000   0.062000 (  0.066004)
Ruby '.'                    0.312000   0.546000   0.858000 (  0.876040)
Fenix '.'                   0.062000   0.000000   0.062000 (  0.060000)
Ruby 'foo', 'bar'           0.312000   0.983000   1.295000 (  1.328060)
Fenix 'foo', 'bar'          0.078000   0.000000   0.078000 (  0.106003)
Ruby '', 'C:/'              0.031000   0.000000   0.031000 (  0.031000)
Fenix '', 'C:/'             0.047000   0.000000   0.047000 (  0.050000)
Ruby 'foo', 'C:/'           0.171000   1.965000   2.136000 (  2.248100)
Fenix 'foo', 'C:/'          0.047000   0.000000   0.047000 (  0.054003)
Ruby '~'                    0.530000   0.562000   1.092000 (  1.111063)
Fenix '~'                   0.094000   0.000000   0.094000 (  0.100006)
Ruby '~/foo'                0.468000   0.827000   1.295000 (  1.321076)
Fenix '~/foo'               0.078000   0.000000   0.078000 (  0.076005)
Ruby 'foo/'                 0.280000   0.624000   0.904000 (  0.917052)
Fenix 'foo/'                0.078000   0.000000   0.078000 (  0.071004)
Ruby '~', 'C:/Foo'          0.375000   0.717000   1.092000 (  1.110063)
Fenix '~', 'C:/Foo'         0.093000   0.000000   0.093000 (  0.090005)
Ruby long_path              0.203000   0.016000   0.219000 (  0.214006)
Fenix long_path             0.203000   0.000000   0.203000 (  0.207005)
Ruby long_path, 'rel'       0.421000   0.734000   1.155000 (  1.237058)
Fenix long_path, 'rel'      0.234000   0.000000   0.234000 (  0.227013)
Ruby long_path, 'C:/Foo'    0.375000   1.981000   2.356000 (  2.470126)
Fenix long_path, 'C:/Foo'   0.187000   0.000000   0.187000 (  0.184010)
Ruby full_long_path         0.156000   0.015000   0.171000 (  0.170010)
Fenix full_long_path        0.156000   0.000000   0.156000 (  0.183011)
Ruby to_path                0.234000   0.359000   0.593000 (  0.619036)
Fenix to_path               0.062000   0.000000   0.062000 (  0.071004)
Ruby to_path, 'rel'         0.468000   0.999000   1.467000 (  1.455083)
Fenix to_path, 'rel'        0.094000   0.000000   0.094000 (  0.091006)
Ruby to_path, 'C:/Foo'      0.390000   2.262000   2.652000 (  2.844161)
Fenix to_path, 'C:/Foo'     0.078000   0.000000   0.078000 (  0.090005)
Ruby full_to_path           0.390000   1.950000   2.340000 (  2.526143)
Fenix full_to_path          0.031000   0.000000   0.031000 (  0.044003)
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1360438.js?file=fenix.txt"&gt;&lt;/script&gt;&lt;p&gt;
Not bad benchmark results.
&lt;/p&gt;

&lt;h3&gt;Patching &amp; Compiling Ruby&lt;/h3&gt;

&lt;p&gt;
Unfortunately only &lt;i&gt;File.expand_path&lt;/i&gt; method is faster when using this extension, but there’s Ruby’s &lt;i&gt;require&lt;/i&gt; and &lt;i&gt;load&lt;/i&gt; methods, which also execute &lt;i&gt;expand_path&lt;/i&gt;, but they will do so by using internal C &lt;i&gt;expand_path&lt;/i&gt; function instead. Solution for that problem is to patch Ruby code to use &lt;i&gt;Fenix.expand_path&lt;/i&gt; internally also! First step would be to clone Ruby itself (make sure that line endings are not converted by Git):
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
C:\&gt;git config --global core.autocrlf false &amp;&amp; git clone -b ruby_1_9_3 git@github.com:ruby/ruby.git
Initialized empty Git repository in C:/ruby/.git/
# ...
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1360438.js?file=ruby.txt"&gt;&lt;/script&gt;&lt;p&gt;
Apply the &lt;a href="https://gist.github.com/1360449#file_0001_make_load_and_require_use_file_expand_path_and_file_realpath.diff" target="_blank"&gt;patch created by Luis&lt;/a&gt;:
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
C:\ruby&gt;git clone git://gist.github.com/1360449.git expand_path-patch
C:\ruby&gt;git apply -v expand_path-patch\0001-make-load-and-require-use-file-expand_path-and-file-realpath.diff
Checking patch file.c...
Checking patch load.c...
Applied patch file.c cleanly.
Applied patch load.c cleanly.

C:\ruby&gt;git status
# On branch ruby_1_9_3
# Changed but not updated:
#   (use "git add &lt;file&gt;..." to update what will be committed)
#   (use "git checkout -- &lt;file&gt;..." to discard changes in working directory)
#
#       modified:   file.c
#       modified:   load.c
&lt;/file&gt;&lt;/file&gt;&lt;/pre&gt;
&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1360438.js?file=patch.txt"&gt;&lt;/script&gt;&lt;p&gt;
`git status` shows us that &lt;i&gt;file.c&lt;/i&gt; and &lt;i&gt;load.c&lt;/i&gt; files are modified. It’s time to start compiling Ruby itself. Best way to do that would be to use RubyInstaller itself (how ironic, we’re using Ruby to build Ruby). Make sure to disable ANSICON too since it is known to cause problems during the compilation process:
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
C:\rubyinstaller&gt;..\ansicon\x64\ansicon.exe -u
C:\rubyinstaller&gt;rake ruby19 NOGEMS=1 NOTK=1 LOCAL=..\ruby
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1360438.js?file=ruby_compile.txt"&gt;&lt;/script&gt;&lt;p&gt;
This takes some time and if the process raises any errors, just try again. If there’s still errors don’t hesitate to write to &lt;a href="http://groups.google.com/group/rubyinstaller" target="_blank"&gt;RubyInstaller mailing list&lt;/a&gt; or contact Luis directly. He’s very helpful, as i already stated above.
&lt;/p&gt;

&lt;p&gt;
After the process is done “install” new Ruby with Fenix and make sure that it’s used by setting environment variables too:
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
C:\rubyinstaller&gt;xcopy /E /I sandbox\ruby19_mingw \ruby193-faster
# ...
C:\rubyinstaller&gt;cd ..\fenix
C:\fenix&gt;xcopy /E /I lib \ruby193-faster\lib\ruby\1.9.1\i386-mingw32
lib\fenix.so
lib\fenix\replace.rb
2 File(s) copied
C:\fenix&gt;set PATH=c:\ruby193-faster\bin;%PATH%
C:\fenix&gt;set RUBYOPT=-rfenix/replace
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1360438.js?file=install.txt"&gt;&lt;/script&gt;&lt;p&gt;
Make sure that the PATH and RUBYOPT environment variables are set permanently. And try it out if it’s faster for you too!
&lt;/p&gt;

&lt;h3&gt;Faster Way&lt;/h3&gt;

&lt;p&gt;
In case you don’t want to spend your time cloning, compiling and testing then there is a faster way to boost your Ruby. There exists a project called &lt;a href="http://thecodeshop.github.com/" target="_blank"&gt;The Code Shop&lt;/a&gt;, which tries to solve the Ruby performance problem on Windows. It makes different &lt;a href="https://github.com/thecodeshop/ruby/wiki/Downloads" target="_blank"&gt;builds available to download&lt;/a&gt;, each experimenting with different set of patches. I can recommend tcs-ruby193_require_winio_fenix-20111113 because it seems to be the fastest. Here are some benchmark results: 
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
# tcs-ruby193_winio_fenix-20111113
C:\empty-193&gt;timer ruby script\rails runner ""
       user     system      total        real
   0.000000   0.000000   0.000000 (  6.802955)


C:\measurements&gt;rci bench core_require_empty &amp;&amp; rci bench core_require_nested
tcs-ruby 1.9.3p0 (2011-11-08) [i386-mingw32]
Rehearsal ------------------------------------------------------
core_require_empty   2.044000   2.589000   4.633000 (  4.726269)
--------------------------------------------- total: 4.633000sec

                         user     system      total        real
core_require_empty   1.778000   2.746000   4.524000 (  4.652266)
tcs-ruby 1.9.3p0 (2011-11-08) [i386-mingw32]
Rehearsal -------------------------------------------------------
core_require_nested   2.075000   3.603000   5.678000 (  5.779272)
---------------------------------------------- total: 5.678000sec

                          user     system      total        real
core_require_nested   2.028000   3.526000   5.554000 (  5.791128)



# tcs-ruby193_require_winio_fenix-20111113
C:\empty-193&gt;timer ruby script\rails runner ""
       user     system      total        real
   0.000000   0.000000   0.000000 (  5.635120)


C:\measurements&gt;rci bench core_require_empty &amp;&amp; rci bench core_require_nested
tcs-ruby 1.9.3p0 (2011-11-08) [i386-mingw32]
Rehearsal ------------------------------------------------------
core_require_empty   1.497000   2.948000   4.445000 (  4.571255)
--------------------------------------------- total: 4.445000sec

                         user     system      total        real
core_require_empty   1.326000   3.151000   4.477000 (  4.577208)
tcs-ruby 1.9.3p0 (2011-11-08) [i386-mingw32]
Rehearsal -------------------------------------------------------
core_require_nested   1.732000   3.650000   5.382000 (  5.529468)
---------------------------------------------- total: 5.382000sec

                          user     system      total        real
core_require_nested   1.716000   3.604000   5.320000 (  5.437311)
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1360438.js?file=tcs_bench.txt"&gt;&lt;/script&gt;&lt;p&gt;
Fenix is already precompiled into these builds. You still need to &lt;del&gt;compile and install Fenix and&lt;/del&gt; set PATH and RUBYOPT environments as described above.
&lt;/p&gt;

&lt;h3&gt;In Conclusion&lt;/h3&gt;

&lt;p&gt;
The main point of this post is that things aren’t always as rosy as they could be, but it’s possible to make them better. It is really valuable that you give feedback to projects like The Code Shop (e.g. what are your benchmark results) so the final result could get better in the future without any additional hassle for everyone. I hope that you can now start your engines much faster!
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/glkZ1QrgIe4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/glkZ1QrgIe4/12897174267</link><guid isPermaLink="false">http://itreallymatters.net/post/12897174267</guid><pubDate>Thu, 17 Nov 2011 00:37:00 +0200</pubDate><category>ruby</category><feedburner:origLink>http://itreallymatters.net/post/12897174267</feedburner:origLink></item><item><title>An Update is Available for Your Computer</title><description>&lt;img src="http://25.media.tumblr.com/tumblr_lueug366tt1qa9b99o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;An Update is Available for Your Computer&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/BrnO8eYY1XQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/BrnO8eYY1XQ/12566068902</link><guid isPermaLink="false">http://itreallymatters.net/post/12566068902</guid><pubDate>Wed, 09 Nov 2011 22:33:39 +0200</pubDate><feedburner:origLink>http://itreallymatters.net/post/12566068902</feedburner:origLink></item><item><title>Awesome Page Objects In Testing</title><description>&lt;p&gt;
I mentioned &lt;i&gt;page objects&lt;/i&gt; in the &lt;a href="http://itreallymatters.net/post/9085718628/watirsplash-2" target="_blank"&gt;post about WatirSplash 2&lt;/a&gt;. In this post i’m gonna explain what these things exactly are and how to use them.
&lt;/p&gt;

&lt;h3&gt;What Is A Page?&lt;/h3&gt;

&lt;p&gt;
When it comes to automated testing then the page is really nothing else than the page user sees when visiting the website. Any meaningful page consists of different components some of which just show information (e.g. text) others allow interaction (e.g. text fields and buttons). Different pages might also have some shared content like header, search field and footer. One important thing about components is that the result of some interactions is another page.
&lt;/p&gt;

&lt;p&gt;
Let me bring you a concrete example. Let’s look at the &lt;a href="http://bing.com" target="_blank"&gt;Bing’s main page&lt;/a&gt; (enough of Google in all examples, alright). You can think of the possible sections (Web, Images, Videos, News and More) as a header. There is also the &lt;i&gt;search field&lt;/i&gt; and &lt;i&gt;button&lt;/i&gt;. &lt;i&gt;Search button&lt;/i&gt; is special since clicking on it changes the current page to &lt;i&gt;results page&lt;/i&gt;. Makes sense? Let’s see how to convert that information into &lt;i&gt;WatirSplash Page Objects&lt;/i&gt;.
&lt;/p&gt;

&lt;h3&gt;Point Of Having Page Objects&lt;/h3&gt;

&lt;p&gt;
The point of having Page Objects is to have better structured code and keep it &lt;a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself" target="_blank"&gt;DRY&lt;/a&gt; in your tests too. This all makes your tests easier to maintain. If you’re a software developer then you care about these things when it comes to production code. Why not to use these good practices in tests also? Page Objects make it all possible. Having Page Objects means that it should be easier to change your tests if the application under test (AUT) changes since you need only one place (ideally) to change. Page Objects also make it very clear where to find existing and put the new code.
&lt;/p&gt;

&lt;h3&gt;Let’s Get Rockin’ With Pages And Objects&lt;/h3&gt;

&lt;p&gt;
Let’s get more concrete. I assume that you have created a WatirSplash 2 project already. If not then follow the instructions in the &lt;a href="http://itreallymatters.net/post/9085718628/watirsplash-2" target="_blank"&gt;post about WatirSplash 2&lt;/a&gt; or read everything you need to know straight from the &lt;a href="https://github.com/jarmo/WatirSplash/blob/master/README.rdoc" target="_blank"&gt;README&lt;/a&gt;. Let’s create the Main page first:
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
C:\my_project\ui-test&gt;watirsplash page main --url &lt;a href="http://bing.com" target="_blank"&gt;http://bing.com&lt;/a&gt;
      create  lib
      create  lib/app/page/main.rb
       exist  spec
      create  spec/app/page/main_spec.rb
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1325268.js?file=main.cmd"&gt;&lt;/script&gt;&lt;p&gt;
This command created us the Main page object and a test for it. The generated file looks like this:
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
# lib/app/page/main.rb
module App
  module Page
    class Main 
&lt;/pre&gt;&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1325268.js?file=main.rb"&gt;&lt;/script&gt;&lt;p&gt;
And the test itself is nothing fancy yet:
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
# spec/app/page/main_spec.rb
describe App::Page::Main do
  it "has something on the main page" do
    main_page = App::Page::Main.new
  end
end
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1325268.js?file=main_spec.rb"&gt;&lt;/script&gt;&lt;p&gt;
Let’s add something meaningful to our Main page object like search field and button:
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
# lib/app/page/main.rb
module App
  module Page
    class Main  "q")
      end

      def search_button
        button(:name =&gt; "go")
      end
    end
  end
end
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1325268.js?file=main_2.rb"&gt;&lt;/script&gt;&lt;p&gt;
You can use all the familiar &lt;a href="http://watir.com" target="_blank"&gt;Watir&lt;/a&gt; methods directly in your Page objects! For the sake of clarity let’s also add Header functionality. To do that we’d just use Ruby’s mixin functionality - the &lt;i&gt;Header&lt;/i&gt; module:
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
# lib/app/page/_header.rb
module App
  module Page
    module Header
      def sections
        ul(:id =&gt; "sch_scopes").lis
      end
    end
  end
end
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1325268.js?file=_header.rb"&gt;&lt;/script&gt;&lt;p&gt;
And make sure to include it into your page object:
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
# lib/app/page/main.rb
module App
  module Page
    class Main 
&lt;/pre&gt;&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1325268.js?file=main_3.rb"&gt;&lt;/script&gt;&lt;p&gt;
We can now update our main_spec to actually test something:
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
# spec/app/page/main_spec.rb
describe App::Page::Main do
  let(:main_page) {App::Page::Main.new}

  it "has header with sections" do
    main_page.sections.should have(5).items
  end

  it "allows to search" do
    main_page.search_field.set "watirsplash jarmo"
    results_page = main_page.search_button.click
    results_page.results.count.should == 10
    results_page.results[0].text.should =~ /watirsplash/i
  end
end
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1325268.js?file=main_spec_3.rb"&gt;&lt;/script&gt;&lt;p&gt;
I made two tests - one for the header and another for the search functionality. Since header should be on every page, i could have taken advantage of the &lt;a href="https://www.relishapp.com/rspec/rspec-core/v/2-0/docs/example-groups/shared-example-group" target="_blank"&gt;RSpec’s Shared Examples&lt;/a&gt; feature, but for the sake of this post’s clarity i didn’t.
&lt;/p&gt;

&lt;p&gt;
The second test is a failing test since there’s no way that Watir’s &lt;i&gt;Button#click&lt;/i&gt; will return us a results page object. But hey, i’ve just done a little &lt;a href="http://en.wikipedia.org/wiki/Test-driven_development" target="_blank"&gt;TDD&lt;/a&gt; here! Let’s make it work like we want it to work:
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
# lib/app/page/main.rb
module App
  module Page
    class Main  "go"),
          :click =&gt; lambda {redirect_to Results}
      end
    end
  end
end
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1328007.js?file=main4.rb"&gt;&lt;/script&gt;&lt;p&gt;
I’ve used the &lt;i&gt;WatirSplash::Page::Base#modify&lt;/i&gt; method which takes some object as it’s first argument (here button) and a Hash as a second argument. Hash consists of method name as a key and value as Proc object. In this particular case the code above overrides this particular button’s &lt;i&gt;#click&lt;/i&gt; method with my &lt;i&gt;#click&lt;/i&gt;, which returns Results page object due to the usage of &lt;i&gt;#redirect_to&lt;/i&gt; method. Since &lt;i&gt;#click&lt;/i&gt; is already existing method on that button, then it will call the original method (e.g. performs the actual clicking) before calling the defined block. The &lt;i&gt;#modify&lt;/i&gt; method does all that by using Ruby’s meta-programming. You can always &lt;a href="https://github.com/jarmo/WatirSplash/blob/master/lib/watirsplash/page/base.rb#L32-45" target="_blank"&gt;look at the source&lt;/a&gt; itself if you’re more interested in the nitty-gritty details.
&lt;/p&gt;

&lt;p&gt;
Let’s create ourselves a Results page object with the &lt;i&gt;results&lt;/i&gt; method. This time, let’s be even cooler and generate more code than we did with the Main page object:
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
C:\my_project\ui-test&gt;watirsplash page results results:ul:id:wg0 --no-spec
       exist  lib
      create  lib/app/page/results.rb
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1325268.js?file=results.cmd"&gt;&lt;/script&gt;&lt;p&gt;
This generated us the Results class with the &lt;i&gt;results&lt;/i&gt; method:
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
# lib/app/page/results.rb
module App
  module Page
    class Results  "wg0")
      end

    end
  end
end
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1325268.js?file=results.rb"&gt;&lt;/script&gt;&lt;p&gt;
Let’s add the &lt;i&gt;#count&lt;/i&gt; and &lt;i&gt;#[]&lt;/i&gt; methods to our &lt;i&gt;#results&lt;/i&gt; object by using &lt;i&gt;#modify&lt;/i&gt; again so we could chain method invocations naturally as i’ve written in the search functionality test:
&lt;/p&gt;

&lt;noscript&gt;
&lt;pre&gt;
# lib/app/page/results.rb
module App
  module Page
    class Results  "wg0"),
          :count =&gt; lambda {results.lis(:class =&gt; "sa_wr").size},
          :[] =&gt; lambda {|i| results.li(:class =&gt; "sa_wr", :index =&gt; i)}
      end
    end
  end
end
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;script src="https://gist.github.com/1328007.js?file=results_2.rb"&gt;&lt;/script&gt;&lt;p&gt;
I’m invoking the &lt;i&gt;#results&lt;/i&gt; method again to get the &lt;i&gt;Watir::Ul&lt;/i&gt; element to execute regular Watir methods on it - in these cases &lt;i&gt;#li&lt;/i&gt; and &lt;i&gt;#lis&lt;/i&gt;. This neat trick hides the implementation details from the tests and makes the tests even more natural to read.
&lt;/p&gt;

&lt;h3&gt;In Conclusion&lt;/h3&gt;

&lt;p&gt;
That’s it - we have created a few tests using Page Objects functionality in &lt;a href="http://github.com/jarmo/watirsplash" target="_blank"&gt;WatirSplash 2&lt;/a&gt;! Using Page Objects makes your tests (hopefully) more readable and easier to maintain. I like my implementation when compared to others because it makes your page objects to look really succinct and doesn’t add any additional complex API to learn - you can use already learnt Watir methods as you did before. And &lt;a href="https://github.com/jarmo/WatirSplash/blob/master/lib/watirsplash/page/base.rb" target="_blank"&gt;the code written&lt;/a&gt; to support creating and using these Page Objects is also quite clever and short. I love it! I hope you will too.
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/YmnJ4FSRyQI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/YmnJ4FSRyQI/12242886944</link><guid isPermaLink="false">http://itreallymatters.net/post/12242886944</guid><pubDate>Wed, 02 Nov 2011 17:41:00 +0200</pubDate><category>watir</category><category>ruby</category><category>testing</category><category>watirsplash</category><feedburner:origLink>http://itreallymatters.net/post/12242886944</feedburner:origLink></item><item><title>Solutions To The Hardest Problems</title><description>&lt;img src="http://24.media.tumblr.com/tumblr_lt99f86YiD1qa9b99o1_400.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;Solutions To The Hardest Problems&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/WWPu9S85h2s" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/WWPu9S85h2s/11607937103</link><guid isPermaLink="false">http://itreallymatters.net/post/11607937103</guid><pubDate>Tue, 18 Oct 2011 12:37:56 +0300</pubDate><feedburner:origLink>http://itreallymatters.net/post/11607937103</feedburner:origLink></item><item><title>Angry Birds Anger Management</title><description>&lt;img src="http://27.media.tumblr.com/tumblr_lsqlajCcYB1qa9b99o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;Angry Birds Anger Management&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/LPF3Xqq4B7A" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/LPF3Xqq4B7A/11174028163</link><guid isPermaLink="false">http://itreallymatters.net/post/11174028163</guid><pubDate>Sat, 08 Oct 2011 10:39:55 +0300</pubDate><feedburner:origLink>http://itreallymatters.net/post/11174028163</feedburner:origLink></item><item><title>Facebook, Watir And Testing</title><description>&lt;p&gt;
I’ve known some time now that &lt;a href="http://www.facebook.com" target="_blank"&gt;Facebook&lt;/a&gt; has been using &lt;a href="http://www.watir.com" target="_blank"&gt;Watir&lt;/a&gt; as their integration testing tool. Hell, there’s even a Facebook logo on the main page of &lt;a href="http://watir.com" target="_blank"&gt;watir.com&lt;/a&gt;. But today was a special day because i had to read one article about &lt;a href="http://www.facebook.com/notes/facebook-engineering/watir-to-webdriver-unit-test-frameworks/10150314152278920" target="_blank"&gt;Facebook moving away from Watir&lt;/a&gt;. 
&lt;/p&gt;

&lt;h3&gt;Confusions&lt;/h3&gt;

&lt;p&gt;
Since i’m one of the few core developers of Watir then this article made me notice statements which are not true or are just misleading. It seems to me that the author of that post doesn’t know the insights of Watir and other tools he’s mentioning or just uses wrong terminology by accident.
&lt;/p&gt;

&lt;h3&gt;Watir &amp; JavaScript&lt;/h3&gt;

&lt;p&gt;
First statement which forced me to questioning myself was the following: &lt;i&gt;“Watir automates the browser with JavaScript…”&lt;/i&gt;.
&lt;/p&gt;

&lt;p&gt;
It took me some time before i understood that the author had &lt;i&gt;FireWatir&lt;/i&gt; in his mind and not the &lt;i&gt;Watir&lt;/i&gt; itself. FireWatir was used to automate Firefox browser and it truly used JavaScript as it’s engine to perform all the automations. Watir on the other hand controls &lt;i&gt;Internet Explorer&lt;/i&gt; and uses it’s &lt;a href="http://en.wikipedia.org/wiki/OLE_Automation" target="_blank"&gt;OLE interface&lt;/a&gt; instead to control the browser. This means in effect that there’s almost no JavaScript used in Watir.
&lt;/p&gt;

&lt;h3&gt;Watir != Watir-WebDriver != WebDriver&lt;/h3&gt;

&lt;p&gt;
The next statement causing confusion is: &lt;i&gt;“The Watir we adopted in 2009 has since been improved, integrating a new protocol called WebDriver which allows you to automate the browser more accurately and with more power than could previously be done with straight JavaScript.”&lt;/i&gt;
&lt;/p&gt;

&lt;p&gt;
First - Watir has been improved indeed when compared to year 2009 :) This is a good thing and a true statement. Second - Watir doesn’t integrate with the new protocol called WebDriver - it does still use OLE. I’m not exactly sure what the author means by the end of his statement about more accuracy and power. And of course - third - as mentioned already, Watir itself doesn’t use JavaScript and didn’t even do that in the year of 2009.
&lt;/p&gt;

&lt;p&gt;
I think that you can call the WebDriver as a protocol, but the most famous implementation of that protocol is for sure &lt;a href="http://code.google.com/p/selenium/" target="_blank"&gt;Selenium-WebDriver aka Selenium 2&lt;/a&gt;. &lt;a href="https://github.com/jarib/watir-webdriver" target="_blank"&gt;Watir-WebDriver&lt;/a&gt; is a library written on top of Selenium-WebDriver’s &lt;a href="http://www.ruby-lang.org" target="_blank"&gt;Ruby&lt;/a&gt; bindings. In other words it is an improved API over Selenium’s API. At least this is the way, we, Watir-loving people like to think. It does even have some API improvements which &lt;i&gt;vanilla&lt;/i&gt; Watir doesn’t have yet. There is a project called &lt;a href="https://github.com/jarib/watirspec" target="_blank"&gt;WatirSpec&lt;/a&gt;, which is &lt;i&gt;the&lt;/i&gt; specification for Watir’s API. Even Watir itself doesn’t conform to that yet. But the ultimate goal is to make Watir-WebDriver and Watir 100% compatible with each other.&lt;a href="http://watir.com/2011/08/11/watir-2-0/" target="_blank"&gt; Latest releases of Watir&lt;/a&gt; have been moving towards that goal.
&lt;/p&gt;

&lt;h3&gt;Abandoning Watir&lt;/h3&gt;

&lt;p&gt;
And then i have to read the saddest statement of that article: &lt;i&gt;“Once I understood all these factors, my course of action seemed clear: Abandon Watir, create a WebDriver client in PHP, and reuse our mature PHP unit test system for our browser tests. The WebDriver protocol was straightforward enough that I had a fully featured client in PHP by the end of a weekend’s work.”&lt;/i&gt;
&lt;/p&gt;

&lt;p&gt;
On the one hand i’m happy that the engineers in the Facebook try to make things better - having the same technologies used between different projects is always a good thing. On the other hand i’m not sure i understand as to why they had to create a new PHP WebDriver bindings. Looking from the main page of Selenium 2 i can see that there’s already two seemingly active projects doing just that - &lt;a href="http://code.google.com/p/php-webdriver-bindings/" target="_blank"&gt;php-webdriver-bindings&lt;/a&gt; and &lt;a href="https://github.com/chibimagic/WebDriver-PHP" target="_blank"&gt;WebDriver-PHP&lt;/a&gt;. Maybe engineers at Facebook had good reasons why not to use something already existing. Maybe they just like to feel more challenged and want to invent few bicycles in a while. I don’t know.
&lt;/p&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;
After all it was an interesting read. Since i’ve used Watir about 4 years now then it’s nice to read that someone else had similar or completely different solutions to the same problems. I like the thing about Facebook that it tries to be more open to the world when it comes to the topics of the tools and processes used to make, maintain and release such a widely used product.
&lt;/p&gt;

&lt;p&gt;
On the other hand, posts having false information in them tend to have a strong effect on people using the tools under fire. Especially if this kind of information is originating from a trustworthy source. From that post it seems that it is time to abandon Watir since it is too old and not developed anymore. That’s just plain wrong. Watir is still actively developed and one of the biggest reasons why not to abandon Watir at this moment is that it is still the best automation tool for Internet Explorer. Watir-WebDriver’s IE driver is just not mature enough. Sorry, WebDriver guys. I would be happy to run all my tests with Watir-WebDriver since that would give me an opportunity to test with different browsers, but as long as IE is not working properly, then i just can’t do that. Since IE is the brittlest and still most used browser, then testing with that browser just seems to be mandatory.
&lt;/p&gt;

&lt;p&gt;
I have to agree that if the person is not tied with all or some of these projects on a daily basis then it is hard to understand the difference between Watir, Watir-WebDriver and WebDriver. Maybe the biggest problem is just that the topics aren’t documented enough?
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/xmTC4fXfMCs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/xmTC4fXfMCs/10991877834</link><guid isPermaLink="false">http://itreallymatters.net/post/10991877834</guid><pubDate>Tue, 04 Oct 2011 00:19:19 +0300</pubDate><category>watir</category><category>facebook</category><category>testing</category><feedburner:origLink>http://itreallymatters.net/post/10991877834</feedburner:origLink></item><item><title>Fighting Against Gem Hell</title><description>&lt;p&gt;There is a term called &lt;a href="http://en.wikipedia.org/wiki/DLL_Hell" target="_blank"&gt;DLL Hell&lt;/a&gt; which in my opinion exists also in the &lt;a href="http://www.ruby-lang.org" target="_blank"&gt;Ruby&lt;/a&gt; community with the different name - Gem Hell. This potential problem exists when dependencies for your project and/or libraries are not managed properly.
&lt;/p&gt;

&lt;p&gt;
I’ve written in the post &lt;a href="http://www.itreallymatters.net/post/9085718628/watirsplash-2" target="_blank"&gt;WatirSplash 2&lt;/a&gt; about loading all the dependencies with the help of the &lt;a href="http://gembundler.com/" target="_blank"&gt;Bundler&lt;/a&gt;, which helps to organize the dependencies in a sanely way and tries to eliminate the Gem Hell problem. In this post i’m gonna give a more detailed overview of how the things were before and how they are now in the &lt;a href="https://github.com/jarmo/watirsplash" target="_blank"&gt;WatirSplash&lt;/a&gt; framework. 
&lt;/p&gt;

&lt;h3&gt;Story Behind WatirSplash’ Dependencies&lt;/h3&gt;

&lt;p&gt;
Since WatirSplash is a framework which supports using different frameworks for browser automation (&lt;i&gt;Watir&lt;/i&gt;, &lt;i&gt;Watir-WebDriver&lt;/i&gt; and &lt;i&gt;FireWatir&lt;/i&gt;) then there needs to be some kind of a mechanism for defining the install and runtime dependencies. Install dependencies are easy to specify since they can be put right into the &lt;i&gt;.gemspec&lt;/i&gt; file of the WatirSplash gem and &lt;a href="http://rubygems.org/" target="_blank"&gt;RubyGems&lt;/a&gt; does all the heavylifting:
&lt;/p&gt;

&lt;script src="https://gist.github.com/1192631.js?file=gemspec.rb"&gt;&lt;/script&gt;&lt;noscript&gt;
&lt;pre&gt;
Gem::Specification.new do |s|
  # ...  
  s.add_dependency("rake", "0.8.7")
  s.add_dependency("require_all")
  s.add_dependency("syntax")
end
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;p&gt;
It gets trickier when it comes to specifying the runtime dependencies. “Why runtime dependencies at all?” - you might ask. The answer to this question is fairly simple - because the framework used for automating the browser is chosen during runtime and it’s not possible to put all these gems into installation dependencies due to the problem of &lt;a href="http://watir.com/" target="_blank"&gt;Watir&lt;/a&gt; (for controlling the IE browser) not installing successfully on Linux or OS X operating systems for obvious reasons. There are also other OS-specific gems. Also, it’s not possible (at least not in my knowledge of) to specify platform specific dependencies right into the &lt;i&gt;.gemspec&lt;/i&gt; file itself.
&lt;/p&gt;

&lt;h3&gt;The Old Way&lt;/h3&gt;

&lt;p&gt;
The runtime dependencies in WatirSplash 1 were loaded with the help of the RubyGems itself. When the desired framework was specified then WatirSplash loaded the appropriate file, which executed the code similar to this for Watir:
&lt;/p&gt;

&lt;script src="https://gist.github.com/1192631.js?file=load_watir.rb"&gt;&lt;/script&gt;&lt;noscript&gt;
&lt;pre&gt;
begin
  gem "watir", "=2.0.1"
  require "watir"
rescue Gem::LoadError
  puts "\nWatir dependency is missing. Install it with:"
  puts "  gem install watir -v 2.0.1"
  exit 1
end
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;p&gt;
It meant that the user of WatirSplash needed to have the Watir version 2.0.1 installed and if he didn’t then the installation instructions were provided.
&lt;/p&gt;

&lt;p&gt;
This solution seems to solve the problem of specifying runtime dependencies at first. There are still some problems with this approach. First of all, if Watir has a dependency for some other gem without any specific or with too loose version then it is possible that some newer version of that gem breaks the usage of WatirSplash and i, as a maintainer of the WatirSplash gem, have to release a new version of the WatirSplash gem by specifying the exact version of that gem as a runtime dependency. Second problem is that if a newer version of Watir (or any other among the runtime dependency gems) were released then it was not possible for the user of WatirSplash to try if it was working with the current version of WatirSplash (which was pretty often the case) without modifying the code of WatirSplash itself or waiting for the new release made by me with updated runtime dependencies. These are the two main and quite big problems with this approach.
&lt;/p&gt;

&lt;h3&gt;The New Way&lt;/h3&gt;

&lt;p&gt;
These problems were solved by introducing the usage of Bundler. Bundler allows to specify runtime dependencies exactly like with RubyGems, but it has a difference of locking down the dependencies versions. This means that user A and user B are always using the same versions of all the runtime dependencies no matter what other versions they have installed on their system.
&lt;/p&gt;

&lt;p&gt;
By using WatirSplash 2, you will get the following &lt;i&gt;Gemfile&lt;/i&gt; into your specs directory, when running new project generator, for specifying all the needed dependencies:
&lt;/p&gt;

&lt;script src="https://gist.github.com/1192631.js?file=Gemfile.rb"&gt;&lt;/script&gt;&lt;noscript&gt;
&lt;pre&gt;
source :rubygems

# load WatirSplash and it's dependencies
gem "watirsplash", "2.1.1"

platforms :mingw, :mswin do
    gem "watir", "2.0.1"
    gem "win32screenshot", "~&gt;1.0.5", :require =&gt; "win32/screenshot"
end

gem "watir-webdriver", "~&gt;0.3.1"
gem "firewatir", "&gt;= 1.9.3"
gem "rspec", "~&gt;2.6.0"
gem "spork", "~&gt;0.9.0.rc9"

# add your project specific dependencies here:
# gem "ruby-debug", "0.10.3"
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;p&gt;
After executing `&lt;i&gt;bundle install&lt;/i&gt;` do not forget to add &lt;i&gt;Gemfile.lock&lt;/i&gt; also into your &lt;a href="http://en.wikipedia.org/wiki/Revision_control" target="_blank"&gt;VCS&lt;/a&gt; - this is the only way to guarantee that everyone who is running the tests are using the exact same versions of the dependencies.
&lt;/p&gt;

&lt;p&gt;
This solution allows each user of the WatirSplash to specify their own dependency versions without any need to wait for the new release of the WatirSplash itself. In other words - this solution solves both of the problems existent in the previous RubyGems solution.
&lt;/p&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;
Bundler tries to make the Gem Hell problem disappear and is doing a pretty good job there, but if there are gems which depend on some external native library, which needs compilation then there is still the danger of having a wrong version of that dependency causing compilation errors. Probability of seeing that problem is quite low compared to the problems which Bundler solves. All in all Bundler is a really great tool and thanks to that WatirSplash has gotten even better.
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/9p6kRyxG41Q" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/9p6kRyxG41Q/9886880315</link><guid isPermaLink="false">http://itreallymatters.net/post/9886880315</guid><pubDate>Tue, 06 Sep 2011 23:12:25 +0300</pubDate><category>ruby</category><category>watir</category><category>watirsplash</category><category>bundler</category><category>testing</category><feedburner:origLink>http://itreallymatters.net/post/9886880315</feedburner:origLink></item><item><title>I have been using the screenshot to obtain IE screen captures. This works well when have a remote desktop session to the IE virtual machine. However, I notice that the capture is a black screen when there is no remote desktop session even though the user session still exists.</title><description>&lt;p&gt;Yes, that is a known limitation Windows blocking these system calls when the PC is locked. You can use VNC or some similar remote desktop alternative which emulates the remote PC in a different way and not locking the PC when you disconnect from the remote session.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/XGN0JSWmgXg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/XGN0JSWmgXg/9785604177</link><guid isPermaLink="false">http://itreallymatters.net/post/9785604177</guid><pubDate>Sun, 04 Sep 2011 14:31:49 +0300</pubDate><feedburner:origLink>http://itreallymatters.net/post/9785604177</feedburner:origLink></item><item><title>WatirSplash 2</title><description>&lt;p&gt;
&lt;a href="https://github.com/jarmo/watirsplash" target="_blank"&gt;WatirSplash 2&lt;/a&gt; has been released already some time ago, but i haven’t covered the nice things which came with it. This situation will be improved with the following posts.
&lt;/p&gt;

&lt;h3&gt;New Features&lt;/h3&gt;

&lt;p&gt;
The biggest changes in WatirSplash 2 compared to version 1.x are:
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="http://www.itreallymatters.net/post/9886880315/fighting-against-gem-hell" target="_blank"&gt;Loading all dependencies with the help of Bundler.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Fixed support for Ruby 1.9.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://itreallymatters.net/post/12242886944/awesome-page-objects-in-testing" target="_blank"&gt;Introduced so called &lt;i&gt;Page Objects&lt;/i&gt;.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Removed cumbersome and usually not needed “&lt;i&gt;ui-test-common&lt;/i&gt;” functionality.&lt;/li&gt;
&lt;li&gt;Made WatirSplash more transparent making it easier to follow what, when and how it does the things it does and giving better control over it.&lt;/li&gt;
&lt;/ul&gt;&lt;h3&gt;Removed Features&lt;/h3&gt;

&lt;p&gt;
It is quite easy to understand from the “New Features” list that projects generated with WatirSplash 1.x won’t work out of the box with WatirSplash 2. I had to break backwards compatibility due to the decisions made in the past which were in my way improving the framework to make it just &lt;b&gt;&lt;i&gt;a lot&lt;/i&gt;&lt;/b&gt; better.
&lt;/p&gt;

&lt;p&gt;
I’ve paid attention to the users of WatirSplash and noticed what they didn’t like or what they have been wanting to do differently. This has caused me to use &lt;i&gt;.rspec&lt;/i&gt; file to configure &lt;a href="http://relishapp.com/rspec" target="_blank"&gt;RSpec&lt;/a&gt; all the way instead of doing it programmatically from the WatirSplash itself. This gives a better control for tuning the usage of RSpec when needed.
&lt;/p&gt;

&lt;p&gt;
Even browser window won’t be opened and maximized automatically anymore - you can still do it with the help of &lt;i&gt;RSpec.configure&lt;/i&gt; block.
&lt;/p&gt;

&lt;p&gt;
All these little details should make the experience of using WatirSplash even better!
&lt;/p&gt;

&lt;h3&gt;Getting Started&lt;/h3&gt;

&lt;p&gt;
Starting to use WatirSplash is as easy as &lt;i&gt;splashin’ in the water&lt;/i&gt;. First you have to install the gem itself ofcourse:
&lt;/p&gt;

&lt;script src="https://gist.github.com/1154564.js?file=installing.txt"&gt;&lt;/script&gt;&lt;noscript&gt;
&lt;pre&gt;
C:\my_project&gt;gem install watirsplash
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;p&gt;
After doing that you’d need to generate a default project structure. It can be done by using the “&lt;i&gt;new&lt;/i&gt;” generator:
&lt;/p&gt;

&lt;script src="https://gist.github.com/1154564.js?file=new_project.txt"&gt;&lt;/script&gt;&lt;noscript&gt;
&lt;pre&gt;
C:\my_project&gt;watirsplash new
      create  ui-test
      ...

C:\my_project&gt;cd ui-test
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;p&gt;
Being inside of the newly created project directory, install all the required dependencies aswell:
&lt;/p&gt;

&lt;script src="https://gist.github.com/1154564.js?file=dependencies.txt"&gt;&lt;/script&gt;&lt;noscript&gt;
&lt;pre&gt;
C:\my_project\ui-test&gt;bundle install
Fetching source index for &lt;a href="http://rubygems.org/" target="_blank"&gt;http://rubygems.org/&lt;/a&gt;
...
Using watirsplash
...
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;p&gt;
After having that done, generate the very first Page Object with the “&lt;i&gt;page&lt;/i&gt;” generator. For example:
&lt;/p&gt;

&lt;script src="https://gist.github.com/1154564.js?file=new_page.txt"&gt;&lt;/script&gt;&lt;noscript&gt;
&lt;pre&gt;
C:\my_project\ui-test&gt;bundle exec watirsplash page search --url &lt;a href="http://bing.com" target="_blank"&gt;http://bing.com&lt;/a&gt;
      create  lib
      create  lib/app/page/search.rb
      create  spec
      create  spec/app/page/search_spec.rb
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;p&gt;
There you have it. Modify the newly generated files and start specc’ing. There will be a more thorough posts about the main new features including how to use Page Objects in the future - stay tuned. Feel free to read more information about WatirSplash from it’s repository at &lt;a href="https://github.com/jarmo/watirsplash" target="_blank"&gt;GitHub&lt;/a&gt;.
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/Aej5I37vVK0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/Aej5I37vVK0/9085718628</link><guid isPermaLink="false">http://itreallymatters.net/post/9085718628</guid><pubDate>Thu, 18 Aug 2011 20:45:00 +0300</pubDate><category>ruby</category><category>watir</category><category>watirsplash</category><feedburner:origLink>http://itreallymatters.net/post/9085718628</feedburner:origLink></item><item><title>Take a smile :)</title><description>&lt;img src="http://26.media.tumblr.com/tumblr_lp1wtoIWcm1qa9b99o1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;Take a smile :)&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/EWFWfhwVlfM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/EWFWfhwVlfM/8174216886</link><guid isPermaLink="false">http://itreallymatters.net/post/8174216886</guid><pubDate>Thu, 28 Jul 2011 19:08:12 +0300</pubDate><feedburner:origLink>http://itreallymatters.net/post/8174216886</feedburner:origLink></item><item><title>Viva la RAutomation</title><description>&lt;p&gt;
&lt;a href="https://rubygems.org/gems/watir/versions/1.9.0" target="_blank"&gt;Watir 1.9.0&lt;/a&gt; got recently released. One of the biggest changes in that version, addition to the support for IE9, is a replacement of &lt;a href="http://www.autoitscript.com/site/autoit/" target="_blank"&gt;AutoIt&lt;/a&gt; with &lt;a href="http://www.itreallymatters.net/post/2352350743/automating-windows-and-their-controls-with-ruby" target="_blank"&gt;RAutomation&lt;/a&gt;! This means that the next time you’re installing Watir, you will lose all the functionality of AutoIt automatically. If you used it somewhere specifically to do something, then this post will try to help you to make the upgrade process less painful.
&lt;/p&gt;

&lt;h3&gt;The Bad News About AutoIt&lt;/h3&gt;

&lt;p&gt;
Let’s pretend you have something like this in your test:
&lt;/p&gt;

&lt;script src="https://gist.github.com/1040166.js?file=old_watir.rb"&gt;&lt;/script&gt;&lt;noscript&gt;
&lt;pre&gt;
Watir.autoit.WinWait("Blank Page - Windows Internet Explorer")
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;p&gt;
Statement like this was pretty normal - you could use AutoIt directly from Watir. When you try to do the same with Watir 1.9.0 you will get an error like this:
&lt;/p&gt;

&lt;script src="https://gist.github.com/1040166.js?file=autoit_error.rb"&gt;&lt;/script&gt;&lt;noscript&gt;
&lt;pre&gt;
NoMethodError: undefined method `autoit' for Watir:Module
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;p&gt;
This happens because there isn’t even anymore any method called &lt;i&gt;autoit&lt;/i&gt; in Watir.
&lt;/p&gt;

&lt;h3&gt;Quick &amp; Dirty Fix&lt;/h3&gt;

&lt;p&gt;
There are two ways to fix that problem. You could initialize your own AutoIt object and use that or you could use RAutomation’s AutoIt adapter. You can switch the adapter to AutoIt before loading Watir by setting the environment variable called &lt;i&gt;RAUTOMATION_ADAPTER&lt;/i&gt; to “autoit” before loading Watir itself:
&lt;/p&gt;

&lt;script src="https://gist.github.com/1040166.js?file=use_autoit.rb"&gt;&lt;/script&gt;&lt;noscript&gt;
&lt;pre&gt;
ENV["RAUTOMATION_ADAPTER"] = "autoit"
require "watir" # now Watir uses RAutomation with AutoIt adapter.
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;p&gt;
Of course this is not a good solution, after all AutoIt was replaced by RAutomation with having best intentions in mind. But it allows now to do something like this:
&lt;/p&gt;

&lt;script src="https://gist.github.com/1040166.js?file=use_autoit_methods.rb"&gt;&lt;/script&gt;&lt;noscript&gt;
&lt;pre&gt;
browser = Watir::Browser.new
browser.rautomation.WinWait("Blank Page - Windows Internet Explorer")
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;p&gt;
This makes it possible to use AutoIt’s methods directly through RAutomation’s AutoIt adapter.
&lt;/p&gt;

&lt;h3&gt;Use AutoIt Only Where Really Needed&lt;/h3&gt;

&lt;p&gt;
It would be ideal if you’d just convert all the existing AutoIt code to use RAutomation. Trust me, it would make sense to even you after you’ve changed your code - it’s cleaner, more readable and better in any way. Just refer to RAutomation’s &lt;a href="https://github.com/jarmo/RAutomation/blob/master/README.rdoc" target="_blank"&gt;README&lt;/a&gt; and &lt;a href="http://www.itreallymatters.net/post/2352350743/automating-windows-and-their-controls-with-ruby" target="_blank"&gt;this blog post&lt;/a&gt; and you’re set to go. If you’re familiar with the syntax of Watir itself then RAutomation’s syntax should be quite easy to follow also since it is inspired by Watir.
&lt;/p&gt;

&lt;p&gt;
If there are still some places where you really-really need to use AutoIt due to some missing feature in RAutomation itself (don’t forget to tell me about it through &lt;a href="https://github.com/jarmo/rautomation/issues" target="_blank"&gt;GitHub issues&lt;/a&gt;!) then you can use AutoIt adapter also per RAutomation object and not globally by using environment variable like this:
&lt;/p&gt;

&lt;script src="https://gist.github.com/1040166.js?file=change_adapter.rb"&gt;&lt;/script&gt;&lt;noscript&gt;
&lt;pre&gt;
RAutomation::Window.new(:title =&gt; /Internet Explorer/).adapter # =&gt; defaults to :win_ffi
RAutomation::Window.new(:title =&gt; /Internet Explorer/, :adapter =&gt; :autoit).adapter # =&gt; uses :autoit for this object
&lt;/pre&gt;
&lt;/noscript&gt;

&lt;p&gt;
This makes it possible for you to use AutoIt’s adapter in only places necessary.
&lt;/p&gt;

&lt;h3&gt;Overview Of Upgrading Steps&lt;/h3&gt;

&lt;p&gt;
If you don’t have any custom code using AutoIt then upgrading to Watir 1.9.0 shouldn’t cause you any problems - internally RAutomation is used and you shouldn’t even notice it. But if you have, then i recommend following the steps below to make the upgrade less painful:
&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;set RAutomation to use AutoIt globally via environment variable&lt;/li&gt;
&lt;li&gt;replace usages of &lt;i&gt;Watir.autoit&lt;/i&gt; with &lt;i&gt;browser.rautomation&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;replace in small steps your AutoIt code to use RAutomation&lt;/li&gt;
&lt;li&gt;use &lt;i&gt;:adapter =&gt; :autoit&lt;/i&gt; option for RAutomation to use AutoIt in very specific places where using RAutomation’s default adapter is impossible&lt;/li&gt;
&lt;li&gt;remove the environment variable to use RAutomation’s default adapter&lt;/li&gt;
&lt;li&gt;profit!&lt;/li&gt;
&lt;/ul&gt;&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;
I think that using RAutomation instead of AutoIt is a good move. I’ve had that idea for a longer period of time and that’s one of the reasons i created RAutomation in the first place. Thanks to &lt;a href="https://twitter.com/hmcgowan" target="_blank"&gt;Hugh McGowan&lt;/a&gt; for implementing this idea. Viva la RAutomation!
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/4zqJy7iZN-4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/4zqJy7iZN-4/6791652065</link><guid isPermaLink="false">http://itreallymatters.net/post/6791652065</guid><pubDate>Wed, 22 Jun 2011 18:26:00 +0300</pubDate><feedburner:origLink>http://itreallymatters.net/post/6791652065</feedburner:origLink></item><item><title>WatirSplash With Different Browsers</title><description>&lt;p&gt;
&lt;a href="https://github.com/jarmo/watirsplash" target="_blank"&gt;WatirSplash&lt;/a&gt; supported only Windows operating system and IE browser to perform browser based user interface testing. The reason behind that restriction was the usage of &lt;a href="http://watir.com" target="_blank"&gt;Watir&lt;/a&gt; framework, which by design is Windows-specific and controls Internet Explorer. Using that browser to test is usually great because most of the developers (including myself) are not using IE during their development time and it is also the most error-prone browser. This all means that it’s &lt;b&gt;good&lt;/b&gt; to run your tests with the &lt;b&gt;IE&lt;/b&gt; since it has the highest probability to find some bugs during the creation of the tests and in the future.
&lt;/p&gt;

&lt;h3&gt;Gimme More!&lt;/h3&gt;

&lt;p&gt;
Starting from WatirSplash &lt;b&gt;version 1.1.0&lt;/b&gt; it is now possible to run tests in &lt;b&gt;Linux&lt;/b&gt; and &lt;b&gt;OS X&lt;/b&gt; by using &lt;b&gt;Firefox&lt;/b&gt; and &lt;b&gt;Chrome&lt;/b&gt; browsers. This functionality is provided by using other frameworks in addition to Watir itself - FireWatir and &lt;a href="https://github.com/jarib/watir-webdriver" target="_blank"&gt;Watir-WebDriver&lt;/a&gt;. WatirSplash allows easy switching between the frameworks and browsers.
&lt;/p&gt;

&lt;h3&gt;Switching the Frameworks&lt;/h3&gt;

&lt;p&gt;
It is possible to switch the framework by using environment variable or by just specifying the framework in the code.
&lt;/p&gt;

&lt;p&gt;
All possible values for different frameworks and browsers are currently the following:
&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;watir&lt;/li&gt;
&lt;li&gt;firewatir&lt;/li&gt;
&lt;li&gt;watir-webdriver/ie&lt;/li&gt;
&lt;li&gt;watir-webdriver/firefox&lt;/li&gt;
&lt;li&gt;watir-webdriver/chrome&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;
Use environment variable called &lt;b&gt;WATIRSPLASH_FRAMEWORK&lt;/b&gt; to specify the current framework:
&lt;/p&gt;

&lt;p&gt;
&lt;script src="https://gist.github.com/844568.js?file=env.cmd"&gt;&lt;/script&gt;&lt;/p&gt;&lt;noscript&gt;
&lt;pre&gt;
WATIRSPLASH_FRAMEWORK=watir-webdriver/firefox
&lt;/pre&gt;
&lt;/noscript&gt;


&lt;p&gt;
This makes your WatirSplash project tests to use Watir-WebDriver framework with Firefox browser. Pretty straight-forward.
&lt;/p&gt;

&lt;p&gt;
As written above then it is also possible to specify the used framework directly in the code. It is meant to be done in your &lt;b&gt;config.rb&lt;/b&gt; file under the &lt;b&gt;ui-test&lt;/b&gt; and/or &lt;b&gt;ui-test-common&lt;/b&gt; directories. If you specify it in the ui-test-common directory then the ui-test directory has higher precedence and framework specified there will be used. On the other hand if you don’t have any frameworks specified in the ui-test directory then the framework specified in the ui-test-common directory will be used. The framework to be used can be specified like this:
&lt;/p&gt;

&lt;p&gt;
&lt;script src="https://gist.github.com/844568.js?file=config.rb"&gt;&lt;/script&gt;&lt;/p&gt;&lt;noscript&gt;
&lt;pre&gt;
WatirSplash::Util.framework = "firewatir"
&lt;/pre&gt;
&lt;/noscript&gt;


&lt;p&gt;
This statement makes WatirSplash to use FireWatir framework with Firefox browser (obviously).
&lt;/p&gt;

&lt;p&gt;
Framework specified by environment variable has always the highest precedence, then comes the ui-test’s and ui-test-common’s config.rb, in that order.
&lt;/p&gt;

&lt;h3&gt;Default Frameworks&lt;/h3&gt;

&lt;p&gt;
This additional functionality in WatirSplash is fully backwards compatible. If the framework is not specified anywhere then the default framework will be used. The default framework depends of the platform where the tests are ran. The default framework in Windows is Watir and in Linux/OS X it is FireWatir.
&lt;/p&gt;

&lt;h3&gt;Possible Dangers&lt;/h3&gt;

&lt;p&gt;
You have to keep in mind that switching the frameworks could cause some problems when running the tests due to the different incompatibilities between the frameworks. Watir and FireWatir, for example, are not 100% compatible with each other. Same goes for Watir and Watir-WebDriver. Also, i’d not consider Watir-WebDriver’s IE and Chrome drivers stable yet. The only driver i’d recommend to use from Watir-WebDriver would be Firefox’s.
&lt;/p&gt;

&lt;h3&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;
There you have it - a quite flexible solution for all your browser testing needs. Just have some things in your mind while switching the frameworks and you’re good to go. There will be probably more supported frameworks added to WatirSplash in the future. Just keep an eye on the &lt;a href="https://github.com/jarmo/WatirSplash/blob/master/History.rdoc" target="_blank"&gt;changelog&lt;/a&gt;.
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/7ixkdXbIxoU" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/7ixkdXbIxoU/3579456621</link><guid isPermaLink="false">http://itreallymatters.net/post/3579456621</guid><pubDate>Tue, 01 Mar 2011 10:00:07 +0200</pubDate><category>watir</category><category>watirsplash</category><category>ruby</category><category>testing</category><feedburner:origLink>http://itreallymatters.net/post/3579456621</feedburner:origLink></item><item><title>Autotesting With Doom-Guy</title><description>&lt;p&gt;
This post is inspired by one of the &lt;a href="http://szeryf.wordpress.com/2007/07/30/way-beyond-cool-autotest-growl-doomguy/" target="_blank"&gt;over-3-year-old-posts&lt;/a&gt; about using &lt;a href="http://www.zenspider.com/ZSS/Products/ZenTest/" target="_blank"&gt;Autotest&lt;/a&gt; with &lt;a href="http://growl.info/" target="_blank"&gt;Growl&lt;/a&gt; to show nice notifications about passing and failing tests.
&lt;/p&gt;

&lt;h3&gt;Doom-Guy is here!&lt;/h3&gt;

&lt;p&gt;
I’ve created a small gem for you to get the same helper for your testing needs. It is called &lt;a href="https://github.com/jarmo/autotest-doom" target="_blank"&gt;autotest-doom&lt;/a&gt; which works with &lt;a href="http://relishapp.com/rspec" target="_blank"&gt;RSpec&lt;/a&gt;. Read below for installation and configuration instructions.
&lt;/p&gt;

&lt;p&gt;
This is how it looks under Windows when everything is green and Doom-Guy is happy:
&lt;/p&gt;

&lt;p&gt;
&lt;img src="http://dl.dropbox.com/u/2731643/blog/autotest-doom/01_passing.png" alt="all passing"/&gt;&lt;/p&gt;

&lt;p&gt;
He looks a little bit hesitant, if something has failed:
&lt;/p&gt;

&lt;p&gt;
&lt;img src="http://dl.dropbox.com/u/2731643/blog/autotest-doom/02_slightly_failing.png" alt="slightly failing"/&gt;&lt;/p&gt;

&lt;p&gt;
It looks like his day has gotten even worse:
&lt;/p&gt;

&lt;p&gt;
&lt;img src="http://dl.dropbox.com/u/2731643/blog/autotest-doom/03_more_failures.png" alt="more failures"/&gt;&lt;/p&gt;

&lt;p&gt;
I’d say that there is definitely some visible blood when you’re having this many failures:
&lt;/p&gt;

&lt;p&gt;
&lt;img src="http://dl.dropbox.com/u/2731643/blog/autotest-doom/04_little_bloody.png" alt="little bloody"/&gt;&lt;/p&gt;

&lt;p&gt;
You’d better get yourself together and fix those failing tests now or he’s going to die!
&lt;/p&gt;

&lt;p&gt;
&lt;img src="http://dl.dropbox.com/u/2731643/blog/autotest-doom/05_not_a_good_day.png" alt="not a good day"/&gt;&lt;/p&gt;

&lt;p&gt;
And he’s dead… Do you really want to be such a lousy software developer?
&lt;/p&gt;

&lt;p&gt;
&lt;img src="http://dl.dropbox.com/u/2731643/blog/autotest-doom/06_status_dead.png" alt="status" dead/&gt;&lt;/p&gt;

&lt;p&gt;
Maybe, just maybe, if you’ll fix all the tests he will be alive again and you’ll be a lifesaver. Wouldn’t that just feel awesome?
&lt;/p&gt;

&lt;h3&gt;Installation &amp; Configuration&lt;/h3&gt;

&lt;p&gt;
In today’s Ruby world things are a little different compared with the previously mentioned old post. My approach is to support not just OS X, but also Windows and Linux. It is possible via help of &lt;a href="https://github.com/fnando/test_notifier" target="_blank"&gt;Test Notifier gem&lt;/a&gt;, which has created a clean API by using abstraction layer for using different tools to show notifications. It uses Growl under OS X, Libnotify among many others under Linux and Snarl under Windows.
&lt;/p&gt;

&lt;p&gt;
The following instructions are for Windows, but they’re really similar to other OS-es too. Just refer to &lt;a href="https://github.com/fnando/notifier" target="_blank"&gt;Notifier’s documentation&lt;/a&gt; about installing correct notifier tool for your OS and you’re ready to go.
&lt;/p&gt;

&lt;ol&gt;&lt;li&gt;&lt;a href="http://www.fullphat.net/index.php" target="_blank"&gt;Download &lt;b&gt;Snarl&lt;/b&gt;&lt;/a&gt; from it’s website and install it.&lt;/li&gt;
&lt;li&gt;Install &lt;b&gt;ruby-snarl&lt;/b&gt; and &lt;b&gt;test-notifier&lt;/b&gt; gems:
&lt;p&gt;&lt;code&gt;gem install ruby-snarl test_notifier&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Install &lt;b&gt;autotest&lt;/b&gt; and &lt;b&gt;autotest-doom&lt;/b&gt; gems:
&lt;p&gt;&lt;code&gt;gem install autotest autotest-doom&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Create &lt;b&gt;.autotest&lt;/b&gt; file into your project’s root directory with the following contents:
&lt;p&gt;&lt;code&gt;require "autotest/doom"&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;And &lt;b&gt;start&lt;/b&gt; testing!&lt;/li&gt;
&lt;/ol&gt;&lt;p&gt;
That’s it! Make sure that you’re not killing that poor old Doom-Guy too often and everyone is happy!
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/BlkCWoPuv6g" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/BlkCWoPuv6g/2626638691</link><guid isPermaLink="false">http://itreallymatters.net/post/2626638691</guid><pubDate>Thu, 06 Jan 2011 22:49:05 +0200</pubDate><category>ruby</category><category>autotest</category><category>rspec</category><category>testing</category><feedburner:origLink>http://itreallymatters.net/post/2626638691</feedburner:origLink></item><item><title>Win32-Screenshot - From Cradle To ...</title><description>&lt;p&gt;
&lt;a href="https://github.com/jarmo/win32screenshot" target="_blank"&gt;Win32-Screenshot&lt;/a&gt; is a library in Ruby for capturing screenshots on the Windows operating system. In this post i’m gonna write about the history of this gem since it just made it to the version 1.0.0 and i find that it deserves some extra attention due to the changes it has gone through.
&lt;/p&gt;

&lt;h3&gt;Pre-Historic Times&lt;/h3&gt;

&lt;p&gt;
The gem was originally created by &lt;a href="http://twitter.com/aslak_hellesoy" target="_blank"&gt;Aslak Hellesøy&lt;/a&gt;, now a lead developer of the popular &lt;a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development" target="_blank"&gt;BDD&lt;/a&gt; library called &lt;a href="http://cukes.info/" target="_blank"&gt;Cucumber&lt;/a&gt;. Let’s see when was the first commit made to the Win32-Screenshot project by him:
&lt;/p&gt;

&lt;pre&gt;
C:\win32screenshot&gt;git log --format=medium | tail -n 5
commit bd172fcc53c9a5a2dc96d5c8b71a2595fb16741b
Author: Aslak Hellesøy &lt;aslak&gt;
Date:   Wed Nov 29 17:27:13 2006 +0000

    Importing
&lt;/aslak&gt;&lt;/pre&gt;
&lt;br/&gt;&lt;p&gt;
It’s over 4 years old! Deciding of the commit message “&lt;i&gt;Importing&lt;/i&gt;”, i’d say that the project started even sooner and got imported to the Git versioning system like this. Too bad that &lt;a href="http://www.kernel.org/pub/software/scm/git/docs/git-svn.html" target="_blank"&gt;git-svn&lt;/a&gt; or something similar was not used to prevent losing the earlier history. The version of the library was at the time 0.0.1. Rails was already rocking with the &lt;a href="https://rubygems.org/gems/rails/versions" target="_blank"&gt;version of 1.1.6&lt;/a&gt;.
&lt;/p&gt;

&lt;h3&gt;Final Publicity&lt;/h3&gt;

&lt;p&gt;
When browsing Git history it’s possible to determine that version 0.0.2 got ready at the 2nd Dec of 2006 and ended up also as a &lt;a href="https://rubygems.org/gems/win32screenshot/versions/0.0.2" target="_blank"&gt;gem on RubyGems&lt;/a&gt;. The API was quite simplistic, but also limited:
&lt;/p&gt;

&lt;p&gt;
&lt;script src="https://gist.github.com/746525.js?file=screenshot_002.rb"&gt;&lt;/script&gt;&lt;/p&gt;&lt;noscript&gt;
&lt;pre&gt;
# takes a screenshot of the foreground
width, height, bmp = Win32::Screenshot.foreground

# takes a screenshot of the desktop
width, height, bmp = Win32::Screenshot.desktop

# takes a screenshot of the window having "Firefox" as part of it's title
width, height, bmp = Win32::Screenshot.window(/Firefox/)

# saves the last bitmap to the file
File.open("c:/images/firefox.bmp", "wb") {|io| io.write(bmp)}
&lt;/pre&gt;
&lt;/noscript&gt;


&lt;p&gt;
There was only three simple methods part of the public API - &lt;i&gt;#foreground&lt;/i&gt;, &lt;i&gt;#desktop&lt;/i&gt; and &lt;i&gt;#window&lt;/i&gt;. All of them returned an array of three elements - &lt;i&gt;width&lt;/i&gt;, &lt;i&gt;height&lt;/i&gt; and &lt;i&gt;bmp&lt;/i&gt;. First two represented obviously width and height of the taken screenshot. Last one, &lt;i&gt;bmp&lt;/i&gt;, was a blob of the bitmap in string format, which allowed it to be written into file by using Ruby’s &lt;a href="http://ruby-doc.org/core/classes/File.html" target="_blank"&gt;File&lt;/a&gt; class like demonstrated above.
&lt;/p&gt;

&lt;h3&gt;Inconveniencies&lt;/h3&gt;

&lt;p&gt;
If we’re to think about the problems of that version’s API, then the main one for me was that three-element array returned from the methods. I wanted to use mostly one of the returned variables and it was obviously the one representing bitmap blob. So i had to do something like this:
&lt;/p&gt;

&lt;p&gt;
&lt;script src="https://gist.github.com/746525.js?file=screenshot_002_api.rb"&gt;&lt;/script&gt;&lt;/p&gt;&lt;noscript&gt;
&lt;pre&gt;
# just ignore width and height variables
width, height, bmp = Win32::Screenshot.foreground
File.open("c:/images/foreground.bmp", "wb") {|io| io.write(bmp)}

# ignore them even more by using special variable names
_, _, bmp = Win32::Screenshot.foreground
File.open("c:/images/foreground.bmp", "wb") {|io| io.write(bmp)}

# just use the Array#[] with index
result = Win32::Screenshot.foreground
File.open("c:/images/foreground.bmp", "wb") {|io| io.write(result[2])}

# or use the Array#last method
result = Win32::Screenshot.foreground
File.open("c:/images/foreground.bmp", "wb") {|io| io.write(result.last)}
&lt;/pre&gt;
&lt;/noscript&gt;


&lt;p&gt;
I didn’t like any of the tricks above. &lt;i&gt;Ruby&lt;/i&gt; is meant to be beautiful and this was just not it.
&lt;/p&gt;

&lt;h3&gt;Usability Limitations&lt;/h3&gt;

&lt;p&gt;
The limitations of the API might have not been so obvious, but i’m sure that eventually anyone who was using it, stumbled onto them. There was nothing wrong with the methods &lt;i&gt;#foreground&lt;/i&gt; and &lt;i&gt;#desktop&lt;/i&gt; since they did what you’d like them to do and there was no way that you’d like them to do anything else (well, maybe you’d have liked the &lt;i&gt;#desktop&lt;/i&gt; to take a screenshot of the actual Windows Desktop and not from the entire visible screen, but that is just the functionality of the Windows API itself).
&lt;/p&gt;

&lt;p&gt;
The &lt;i&gt;#window&lt;/i&gt; method on the other hand supported only searching Windows with a regular expression so if you wanted to take a screenshot of some window with an exact title you had to use something like &lt;i&gt;/^exact title$/&lt;/i&gt;. And you couldn’t do much if you had multiple windows with the exact same title since it was the only thing by which you could search by. Maybe you got lucky and got the correct window each time. Maybe you didn’t.
&lt;/p&gt;

&lt;p&gt;
There were an internal methods called &lt;i&gt;#get_hwnd&lt;/i&gt; and &lt;i&gt;#capture_hwnd&lt;/i&gt; which allowed you to get the &lt;a href="http://en.wikipedia.org/wiki/Handle_(computing)" target="_blank"&gt;handle of the window&lt;/a&gt; and take a screenshot of it. The only problem was that &lt;i&gt;#get_hwnd&lt;/i&gt; allowed to search for windows only by the regular expression of the title like &lt;i&gt;#window&lt;/i&gt; did. If you got the handle to your window from somewhere else then you didn’t have any problems of capturing the correct window. Lucky you.
&lt;/p&gt;

&lt;h3&gt;Technical Limitations&lt;/h3&gt;

&lt;p&gt;
The main technical limitation of the Win32-Screenshot 0.0.2 was that it was using Windows API via &lt;a href="http://ttsky.net/ruby/ruby-dl.html" target="_blank"&gt;Ruby/DL&lt;/a&gt;. The problem with that is the fact that DL is part of the Ruby standard libraries and isn’t compatible between different Ruby versions which automatically meant that Win32-Screenshot was not usable between different versions of Ruby either. There were also occasional segmentation faults happening caused by the DL.
&lt;/p&gt;

&lt;p&gt;
Other big technical limitation was the need to use the &lt;a href="http://rmagick.rubyforge.org/" target="_blank"&gt;RMagick gem&lt;/a&gt; to save screenshots into some other formats than &lt;i&gt;big file-sized&lt;/i&gt; bitmap (bmp). If you’ve used RMagick on Windows then you ought to know that the installation of it can be quite painful.
&lt;/p&gt;

&lt;p&gt;
Allow me to fill you in with the details in case you’re not aware of the complexity of that procedure. You have to install &lt;a href="http://www.imagemagick.org" target="_blank"&gt;ImageMagick&lt;/a&gt;. And not any version will do, but you have to install very specific version of ImageMagick to make your experience a little more pleasant. You can get the specific version from the &lt;a href="http://rubyforge.org/frs/?group_id=12&amp;release_id=42049" target="_blank"&gt;RMagick website&lt;/a&gt;. The provided 24 MB compressed file includes also the gem for that specific version which you can install with usual `gem install` command.
&lt;/p&gt;

&lt;p&gt;
This all works as long as you’re using Ruby 1.8.x MRI version. As soon as you’d like to start using 1.9.x, you’re pretty much on your own. You have to compile RMagick gem for yourself. You ought to know that this is not an easy task under Windows. Yes, you can do it with the help of &lt;a href="https://github.com/oneclick/rubyinstaller/wiki/Development-Kit" target="_blank"&gt;DevKit&lt;/a&gt;, but it’s still quite far of the simplest thing you’ll do within the day or two.
&lt;/p&gt;

&lt;p&gt;
Imagine how hard it is to start using Win32-Screenshot gem with the full potential if every new user has to complete that process manually instead of just executing `gem install win32screenshot`.
&lt;/p&gt;

&lt;p&gt;
In addition to the problems above the version 0.0.2 had also a little bug, which made capturing screenshots fail when they were at certain sizes.
&lt;/p&gt;

&lt;h3&gt;Birthday Party Which Got Cancelled?&lt;/h3&gt;

&lt;p&gt;
I have considered the possibility that most of the problems described above didn’t have any easy solutions at that time due to the missing libraries/tools which exist today, but the biggest problem was that all of these problems existed until May of 2010 when i started to clean it up. I guess Aslak just moved on to other platforms like OS X and didn’t have the time nor will to make it any better.
&lt;/p&gt;

&lt;p&gt;
When browsing more of the Git history then there is one interesting commit:
&lt;/p&gt;

&lt;pre&gt;
C:\win32screenshot&gt;git log --format=medium c8e6f9 | head -n 5
commit c8e6f9e20b957e52d1ddf5d5e0416f7f04d7b12b
Author: Aslak Hellesøy &lt;aslak&gt;
Date:   Thu Jan 18 18:36:15 2007 +0000

    Releasing 0.0.3
&lt;/aslak&gt;&lt;/pre&gt;&lt;br/&gt;&lt;p&gt;
But when &lt;a href="https://rubygems.org/gems/win32screenshot/versions" target="_blank"&gt;looking on the RubyGems&lt;/a&gt; then there isn’t version 0.0.3 anywhere to be found.
&lt;/p&gt;

&lt;p&gt;
The only difference pretty much in that version was a small change in the API - instead of returning a three-element array, a block had to be used for all the methods:
&lt;/p&gt;

&lt;p&gt;
&lt;script src="https://gist.github.com/746525.js?file=screenshot_003_api.rb"&gt;&lt;/script&gt;&lt;/p&gt;&lt;noscript&gt;
&lt;pre&gt;
Win32::Screenshot.foreground do |width, height, bmp|
  File.open("c:/images/foreground.bmp", "wb") {|io| io.write(bmp)}
end
&lt;/pre&gt;
&lt;/noscript&gt;


&lt;p&gt;
I liked it at first, but now i’m thinking that it made the API even worse because there wasn’t even possibility to use Array#[] and Array#last methods anymore to avoid using variables for width and height. You just had to always declare those variables. It was like you had to pay your bills, but you had to do it much often. I’m pretty sure that you understand how uncomfortable that makes you feel.
&lt;/p&gt;

&lt;h3&gt;Change Of Winds&lt;/h3&gt;

&lt;p&gt;
If i recall correctly then i started using the library in the end of 2007. I didn’t know much about the Ruby at the time so i just used it. I noticed that sometimes screenshots capturing failed and other times segmentation fault greeted me with a big smile, but it didn’t happen too often. I was using the library occasionally during the period of two years before these things really started to bug me.
&lt;/p&gt;

&lt;p&gt;
I started by looking for a newer version of the gem, but got disappointed since the last version was still 0.0.2. At least RubyGems told me so. Then i found out that there was offered a patch for the bug of erratic failures of capturing the screenshots. I forked the Win32-Screenshot project, applied the patch and made a pull request to Aslak. Aslak didn’t want to accept the pull request, but offered me to maintain the gem myself. I was surprised by that offer and took it. It was a right thing to do in terms of reviving Win32-Screenshot if i’m thinking about that now. Aslak could just have ignored my pull request and the things would be probably be the same today.
&lt;/p&gt;

&lt;h3&gt;Surfing On The Code&lt;/h3&gt;

&lt;p&gt;
That essentially meant i could do whatever i liked with the library. I’ve added the patch for the bug which caused screenshot capturing to fail and started with replacing fragile Test-Unit tests with more robust RSpec specs.
&lt;/p&gt;

&lt;p&gt;
Next step was to replace Ruby/DL with something else due to these segmentation faults. I didn’t think at first that there would be any problems when using &lt;a href="https://rubygems.org/gems/win32-api" target="_blank"&gt;win32-api gem&lt;/a&gt;. All usages of Ruby/DL got replaced one by one with win32-api until i realized that if i’d like to use Ruby 1.9 then this solution wouldn’t work either, since there wasn’t any pre-built win32-api gem for these versions of Ruby. At this point i discovered the wonderful &lt;a href="https://rubygems.org/gems/ffi" target="_blank"&gt;ruby-ffi gem&lt;/a&gt; which also promised to give me support for JRuby. What a bargain! Again, all usages of win32-api got replaced with ruby-ffi and a support for all MRI versions of Ruby and JRuby was achieved.
&lt;/p&gt;

&lt;p&gt;
I started to like how the code was turning more beautiful with each day and released version 0.0.4 on May 26, 2010. This version addressed those three critical show stoppers - failure of capturing screenshots, segmentation faults and compatibility with different Ruby versions. It felt almost perfect. I called it as “A Complete Overhaul”.
&lt;/p&gt;

&lt;h3&gt;Highway To Better&lt;/h3&gt;

&lt;p&gt;
After the release of version 0.0.4 i started to polish the code and add some additional methods to the API like #window_area and it’s friends, which allowed to capture an area of the window specified by the coordinates. Also, exact window title could now be used by specifying string instead of a regular expression. I got also some contributions from &lt;a href="https://github.com/rdp" target="_blank"&gt;Roger Pack&lt;/a&gt;. I always love contributions, thank you!
&lt;/p&gt;

&lt;p&gt;
From that point forward new versions were released quite often, until 0.0.8. At that moment the API was more or less the same as it was in 0.0.3 (the need to use blocks was still there), but just more methods were in the arsenal. Even methods which didn’t make anymore sense to have in the context of “capturing a screenshot”. For example there were some utility methods like &lt;i&gt;#all_desktop_windows&lt;/i&gt; and &lt;i&gt;#window_process_id&lt;/i&gt;, which just didn’t seem to fit in my mind in that gem.
&lt;/p&gt;

&lt;h3&gt;Cleaning Leaves&lt;/h3&gt;

&lt;p&gt;
That’s when i realized that i wanted to do a completely separate library for searching and retrieving information about the windows. I started development of &lt;a href="http://github.com/jarmo/rautomation" target="_blank"&gt;RAutomation&lt;/a&gt;. I’ve written about that library in my previous post “&lt;a href="http://www.itreallymatters.net/post/2352350743/automating-windows-and-their-controls-with-ruby" target="_blank"&gt;Automating Windows and Their Controls With Ruby&lt;/a&gt;”.
&lt;/p&gt;

&lt;h3&gt;Extermination Of Bad Bacteria&lt;/h3&gt;

&lt;p&gt;
As written above then the bad dependencies for Win32-Screenshot included ImageMagick and RMagick. I tried to find a way to remove the need for dependencies which need to be installed separately of the gem. My research for possible options ended up with an unfortunate news that there just wasn’t any fast enough solutions to save files to PNG format with pure Ruby. The next best idea was to use &lt;a href="https://github.com/probablycorey/mini_magick" target="_blank"&gt;MiniMagick&lt;/a&gt;, which is a Ruby library wrapping ImageMagick’s executables for image manipulation and saving to different formats. So if i could bundle all necessary ImageMagick’s libraries and binaries with the gem i’d be on the road.
&lt;/p&gt;

&lt;p&gt;
You know what? I managed to do it! Starting from version 1.0.0 all necessary parts of ImageMagick are bundled with the gem which means that you don’t have to have ImageMagick nor RMagick installed to save screenshots into BMP, GIF, JPG or PNG formats with Win32-Screenshot! Now you just have to have Ruby installed and you can just execute `gem install win32screenshot` and not worry about anything else. Awesome, isn’t it?
&lt;/p&gt;

&lt;h3&gt;The New Beginning&lt;/h3&gt;

&lt;p&gt;
Removal of dependencies ImageMagick and RMagick made me think that maybe, just maybe, i could make Win32-Screenshot even better.
&lt;/p&gt;

&lt;p&gt;
Creation of RAutomation allowed me to delete a lot of code from Win32-Screenshot. For example i was able to delete all the code related with searching the windows - “Capturing screenshots functionality shouldn’t know anything about how to find windows”, i thought. All that code, in better form of course, ended up in RAutomation. I just had to set RAutomation as a Win32-Screenshot’s dependency and start using it in the code.
&lt;/p&gt;

&lt;p&gt;
By using RAutomation i got this idea of changing the API of Win32-Screenshot quite drastically to make it better, but of course break backwards compatibility as a side-effect. I started to tinker the code by trying out different ways of how the new API could look like. The result i came up with has only one method in the public API which parameters decide what to take screenshot of and an &lt;i&gt;Image&lt;/i&gt; class which holds the bitmap data with allowing to save it to the disk. Check out the following examples:
&lt;/p&gt;

&lt;p&gt;
&lt;script src="https://gist.github.com/746525.js?file=screenshot_100_api.rb"&gt;&lt;/script&gt;&lt;/p&gt;&lt;noscript&gt;
&lt;pre&gt;
# Take a screenshot of the window with the specified title
Win32::Screenshot::Take.of(:window, :title =&gt; "Windows Internet Explorer").write("image.bmp")

# Take a screenshot of the foreground
Win32::Screenshot::Take.of(:foreground).write("image.png")

# Take a screenshot of the specified window's top-left corner's area
Win32::Screenshot::Take.of(:window, :title =&gt; /internet/i, :area =&gt; [10, 10, 20, 20]).write("image.jpg")

# Take a screenshot of the window with the specified handle
Win32::Screenshot::Take.of(:window, :hwnd =&gt; 123456).write("image.gif")

# Take a screenshot of the child window with the specified internal class name
Win32::Screenshot::Take.of(:window, :rautomation =&gt; RAutomation::Window.new(:hwnd =&gt; 123456).
        child(:class =&gt; "Internet Explorer_Server")).write("image.png")

# Use the Image for something else than #write
image = Win32::Screenshot::Take.of(:window, :hwnd =&gt; 123456)
image.height # =&gt; height of the image
image.width  # =&gt; width of the image
image.bitmap # =&gt; bitmap blob
&lt;/pre&gt;
&lt;/noscript&gt;


&lt;p&gt;
The integration with RAutomation allows to use the same nice API for specifying what window to take a screenshot of. I’ve also made it possible to give a RAutomation window object directly as a parameter to make it all even more flexible without the need to add much complexity to the Win32-Screenshot’s own code. Also, the #write method used in the examples above works as you might expect - if you specify the image file extension as a “.png” then it will be saved into the PNG format. No need to specify anywhere explicitly that you really want it to be saved as a PNG format and not just with an extension of “.png”.
&lt;/p&gt;

&lt;h3&gt;From Cradle to Adulthood&lt;/h3&gt;

&lt;p&gt;
There is this other popular saying called “From Cradle To Grave”, but this post is not about that at all even if the title might have suggested it. This is about a birth and it’s journey to it’s adulthood of Win32-Screenshot. It made it to the version of 1.0.0 on December 16th of 2010. Since it is now following “&lt;a href="http://semver.org/" target="_blank"&gt;Semantic Versioning&lt;/a&gt;” rules then i felt increasing the major version number due to the backwards incompatibility changes to it’s API. Also there’s a statement on the “Semantic Versioning” guidelines which just made it great to increase the version: “Version 1.0.0 defines the public API”. I’m declaring to the world that this is the public API and i’m really happy with the results code-wise and API-wise.
&lt;/p&gt;

&lt;p&gt;
Thank you, Aslak for making it all possible! Happy holidays with screenshottin’ and don’t hesitate to give me any feedback!
&lt;/p&gt;

&lt;p&gt;
One last thing - guess what happens if the following code is executed right now on my machine:
&lt;/p&gt;

&lt;p&gt;
&lt;script src="https://gist.github.com/746525.js?file=source_of_awesomeness.rb"&gt;&lt;/script&gt;&lt;/p&gt;&lt;noscript&gt;
&lt;pre&gt;
Win32::Screenshot::Take.of(:window, :title =&gt; /GVIM/, :area =&gt; [75, 0, 575, 180]).write("c:/images/source_of_awesomeness.png")
&lt;/pre&gt;
&lt;/noscript&gt;


&lt;p&gt;
Of course glimpse of &lt;i&gt;The Awesomeness&lt;/i&gt; will be saved to my disk with &lt;i&gt;The Awesomeness&lt;/i&gt; itself. It’s almost as scary as running &lt;a href="http://en.wikipedia.org/wiki/Virtual_machine" target="_blank"&gt;VM&lt;/a&gt; inside of another VM!
&lt;/p&gt;

&lt;p&gt;
&lt;img src="http://dl.dropbox.com/u/2731643/blog/win32screenshot_introduction/source.png" alt="Screenshot Of The Awesomeness"/&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/PIieSQT0Ygs" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/PIieSQT0Ygs/2419607946</link><guid isPermaLink="false">http://itreallymatters.net/post/2419607946</guid><pubDate>Wed, 22 Dec 2010 22:28:00 +0200</pubDate><category>ruby</category><category>screenshot</category><category>windows</category><feedburner:origLink>http://itreallymatters.net/post/2419607946</feedburner:origLink></item><item><title>Automating Windows and Their Controls With Ruby</title><description>&lt;p&gt;
&lt;b&gt;Update:&lt;/b&gt; added part about handling popups.
&lt;/p&gt;

&lt;p&gt;
How would you automate windows and their controls like button and text fields if you had to? How would you do that in Ruby? I guess you wouldn’t. At least not in any user-friendly way.
&lt;/p&gt;

&lt;p&gt;
Until now. I’ve created a Ruby library called &lt;a href="https://github.com/jarmo/rautomation" target="_blank"&gt;RAutomation&lt;/a&gt; which allows you to control windows, retrieve different kind of information about them, fill text fields with desired jargon and click the buttons on them! That’s all via very user friendly API.
&lt;/p&gt;

&lt;h3&gt;Let’s Start to RAutomate&lt;/h3&gt;

&lt;p&gt;
For example, let’s fire up &lt;i&gt;Internet Explorer&lt;/i&gt; so that it has &lt;i&gt;File Save As&lt;/i&gt; dialog opened like seen on the picture below:
&lt;/p&gt;

&lt;p&gt;
&lt;img alt="Internet Explorer's Save As Dialog" src="http://dl.dropbox.com/u/2731643/blog/rautomation_introduction/ie_file_save_as_dialog.png"/&gt;&lt;/p&gt;

&lt;p&gt;
Now, let’s install RAutomation gem and start up an irb session so we can have our fun with that window:
&lt;/p&gt;

&lt;p&gt;
&lt;script src="https://gist.github.com/745734.js?file=rautomation_first.rb"&gt;&lt;/script&gt;&lt;/p&gt;&lt;noscript&gt;
&lt;pre&gt;
C:\Users\jarmo&gt;gem install rautomation
Successfully installed rautomation-0.2.1
1 gem installed

C:\Users\jarmo&gt;irb
require "rautomation"
=&gt; true
window = RAutomation::Window.new :title =&gt; "File Download"
=&gt; #&lt;:window:0x359268&gt;"File Download"}&gt;, @adapter=:ffi&gt;
window.title
=&gt; "File Download"
window.exists?
=&gt; true
window.visible?
=&gt; true
window.hwnd
=&gt; 30345632
&lt;/:window:0x359268&gt;&lt;/pre&gt;
&lt;/noscript&gt;


&lt;p&gt;
If you’ve used browser automation tool called &lt;a href="http://www.watir.com" target="_blank"&gt;Watir&lt;/a&gt; before then the code above should seem awful lot similar. The thing is that RAutomation’s API is inspired by Watir’s clean and nice API. Awesome news, isn’t it?
&lt;/p&gt;

&lt;p&gt;
You can also see that i’ve managed to &lt;i&gt;find&lt;/i&gt; the window, made sure that it has a title, that it exists, is visible and has a &lt;a href="http://en.wikipedia.org/wiki/Handle_(computing)" target="_blank"&gt;window handle (hwnd)&lt;/a&gt;. Nice.
&lt;/p&gt;

&lt;h3&gt;Clicking the Button&lt;/h3&gt;

&lt;p&gt;
Ok, let’s click the &lt;i&gt;Save&lt;/i&gt; button because that’s what i want to do, right? I want to download RAutomation’s gem from the &lt;a href="https://rubygems.org/gems/rautomation" target="_blank"&gt;RubyGems website&lt;/a&gt;! That would sound just odd if i wouldn’t. Clickety, click…
&lt;/p&gt;

&lt;p&gt;
&lt;script src="https://gist.github.com/745734.js?file=rautomation_click.rb"&gt;&lt;/script&gt;&lt;/p&gt;&lt;noscript&gt;
&lt;pre&gt;
window.button(:value =&gt; "&amp;Save").click
=&gt; true
&lt;/pre&gt;
&lt;/noscript&gt;


&lt;p&gt;
Whoops. That was almost as easy as walking in the park. The following window appears to make sure that i really want to download the file and i really know where to put it:
&lt;/p&gt;

&lt;p&gt;
&lt;img style="text-align: center;" alt="Yet another Save As Dialog" src="http://dl.dropbox.com/u/2731643/blog/rautomation_introduction/ie_file_save_as_dialog_2.png"/&gt;&lt;/p&gt;

&lt;h3&gt;Filling the Fields&lt;/h3&gt;

&lt;p&gt;
If we’ve already come so far then what choice do we even have anymore? I guess we have to tell it where to save the file. Let’s do it!
&lt;/p&gt;

&lt;p&gt;
&lt;script src="https://gist.github.com/745734.js?file=rautomation_edit.rb"&gt;&lt;/script&gt;&lt;/p&gt;&lt;noscript&gt;
&lt;pre&gt;
new_window = RAutomation::Window.new :title =&gt; /save/i
=&gt; #&lt;:window:0x5730f90&gt;/save/i}&gt;, @adapter=:ffi&gt;
new_window.title
=&gt; "Save As"
edit_field = new_window.text_field :class =&gt; "Edit"
=&gt; #&lt;:textfield:0x56c19d8&gt;/save/i}&gt;, @locators={:class=&gt;"Edit"}, @text_field=#&lt;:adapter::ffi::textfield:0x56c1990&gt;/save/i}&gt;, @locators={:class=&gt;"Edit"}&gt;&gt;
edit_field.exists?
=&gt; true
edit_field.value
=&gt; "rautomation-0.2.1.gem"
edit_field.set "c:\\users\\jarmo\\rautomation-0.2.1.gem"
=&gt; true
edit_field.value
=&gt; "c:\\users\\jarmo\\rautomation-0.2.1.gem"
&lt;/:adapter::ffi::textfield:0x56c1990&gt;&lt;/:textfield:0x56c19d8&gt;&lt;/:window:0x5730f90&gt;&lt;/pre&gt;
&lt;/noscript&gt;


&lt;h3&gt;Saving The File?&lt;/h3&gt;

&lt;p&gt;
It’s also possible to search windows by regular expressions? Nice! Ok, let’s click now that final &lt;i&gt;Save&lt;/i&gt; button. Oh, dang. I just realised that i already have this nice gem because i installed it with &lt;i&gt;`gem install rautomation`&lt;/i&gt; early on. It would be just plain stupidity to download it again, especially like this. I guess i’ll just ditch the window instead and carry on with the knowledge of having this wonderful library already in my posession.
&lt;/p&gt;

&lt;p&gt;
&lt;script src="https://gist.github.com/745734.js?file=rautomation_close.rb"&gt;&lt;/script&gt;&lt;/p&gt;&lt;noscript&gt;
&lt;pre&gt;
new_window.close
=&gt; nil
new_window.exists?
=&gt; false
&lt;/pre&gt;
&lt;/noscript&gt;


&lt;h3&gt;What About Popups?&lt;/h3&gt;

&lt;p&gt;
Let’s pretend that after you closed the window above, the following threatening JavaScript popup appeared out of nowhere:
&lt;/p&gt;

&lt;p&gt;
&lt;img style="text-align: center;" alt="Threatening JavaScript popup" src="http://dl.dropbox.com/u/2731643/blog/rautomation_introduction/js_alert.png"/&gt;&lt;/p&gt;

&lt;p&gt;
First of all, if you’re using &lt;i&gt;Watir&lt;/i&gt; then &lt;a href="http://www.itreallymatters.net/post/1482786902/testing-webpages-with-javascript-popups-correctly" target="_blank"&gt;make sure that you’re testing your page correctly&lt;/a&gt;. If that’s not the case, then by all means, take risks in your life once in a while and close that popup:
&lt;/p&gt;

&lt;p&gt;
&lt;script src="https://gist.github.com/745734.js?file=rautomation_popup.rb"&gt;&lt;/script&gt;&lt;/p&gt;&lt;noscript&gt;
&lt;pre&gt;
RAutomation::Window.new(:title =&gt; /windows internet/i).child(:title =&gt; /message from webpage/i).close
=&gt; nil
&lt;/pre&gt;
&lt;/noscript&gt;


&lt;h3&gt;Where’s The Catch?&lt;/h3&gt;

&lt;p&gt;
The catch is that not all kind of windows and platforms are supported. &lt;b&gt;Yet&lt;/b&gt;. Currently only Windows operating system and windows using Windows’ native components are (fully) supported. But why did i emphasize on the “&lt;i&gt;Yet&lt;/i&gt;”? That’s because RAutomation is built to allow cross-platform compatibility with easy extensibility by allowing to support all kind of different technologies. This is where the Adapter comes into the play.
&lt;/p&gt;

&lt;h3&gt;What’s an Adapter?&lt;/h3&gt;

&lt;p&gt;
RAutomation’s adapter is a technical component of the library being responsible for dealing with controlling windows and their controls on a specific operating system for specific technologies. As stated above then currently only Windows operating system is supported with two different adapters - &lt;i&gt;:ffi&lt;/i&gt; and &lt;i&gt;:autoit&lt;/i&gt;. By default &lt;i&gt;:ffi&lt;/i&gt; adapter is used on Windows to execute Windows’ API functions directly. If there’s any need to change the adapter then it’s possible to specify another default one by using an environment variable called &lt;i&gt;RAUTOMATION_ADAPTER&lt;/i&gt; or specifying different adapter for controlling specific window with the &lt;i&gt;:adapter&lt;/i&gt; option:
&lt;/p&gt;

&lt;p&gt;
&lt;script src="https://gist.github.com/745734.js?file=rautomation_adapter.rb"&gt;&lt;/script&gt;&lt;/p&gt;&lt;noscript&gt;
&lt;pre&gt;
C:\Users\jarmo&gt;set RAUTOMATION_ADAPTER=autoit

ie_autoit = RAutomation::Window.new :title =&gt; /internet explorer/i
=&gt; #&lt;:window:0x480c000 explorer&gt;, @adapter=:autoit&gt;
ie_autoit.hwnd
=&gt; 18155218
ie_ffi = RAutomation::Window.new :hwnd =&gt; 18155218, :adapter =&gt; :ffi
=&gt; #&lt;:window:0x59fd2d0 :hwnd=""&gt;18155218}&gt;, @adapter=:ffi&gt;
ie_ffi.hwnd
=&gt; 18155218
&lt;/:window:0x59fd2d0&gt;&lt;/:window:0x480c000&gt;&lt;/pre&gt;
&lt;/noscript&gt;


&lt;p&gt;
Since i’ve set the environment variable to &lt;i&gt;autoit&lt;/i&gt; then the first window is using adapter for &lt;a href="http://www.autoitscript.com/autoit3/index.shtml" target="_blank"&gt;AutoIt&lt;/a&gt;. The second one uses &lt;a href="https://github.com/ffi/ffi" target="_blank"&gt;FFI&lt;/a&gt; instead since i specified it with an &lt;i&gt;:adapter&lt;/i&gt; option. And of course they both point to the same physical &lt;i&gt;Internet Explorer&lt;/i&gt; window.
&lt;/p&gt;

&lt;h3&gt;How to Create New Adapters?&lt;/h3&gt;

&lt;p&gt;
Since i’ve built RAutomation having all kinds of different platforms and technologies in mind, i’ve created a possibility to extend it relatively easily. If it’s possible to automate windows with Ruby directly or with the help of some external tools on the platform, then it should be possible to create a new Adapter for RAutomation. Just follow the steps below. I’d be happy to merge the results into the master.
&lt;/p&gt;

&lt;ul&gt;&lt;li&gt;Fork the project at &lt;a href="https://github.com/jarmo/rautomation" target="_blank"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Create entry point file to &lt;i&gt;lib/rautomation/adapter&lt;/i&gt; which should load all adapter specific files&lt;/li&gt;
&lt;li&gt;Add `autoload` statement into &lt;i&gt;lib/rautomation/adapter/helper.rb&lt;/i&gt; for that file&lt;/li&gt;
&lt;li&gt;Create a directory for your adapter’s specific code into &lt;i&gt;lib/rautomation/adapter&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;Copy &lt;i&gt;button.rb&lt;/i&gt;, &lt;i&gt;text_field.rb&lt;/i&gt; and &lt;i&gt;window.rb&lt;/i&gt; from some of the existing adapter’s directory&lt;/li&gt;
&lt;li&gt;Add spec data for your adapter into &lt;i&gt;spec/spec_helper DATA&lt;/i&gt; constant&lt;/li&gt;
&lt;li&gt;Use environment variable &lt;i&gt;RAUTOMATION_ADAPTER&lt;/i&gt; to point to that adapter&lt;/li&gt;
&lt;li&gt;Start coding and spec-ing until as much of possible of the public API is satisfied&lt;/li&gt;
&lt;li&gt;Make me a pull request&lt;/li&gt;
&lt;/ul&gt;&lt;p&gt;
Until then, have fun with the existing adapters!
&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/ITReallyMatters/~4/YFs9mIN-PJE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/ITReallyMatters/~3/YFs9mIN-PJE/2352350743</link><guid isPermaLink="false">http://itreallymatters.net/post/2352350743</guid><pubDate>Sat, 18 Dec 2010 01:07:00 +0200</pubDate><category>ruby</category><category>automation</category><category>testing</category><feedburner:origLink>http://itreallymatters.net/post/2352350743</feedburner:origLink></item></channel></rss>

