Introduction
This is the tenth article of a series of blog post called the WIMPinator Chronicles that describe how to setup a PHP development environment for Windows 7 and IIS 7.5.
So far we covered how to install a Wordpress blog and all its dependencies using the WPI (Web Platform Installer). Then we installed additional features and extensions to the PHP deployment on Windows for IIS. I explained how to get PEAR setup and how to download and deploy the PHPUnit unit testing framework using PEAR. In the next two posts I described how to install Eclipse PDT and make it work with Subversion source control using Subclipse. I showed how to create an IIS 7.5 Fast CGI web site from scratch and in a more recent tutorial I covered how to use ANT build tasks to deploy your PHP project from Eclipse to your IIS test server using custom build steps. I demonstrated how to use XDebug with PDT and IIS.
This blog post is a follow up on the last article that described how to install and configure the de facto Web UI test automation standard Watir. I am taking the Watir environment to the next level and use Eclipse and the Ruby Development Tools (RDT) to write and run Watir Web UI tests as unit tests.
The Series
- Getting a Wordpress blog installed in a jiffy on Windows 7 using the Web Platform Installer
- Adding additional features to PHP
- Installing PEAR and PHPUnit
- Installing Eclipse PDT
- Configuring Eclipse PDT to work with Subversion source control
- Creating a new IIS 7.5 fast CGI web site
- Configuring Eclipse to work with Ant build tasks
- Setting up XDebug with Eclipse and IIS 7.5
- Configuring Ruby and Watir
- Writing Watir unit tests with Eclipse and RDT
- Moving a Wordpress blog from GoDaddy shared hosting to my local debugging system.
- NEW: Setting up the CodeIgnitor MVC framework with PDT and IIS 7.5
- NEW: Configuring IIS 7.5 Rewrite rules to exclude index.php from the URL
- NEW: Configuring SSL on IIS 7.5
- NEW: Writing unit tests with PHP Unit
References
Here are the links that I used to research the topic of this blog post:
Using the Ruby Development Tools with Eclipse
http://www.ibm.com/developerworks/opensource/library/os-rubyeclipse/
Watir Tutorial:
http://wiki.openqa.org/display/WTR/Tutorial
Unit Test Examples:
http://svn.openqa.org/svn/watir/trunk/watir/unittests/
Installing the Ruby Development Tools for Eclipse
The two prerequisites for this tutorial are to have Eclipse and Watir installed. If you haven’t done this yet, then use the following two tutorials:
Installing Eclipse PDT
Configuring Ruby and Watir
First open Eclipse using the Run as administrator option:
Figure 1: Run Eclipse as Administrator
Note: I am using Eclipse Build id: 20100218-1602 for this tutorial
Figure 2: Eclipse Build id: 20100218-1602
After you launched Eclipse go to the Help->Install New Software.. menu
Figure 3: Open the Install New Software wizard in Eclipse
From the Work with: drop-down box select the “Galileo – http://download.eclipse.orb/releases/galileo” option. This will fill the list view underneath with a list of available software extensions for Eclipse.
Figure 4: Select Work with: Galileo…
Then scroll to the Programming Languages node and expand it.
Figure 5: Expand the Programming Languages
You can also type “ruby” into the filter text box. This will take you straight to correct the Dynamic Languages Toolkit package.
Figure 6: Filter for ruby
Select the Dynamic Languages Toolkit node that is the result of the ruby filter.
Figure 7: Select the Dynamic Languages Toolkit that the ruby filter displays
Click next to get to the Install Details dialog.
Figure 8: Install Details dialog
Click next and pick the “I accept the terms of the license agreement” radio box.
Figure 9: Accept the license agreement
Click Finish to start the download of the Dynamic Languages Toolkit for Ruby package.
Figure 10: The package is downloading
Click on the Checkbox and then OK to trust the package’s certificate.
Figure 11: Trust the certificate
At the end of the installation a message box asks you to automatically restart Eclipse. Say No and restart manually.
Figure 12: Say No and restart Eclipse manually
At this point the Dynamic Language Toolkit for Ruby in Eclipse should be successfully installed.
Configure a Ruby Interpreter for Eclipse
In the next section I am going to describe how to bind Eclipse with the already pre-installed Ruby executable / Interpreter. The quickest for this is to create a new Ruby project. The new project wizard will guide you through the process of hooking up the Ruby runtime.
Go File->New->Project in Eclipse.
Figure 13: File New Project
This will open the New Project’s Select a wizard dialog. Expand the Ruby folder and select the Ruby Project node.
Figure 14: Select the Ruby project wizard
In the Create a Ruby project wizard specify a Project name. In my example I am calling the project WatirTests. Since the default interpreter is currently undefined (see the execution section of the wizard) we need to click on the blue hyperlink that says: Configure interpreters…
Figure 15: Specify project name and then configure an interpreter
In the interpreter Preferences dialog click the Add… button on the right to add a new interpreter.
Figure 16: Add a new interpreter
Next click the Browse… button and navigate to the Ruby\bin folder.
Figure 17: Browse to your ruby.exe file
I installed Ruby under C:\Ruby and therefore I am going to pick C:\ruby\bin\ruby.exe.
Figure 18: Interpreter system libraries get added after the executable has been selected
Next press OK to add the ruby interpreter to the list. and select it.
Figure 19: Press OK to add the new interpreter
Create a Ruby project
At this point we continue to actually create a project. Select the interpreter (See Figure 19) and then click OK.
Figure 20: With the interpreter selected provide a Project name
Click Next to review your choices. Then click Finish.
Figure 21: Review your project choices
The next dialog asks you whether you would like to change your perspective to Ruby.
Figure 22: Change perspective to Ruby
Writing your first Watir unit test
With the new project active go to File->New->Ruby Class menu to create a new *.rb ruby file.
Figure 23: Create new ruby class
The new ruby class will be a unit test class. I call it GoogleTest.
Figure 24: Call the test class GoogleTest
Our GoogleTest unit test class will open a browser, navigate to Google, search for Watir and click on the first search result to get to the Watir home page. Then it will look for a specific string and pass, if the string matches an expected value.
Figure 25: Testing Google with Watir
Copy the following source code snippet into the GoogleTest.rb text editor.
Unit Test for Eclipse
require 'test/unit'
require 'watir'
class GoogleHomePage < Test::Unit::TestCase
def test_there_should_be_text_About_Google
browser = Watir::IE.start "http://www.google.com"
assert(browser.text.include?("About Google"))
end
end
require 'test/unit'
require 'watir
class GoogleHomePage < Test::Unit::TestCase
def test_there_should_be_watir
ie = Watir::IE.new
ie.goto("http://www.google.com")
ie.text_field(:name, "q").set "watir"
ie.button(:name, "btnG").click
ie.link(:href, "http://watir.com/").click
assert(ie.text.include?("Why Watir?"))
end
end
require 'test/unit'
require 'watir'
class GoogleHomePage < Test::Unit::TestCase
def test_there_should_be_watir
ie = Watir::IE.new
ie.goto("http://www.google.com")
ie.text_field(:name, "q").set "watir"
ie.button(:name, "btnG").click
ie.link(:href, "http://watir.com/").click
assert(ie.text.include?("Why Watir?"))
end
end
Executing Ruby unit tests in Eclipse
To execute the unit test just push the Run (green triangle) button in eclipse. Eclipse will ask you whether you want to run this class as Test or as Script. Select Ruby Test and click OK.
Figure 26: Select Ruby Test
And Voila, if everything goes well your first Watir unit test got executed by Eclipse and passed successfully.
Figure 27: Watir unit test passed in Eclipse
Ausblick
At this point, after producing this tutorial, I can’t wait to actually write some Watir scripts. Here are some ideas I would like to work on:
- Submit blog posts to DZone automatically using Watir
- Running load tests using Watir
- Monitor my website response times with Watir
I hope this and the previous tutorial will help you with the development of Watir tests.