After another unfortunate accident at sdn, I had a strong desire to have at least a couple of simple tests to check that the sites are online and people can log in. With so many infrastructure changes it would hopefully help to reduce human element errors. Having the dense day schedule, it had to became a 'Thursday Night' project (thursay because I though of it at thursday and coudn't sleep until I try it)
Thanks to
Scott Hanselman's blog,
WATIR was the first thing that popped into my mind. WATIR stands for Web Application Testing in Ruby, and Ruby is being praised by its followers for elegance and joy most of all.
Cutting the long story short (it's actually a short story thanks to ruby) it worked out pretty well, and in a few hours I had tests that would check that
1. The homepage can be loaded and doesn't redirect anywhere else
2. It is possible to log in
WATIR uses Internet Explorer automation, so it will only work with IE available. Obviously it's not the tool of choice to have thorough UI tests, ensuring that everything works as it should in all browsers. However in my case, I think it does a great job with minimum effort.
[
ruby source code]
Assuming that you have Ruby and Watir installed, you need to unzip it somewhere and start either cocrete tests (sdn5.rb, sdn4.rb..) or a complete suite (sdnSuite.rb). Double click the file and you should see IE window having its own life. Here's how the sdn5 test case looks like:
require 'Watir'
require 'SdnBase'
require 'test/unit'
class Sdn5 < SdnBase
def setup
super
@homepage = "http://sdn5.sitecore.net/"
end
def test_homepage
assert_homepage(/welcome/i)
end
def test_login
go_homepage
@browser.text_field(:id, /username/i).set(@username)
@browser.text_field(:id, /password/i).set(@password)
@browser.button(:name, /loginbutton/i).click
assert(@browser.contains_text(/welcome ar@sitecore.net/i), "failed to log in")
end
endNote that login tests will fail because I've removed my password in SdnBase.
Here's what will get you started:
1. Install Ruby for Windows. The simpliest way is
Ruby one click installer 2. Install WATIR [http://wtr.rubyforge.org/]. Again, there's a
windows installer available3. Read
WATIR user guide for starting steps
4. A great companion to WATIR would be either Firefox DOM explorer or
IE web developer toolbar[5]. If you want to get serious, Scott Hanselman has an
NUnit-Watir integration guideAnother interesting thing to look at is
Selenium:
"
Selenium uses JavaScript and Iframes to embed a test automation engine in your browser. This technique should work with any JavaScript-enabled browser."
It supports xpath to access DOM elements, which is nice and familiar to Sitecore developers. I think it might even be reasonable to make Sitecore shell tests with something like that. It would definitely involve a combined effort, but might be worth looking at.