Thursday, February 11, 2010

Importance of pre-production like environment

Pre-production environment plays pivotal role in defining test completion criteria. System Performance and System Readiness testing rely on a stable system like Production - called Pre-prod environment. These tests are final preparation for the new system and will dictate whether the Production environment is ready for actual production processing.  In terms of completion criteria, both phases are all or nothing.  This means, in both phases, tests either pass or fail as a whole based on pre-determined criteria from Business Users, Legacy Owners, and Process Owners.  

The precautions an organization should take place:
  • Entire infrastructure or architecture should be as close as production
  • Various kinds of testing to be preformed
  • Accounts to be used against these enviornments
  • Revenue impacts
  • Automated testing if any, which test scenarios to be executed


Since these environment is very close to real production environment, tons of weired behavior of application or product can be detected early on in release cycle in help avoiding last minutes or production emergencies.

However, one should not perform entire testing on these environments. Say a day or 2 days execution of various tests is good enough!

Monday, February 1, 2010

Dependency Injection in Ruby

I had an opportunity to use DI in one of my past company projects. Since I have made a switch to Ruby at work, just wanted explore DI in ruby world.

Before that I should mention that Ruby is focus on simplicity and productivity. Syntax in ruby is elegant and easy to read/write.

Initially I was under impression that DI equals Spring, but that's not entirely true. In simple terms, DI contributes to mitigate the proliferation of dependencies. A good example is use of factory class is most common way to implement DI.

In ruby, DI concepts to creation of objects and wiring them...
Example: TBAdded later...

Thursday, December 17, 2009

A day without work notebook or laptop :-)

How would a day be without a notebook or laptop :-) My machine froze on me this morning, driver just died and now it just not coming up!! waiting to get a replacement. while waiting on machine, thinking how could be a day with no laptop or notebook ???

Friday, November 13, 2009

Domain Based Testing

Domain Based Testing:  Usually carried out based on two concepts - domain analysis and domain modelling. Its intent is to focus on test rather than the action of the test.
It wraps browser object into page object that provides API that returns the Html element object based on what you can do at the current page.
For ex:

login_page = LoginPage.new(@browser)
login_page.username.type('username')
login_page.password.type('password')
login_page.logon_button.click

It does require designing, implementing page, most common actions, verifications on page and Html elements. But it does pay off. With shared page classes, each tests only need to write code that is specific about that test case. This makes it easy to understand and maintain. Also, it provides an ease to find the code and change it when the element id or name changes.

Tuesday, October 20, 2009

Clearing IE cache and cookies before running Selenium tests

When using FireFox, it is quite easy to setup a profile to be used with your Selenium tests. FireFox allows configuration which can delete all cookies and cached files when shutting down. Internet Explorer neither allows a profile like FireFox nor deletes cookies and cache unless you delete them by using the Tools –> Internet Options menu.

Deleting cache and cookies might be required for some web applications when testing via Selenium. Here is a easy way to incorporate documented Windows calls to delete cache and cookies via Ruby.

The following script uses the system function to get access to the Windows command prompt. Run the following ruby script on a Windows based ruby installation to clear all cookies and cached files.

#This script is meant for Ruby on Windows only for
#clearing all cache and cookies in Internet Explorer.
#Run this script from the command prompt like this
#C:\Ruby>ruby clear-ie-cache-cookies.rb

#To clear IE7 temporary Internet files
system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8')

#To clear IE7 browsing cookies
system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2')

#To clear IE7 browsing history
system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1')

#To clear IE7 form data
system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16')

#To clear IE7 remembered passwords for filling web login forms
system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32')

#To clear or delete all IE7 browsing history – all of the above!
system('RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255')

Wednesday, October 7, 2009

Running Selenium tests written in Ruby on Windows

Here is a follow-up to my earlier post about installing and using Ruby and Selenium on Windows.

Recording a Selenium test using Selenium IDE for FireFox.

I used the Selenium IDE add-on with FireFox to record a quick example test in Ruby. I visited the Yahoo homepage and typed a search for Selenium RC. Here is the code in Ruby

require "selenium"
require "test/unit"

class SeleniumRubyWindowsTest < Test::Unit::TestCase
def setup
@verification_errors = []
if $selenium
@selenium = $selenium
else
@selenium = Selenium::SeleniumDriver.new("localhost", 4444, "*chrome", "http://www.yahoo.com/", 10000);
@selenium.start
end
@selenium.set_context("SeleniumRubyWindowsTest")
end

def teardown
@selenium.stop unless $selenium
assert_equal [], @verification_errors
end

def test_SeleniumRubyWindowsTest
@selenium.open "/"
assert_equal "Yahoo!", @selenium.get_title
@selenium.type "p_13838465-p", "Selenium RC"
@selenium.click "search-submit"
@selenium.wait_for_page_to_load "30000"
assert_equal "Selenium RC - Yahoo! Search Results", @selenium.get_title
end
end


Save this file as SeleniumRubyWindowsTest.rb


Now that a test is ready to be run, its time to start up the Selenium server.



Running the Selenium server


If you have followed the earlier post about installing Ruby, then you open a command window and go to the directory where you copied the selenium jars. In short go to the directory where Ruby Gems are installed -

