Tuesday, December 7, 2010

Ruby, rspec 1.x and cygwin

One thing that has irritated me for a long time is the inability to run rspec tests in Cygwin without having to maintain dual environments. Keeping 2 parallel environments one for Windows and one for "Cygwin on Windows" is an exercise in futility. But finally I decided to "hack" it, not that i's really an hack.

Use => ruby "c:\Ruby191\bin\spec" item_spec.rb

Replace C:\Ruby191 with your ruby installation directory and ofc item_spec.rb with your spec file of choice.

For an even more easy way, put it as an alias in your .bash_profile, e.g.
alias rsp="ruby 'c:\Ruby191\bin\spec'"

Then you can use => rsp item_spec.rb

More detailed explanation:
in the bin directory there is an spec.bat, the mixture of Ruby for Windows and Cygwin has a problem with paths. So by running the command in the spec.bat file we circumvent that problem and voila everything works.

Addition: Regarding my environment. Due to restrictions with selenium grid and local factors I am using ruby 1.87 and 1.9.1, with rspec 1.2.8 and latest selenium-client (as of 2010-11).

Tuesday, November 16, 2010

How to teach non-tech savy testers to automate (part 1)

or "Make the testers more effective"

Watch out here, you are about to be critted by a wall of text... and as usual the troll expects all to forgive him his mistakes, especially all the typos!

Make the testers more effective..

I have gone through this a couple of times, and there have been some good articles on related subjects. But I can't seem to find them when I need to. In short I usually find me in the position of advocating that we need to make a testers time more effective. So we need to teach testers to automate their test. Now some of them are from a programmer background, some have education in systems development on so on and so forth.
But there is always some there that do not either have the technical background or just haven't had the time or the interest to delve deeper into the automation side of testing.
Usually the tester gaining the most from being able to automate they're tests are just so overloaded that they never seem to have the time to do check out the benefits of automating the boring basic regression tests that most application seem to need, i.e. is the logo still there, the submit button, the company information and so on and so forth.

I have seen several Let's get all automated drives in companies fail horrible. Usually these drives tend to share the same problems. Bing Bang approach and using too techy approach for non tech aligned testers.
Let’s look at them one at a time:

Big Bang approach to problem solving is usually bad and at the worst a recipe for disaster, if the problem is huge then solving it one piece at a time is the way to go. Where do you think that the proverb "divide and conquer" comes from... Divide up your problems and conquer each "mini" problem at the time and you will have much better success.

"Too Techy” approach to automation seems to be a normal problem. Usually the organization uses a certain programming language and tools. They then feel that, in order to maintain conformity, they must use the same languages and tools for test automation. This is a problem for many testers since they are often more analytical then "programatical" (did I just invent a word oO). Why not let the testers use an easy to understand and light scripting language instead (and for the love of God I hope you do not think of Perl as one of those). That way the big hump to overcome when starting automation is lessened. A good slide show about this (and very related to this topic) can be viewed at Mountains to Molehills: A Story of QA

Confronting the problem

So how do we get people that are busy or not really interested to develop a spark and interest for automating they're testing?
I find it best to confront this from the “basic” regression test side. These tests often get ignored or skipped or worse when under pressure. Everyone acknowledges that they really need to be run, but ...
So by approaching the problem from this side it is quite easy to get even the non tech-savy tester to get interested.
I am going to lay out my approach here, and then I’ll go deeper into each one further down in this (or next!) post.

Building Awareness

Point out the problem areas and offer to show them how you can help them solve them. Usually these are the basic regression tests. Then ask for a basic regression test case and bring that up (usually those are in excel). (Install and) Fire up Firefox and install the Selenium IDE. Start the IDE and and record at least two cases. Now run them in a suite.

This is usually enough to get a tester started. They see now that they can make a suite of easy tests and that it’s not hard! Now leave them for a while with the mission to make test cases in the IDE from those basic regression tests. It is very important to stress that if they run into problems in a case, it is better to skip that case and later bring that up with you (or go Google the problem). During this stage I usually send them some good pointers, like the Selenium IDE documentation page on SeleniumHQ.

to be continued...

Friday, September 3, 2010

WIFI problems on the android

Very nice article about WIFI problem solving on the andriod. Helped me connect to the 802.1x Enterprise WIFI at work on my android. How to fix Android Wi-Fi problems.

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.

Lowland troll

The troll and the missus went for a short hike around their new home. Too much forest and to few mountains QQ. Since a cold weather front moved in and the temperature dropped as a rock, it was an excellent opportunity for a quick hike. No risk of sunburns and other evil lowland stuff.

Wet troll on a puny hill.

13 degrees Celcius and rain is good weather for the trusty hiking gear, we skipped the wool underwear though.

Friday, July 23, 2010

Moving on to the second example

The second example in the 5 minute getting started guide is an example for reading the suggestions from a suggestions list on google page. Type in any word there and voila it shows a list with suggestions on what you really "might be/are" seatching for.

This trick of pulling out that list is a neat webdriver trick.

The example it self is easy to convert to ruby, just copy the old one and remove the "puts driver.title" then add the new code. The ugly thing about it is that busy loop to wait for the suggestion list to appear, but we'll ignore that for now.

The ruby:fied code with added "catch all" exception handling to ensure that it closes the browser if possible. Note that you can replace firefox with e.g. ie or chrome if you like.

require "selenium-webdriver"

begin
  driver = Selenium::WebDriver.for :firefox
  driver.navigate.to "http://google.com"

  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

  #write em out
  list = driver.find_elements(:xpath, "//td[@class='gac_c']") 
  list.each do |ele|
    puts ele.text
  end

rescue
  puts $!, $@
end

driver.quit

