Monday, August 30, 2010

Sliding scrum ;)


Sometimes vacation plays hell with your nice schedule. This picture is from a maintenance sprint at work, they solved the problem in they're own way ;) 
It works for them, and if it ain't broken ... don't fix it!
We might want to recommend them to end the sprint soon though!

Thursday, August 19, 2010

Friday, August 6, 2010

Accessing Network resources as Administrator on Windows 7

One of the problems I had when using RubyGems (Ruby 1.91) on Windows 7 was that my homedrive is on a network drive.
So when running rubygems in an elevated command prompt (ie running "As Administrator"), rubygems exited with an error something like could not access H:\. Now this is a problem for me since I want those rubygems on my laptop because I want to be able to work offline (ie at home etc).

After some googling I found out that when running as Administrator the network resources that you have as a normal user are not accessible when you are running as Administrator.
This article here from Microsoft support describes how to do this. Cutting to the chase, you need to:

  1.  create an DWORD key in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System called EnableLinkedConnections and set it's value to 1. 
  2. Reboot
And that's it! Now your existing resources are available when you run as Administrator.

Friday, July 30, 2010

Stuck

At the moment I am stuck with some 64 bit problems.
Cannot get ruby 1.91 and Selenium 2.0 to work on the 64 bit windows 2008 server to work.
Since I do _not_ want to mess with that server I am waiting for Infrastructure to get me a clone so I can go medieval on this issue.

Tuesday, July 27, 2010

The troll approves of

Testing

Lean & Agile

The trolls recipe for "Getting started with Selenium 2.0 and Ruby"

To tired today to post anything of use. Also it's launch day for Starcraft II, that is going to destroy my whole week!

Got some more exploration of Selenium 2.0 and Ruby lined up.
Also I really need to write a "short" post about Lean, Agile and the role of self-inspection. Some stuff I need to get of my shoulders there, best way is probably to rant some about it ;)

Posts so far in the series "The Trolls recipe for  'Getting started with Selenium 2.0 and Ruby'" a.k.a The mountain troll does Selenium 2:

  1. Getting started with Selenium 2.0 and Ruby
  2. Moving on to the second example
  3. Adding automation to your Selenium 2.0 tests (Ruby)


/The tired troll

Monday, July 26, 2010

Adding automation to your Selenium 2.0 tests (Ruby)

When I started with this stuff, what I really missed were some simple examples with links to further reading. Hopefully this series of posts here at the Troll can fulfill that category.

Now to make the Google suggest test automation ready. To do that we add two of Ruby's most trusted and proven gems. RSpec and Rake, nowdays Rake is distributed with Ruby (1.9+). We will add a very simple Rakefile and RSpec up our test. And to be build server ready we will add ci_reporter to get those nifty junit compatible test reports that your build server loves.

Now this post is not supposed to be an lesson in RSpec or Rake, I warmly recommend http://rspec.info if you want to get started with RSpec. Rake is harder to find a real good "howto" page for, but a simple google search should get you started. For ci_reporter go to http://caldersphere.rubyforge.org/ci_reporter/.

If you haven't already have the required gems installed here are the commands:
gem install rspec
gem install ci_reporter
and ruby 1.8x only => gem install rake


The testcase
We want to be sure that there is cheesecake in the suggestion list. In addition to the we make two other checks:
1) That we are indeed on a google page (match/regexp example), and
2) that the suggestion list is displayed (no suggestions displayed => no cheesecake => sad troll)

So let's take our old trusty googlesuggest_test.rb and copy to googlesuggest_spec.rb  _spec.rb is the usual name convention for rspec test files. We will use this later in the rakefile.

The code
I have added short notes on important places in the code noted with (x) where x is a number.

require "rubygems"
# (1) Add spec as required
require "spec"
require "selenium-webdriver"

# (2) This is how a testsuite is described/started in
# rspec (required)
describe "find_cheesecake" do

  # (3) before actions are either berfore :all cases in the 
  # suite (ie run once) or :each (ie run once before each case)
  # Here we start up the browser
  before(:all) do
    @driver = Selenium::WebDriver.for :firefox
  end

  # (4) Start of testcase the rspec way
  it "should be cheesecake" do
    @driver.navigate.to "http://google.com"
    # Did we arrive? 
    # (5) Check if the title of the page starts with "Google"
    @driver.title.should match(/^Google/)

    element = @driver.find_element(:name, 'q')
    element.send_keys "cheese"

    # wait 5 s or until form is loaded
    five_sec = (Time.now) + 5
    until five_sec < Time.now
      resultsDiv = @driver.find_element(:class_name, "gac_m")
      if resultsDiv.displayed?
        break
      end
    end
    # (6) We do not want to continue if the resultDiv
    # did not display
    resultsDiv.displayed?.should be_true

    list = @driver.find_elements(:xpath, "//td[@class='gac_c']")
    # We do love cheesecake and need it in the list
    # to be satisfied.

    # Do a find in the list for "cheesecake"
    res = list.find {|ele| ele.text == "cheesecake"}

    # (7) if no cheesecake was found, the result is "nil"
    # == sad troll
    res.should_not be_nil
  end

  # (8) "after" works like "before" but only after :)
  after(:all) do
    # ensure that the browser is shutdown
    @driver.quit
  end
end


RSpec assertions are usually done with .should, more information about them are available on the Spec::Matchers page.


Now we need to test this, start your favorite terminal and navigate to the correct directory and run

spec googlesuggest_spec.rb


if everything was OK you will get a result similar to this

C:\Projects\selenium2_test> spec googlesuggest_spec.rb
.

Finished in 9.750975 seconds

1 example, 0 failures

Adding a rakefile
Adding a quick rakefile is quite easy (if you know howto) further reading about spec tasks and rakefiles is availble on the web. Good starting places would be http://rake.rubyforge.org/ and http://rspec.info/documentation/tools/rake.html

We add ci_reporter to it as per http://caldersphere.rubyforge.org/ci_reporter/

require "rubygems"
require "rake"
require "spec/rake/spectask"
gem 'ci_reporter'
require 'ci/reporter/rake/rspec'

desc "Run all examples"
Spec::Rake::SpecTask.new('examples') do |t|
  t.spec_files = FileList['*_spec.rb']
  t.fail_on_error = false
end

As you can see in the "examples" task, we add all files in the directory which match "*_spec.rb". The task it self know how to run em.
Save as "Rakefile" and the run
rake examples
in your terminal window, output should be like this:

C:\Projects\selenium2_test> rake examples
(in C:/Projects/selenium2_test)
.

Finished in 8.532853 seconds

1 example, 0 failures

Now to run it with ci_reporter to get the unit test compatible report, run
rake ci:setup:rspec examples
and you shall be rewarded with an SPEC-find-cheesecake.xml test report file in the spec\reports sub-directory. ci_reporter will produce 1 xml file per test suite (those started with describe as you remember).


The last command is also the one you want your build server to run, then you point it to the reports directory for test results.