<GEM_INSTALL_DIR>\Selenium-1.1.16\lib\selenium\openqa


In this location, using the Java JRE installed in your system, start the Selenium server like this


<GEM_INSTALL_DIR>\Selenium-1.1.16\lib\selenium\openqa java –jar selenium-server.jar


See the screen shot


clip_image002


Now your Selenium Server should start running at the default port of 4444. See screen shot.



clip_image002[5]



Running your first Selenium test written in Ruby

The Selenium test has already been recorded using the Seleniun IDE add-on for FireFox - SeleniumRubyWindowsTest.rb



  • Ensure that your Selenium server is still running

  • Run this test by going to C:\Ruby and typing the following command

  • C:\Ruby>ruby SeleniumRubyWindowsTest.rb

  • Selenium RC window should launch in Internet Explorer

  • A separate FireFox window should launch and show the web pages as per the test SeleniumRubyWindowsTest.rb



Running tests in Internet Explorer on Windows XP and Windows Vista

I have tried the above test using Internet Explorer 7 on Windows XP as well as Internet Explorer 8 on Windows Vista. There were no problems in running the test on IE7 with Win XP. Offcourse you must turn off your popup blocker before running tests. Extra steps are required to run on Windows Vista, as described in the next pargraph.



Code change required to make the example test run in IE is as simple as changing the following line



@selenium = Selenium::SeleniumDriver.new("localhost", 4444, "*chrome", http://www.yahoo.com/, 10000); 

to


@selenium = Selenium::SeleniumDriver.new("localhost", 4444, "*iexplore", http://www.yahoo.com/, 10000); 


Steps to run the same test on Windows Vista and IE8

However, you need to take a few more steps to run the tests without any problems on Windows Vista and IE8.



  • Create a Desktop shortcut for running the Selenium Server.

  • Start the Selenium server by right clicking the shortcut, and then selecting Run as Administrator option

  • Once server starts running, you can use the same steps as described above for running your test from the command line.


One more tip – IE8 has a popup blocker turned on by default. Turn it off before you start running your tests.



Thats all there is to using Ruby and Selenium on your Windows machine! Happy testing :)

Installing Ruby and Selenium on Windows

Though Ruby is primarily used on *nix and Mac OS X, I wanted to run it on Windows. So I went about setting up a ruby instance on Windows with the aim of writing web application tests using Selenium.

Aim: To set up Ruby and Selenium on Windows to be able to run Selenium based tests against a web application

There is a lot of information out there, but its in bits and pieces for Windows. So here is an attempt to make this a one stop resource for setting up Ruby and Selenium on Windows.

Pre-requisites:

Since Selenium server needs to be started from the provided jar, you will need to have a JRE on your Windows machine.

Getting and installing Ruby on Windows:
  • Go to the following site http://rubyforge.org/frs/?group_id=167

  • Download the latest Ruby Installer for windows. Example - ruby186-27_rc2.exe

  • Run this file to install Ruby.

  • When installing you will get to see options that need to be installed. Ensure that you select ‘Enable RubyGems’ to be installed. See screen shot. Click Next.

clip_image002
  • Install Ruby in a top level directory like C:\Ruby as per screen shot. Click Next.

clip_image002[5]

  • Accept defaults on rest of the screens and complete the installation.

Installing the Ruby Selenium Gem on Windows
  • Go to the following site http://selenium.rubyforge.org/

  • Navigate to the Downloads section (http://selenium.rubyforge.org/download.html) or go to the latest builds here http://selenium.rubyforge.org/builds/ and download the latest version.

    Example – Selenium-1.1.16.gem

  • Save this file to the “C:\Ruby” directory where you installed Ruby for Windows

  • Now start a command prompt and go to C:\Ruby

  • Type the command C:\Ruby>gem install Selenium

  • Wait for the Selenium gem to be installed.

  • Note that Selenium should be with uppercase S and not lowercase s. See screen shot.

clip_image002[7]

Installing Selenium Remote Control for Windows

Selenium Remote Control (RC) is required so that the Selenium Jetty Server can start running and then tests written in Ruby can be run against the web application under test using Selenium Ruby Client driver.

Tests can be executed against any Windows browser like Internet Explorer and FireFox.

  • Go to the following site and download the latest Selenium RC driver http://seleniumhq.org/download/

  • Example – Selenium RC 1.0.1

  • Extract this zip file

  • Copy only the following two folders to the C:\Ruby folder. Refer screen shot.

      1. selenium-server-1.0.1

      2. selenium-ruby-client-driver-1.0.1

    clip_image002[9]

    • Now go to the folder C:\Ruby\selenium-server-1.0.1

    • Copy the selenium-server.jar file from here to the following location

      C:\Ruby\lib\ruby\gems\1.8\gems\Selenium-1.1.16\lib\selenium\openqa

    • In short locate the directory where Ruby Gems are installed <GEM_INSTALL_DIR>\Selenium-1.1.16\lib\selenium\openqa

    You are done with all installations! Now the next step is to run the Selenium RC via the Jetty Server bundled with Selenium. I will post about this later on.