The trick here was to find the ruby bindings equivalent for driver.findElement(By.className("gac_m")), driver.findElements(By.xpath("//td[@class='gac_c']")) and getText(). Quick search of the excellent (but devoid of examples) API documentation for the Ruby bindings turned out the correct answer. The answer was to use driver.find_element(:class_name, "gac_m"), driver.find_elements(:xpath, "//td[@class='gac_c']") and text.

When you run this it will reward you with a printout in the console with all the different suggestions for "cheese" weee! Cheesecake here we come!

Note that unless you are in Sweden you will get a different list then me, evil redirects ... :/

C:\Projects\selenium2_test>ruby googlesuggest_test.rb
cheesecake
cheesecake recept
cheese
cheesecake hallon
cheesecake fryst
cheesecake factory
cheesecake citron
cheesecake i glas
cheesecake passionsfrukt
cheesecake vit choklad


Next post will be about making it build server ready, we trolls love automation and will be adding Rspec, Rake and Ci_reporter stuff to this to get it to check if cheesecake is indeed one of the suggestions by Google.

p.s.
What frustrated me in the beginning was that the "meat" in the documentation is accessible thru the 3 boxes in the top right (class list, method list and file list). d.s.

Getting started with Selenium 2.0 and Ruby

Since my previous post about this was a bit trollish, I decided to redo it.
selenium-webdriver with ruby 1.86+ should work out of the box. But with ruby 1.9x and windows you might need too do some tiny troll magic.

Resources:
Ruby installers
Selenium-Webdriver Ruby Bindings
How to fix the msvcrt-ruby18.dll Ruby 1.9 problem

Installing Ruby
If you haven't installed ruby yet, you will need to do so. Head over to http://rubyinstaller.org/downloads/ and grab the one you prefer (I used ruby 1.91). Install it.

Installing the selenium-webdriver gem
After that we need to install the selenium-webdriver gem. Fire up a cmd/terminal. Some systems might force you to do this as an administrator, see Howto start cmd as an Administrator.
On OSX make sure to use sudo, note that you need administration privileges to be able to use sudo.

Windows: gem install selenium-webdriver
OSX and other sudo thingamajig: sudo gem install selenium-webdriver


Try the example:
Now if you want you can try the example at the RubyBindings page.
If this works now, you don't need to do anything more! If you get a popup about msvcrt-ruby18.dll then you need to read on.


Fixing the "msvcrt-ruby18.dll missing" problem:
Windows and Ruby 1.9 only
The problem is in the win32-api dependency, (one of the gems installed). The solution is outlined here.
What you need to do is to rebuild that gem locally, to do that you need to install the devkit from rubyinstaller.org.

Download the devkit at the Rubyinstaller.org download page.
Unpack it into you ruby installation root directory (for me it was C:\Ruby191)

Run the commands detailed in the fix post.
gem uninstall win32-api 
and  then
gem install win32-api --platform=ruby

This should be it, your example should run fine now.

Next post:
Next post will be about "rubyfying" example 2 in the 5 minute getting started guide for Selenium 2.0

Last post and the next ones

The last post was a little .. well .. trollish. It was exactly as I solved the issue, but really thrown together in about 5 minutes.

I´ll redo that post tonight, making it a bit more organised and readable. Then continue on with some more examples of using selenium-webdriver. Then there is the most important part ofc, hooking it up to a unit test framework for automation. We trolls like automation .. yes we do.

We also need to check if the selenium-webdriver gem contains all that is needed, last day was a bit "download all we need and throw it in there to be sure" kind of day.

Thursday, July 22, 2010

The troll takes on selenium 2.0

EDIT: On checking the selenium-webdriver gem, it seems to include everything needed to drive the browsers. So step 2-4 is not really needed. But still, below is exactly how I did this yesterday.

Not that I really work with testing anymore, it still interest me. Well at least getting it more and more automated.
So getting Selenium 2.0 running on my windows laptop sounded like a good summer activity.

In fairness the people responsible for both Selenium 2.0 and selenium-webdriver (which is the ruby frontend, packaged as a ruby gem) did a fantastic job.

You need following installed to get it working:
Firefox (or else you can change the example code to use IE or Chrome etc.)
Ruby 1.9
(Selenium 2.0)
And a few more stuff detailed below.
  1. I installed first ruby 1.8.7 and the ruby 1.9.1 from the one-click installers.
  2. Then I went to the SeleniumHQ and specifically they're Webdriver page.
  3. Downloaded the complete package (selenium-server-2.0a5.zip) from the downloads page.
  4. Unpacked it and added that directory to the CLASSPATH environment variable (I used C:\selenium-2.0a5).
  5. Fired up a cmd prompt and installed the selenium-webdriver gem (gem install selenium-webdriver).
  6. Navigated to the ruby bindings webpage for the WebDriver API => http://code.google.com/p/selenium/wiki/RubyBindings
  7. Fired up gvim (feel free to use your favorite editor here!)
  8. Copy and pasted they're first example and it failed horrible. (Note that on some systems you will need 'require "rubygems"', best is to always use it). Save as google_test.rb
  9. Googled the problem "msvcrt-ruby18.dll selenium-webdriver", found a related watir problem => http://code.google.com/p/selenium/issues/detail?id=583
  10. Installed the devkit from rubyinstaller.org, devkit is available for download on this page => http://rubyinstaller.org/downloads/
  11. unpacked the contents into my ruby 1.9 directory (I use C:\Ruby191)
  12. fired up the cmd again and ran
    gem uninstall win32-api
    gem install win32-api --platform=ruby
    as detailed in the watir fix
  13. Then "ruby google_test.rb" in the cmd and everything worked as intended!

Almost there....


Threw up this little blog to get me started (again) on my slippery blog adventures. First post should be notes about getting selenium 2.0 or selenium + webdriver and ruby to work nicely.