Using the Power of OOP with Selenium

| | TrackBacks (0)

If you have the luxury of using an object oriented programming language for testing your web application, there are a few small principles that you might want to keep in mind when coding your tests.

  1. Don’t test a “Page.” Keep your classes and objects as small as possible.
    Do you allow someone to search for things on your website?
      Then have a class/object that thoroughly tests your search.
    Do you have a coupon that shows up  based on the geo-location of a user’s IP address?  Write a class for that.
    Once you have your classes written for each the parts of a page you want to test, create a test file that instantiates those objects and tests them in the integrated format of the webpage.
  2. Have your test do as little work as possible.
  3. Keep the massive work in small functions that are publicly available for the object you are testing.

Do your work in a public method/function:

   1:      public boolean isPartnerLogoPresent() {
   2:          TestTools.debug(DEBUGLEVEL, "isPartnerLogoPresent()");
   3:          if (sel.isElementPresent(partnerLogoId)) {
   4:              TestTools.debug(DEBUGLEVEL, "\tFound the partner logo\n");
   5:              return true;
   6:          } else {
   7:              TestTools.debug(DEBUGLEVEL, "\tCould NOT find the partner logo\n");
   8:              return false;
   9:          }
  10:      }

Have your test call that function:

   1:      @Test
   2:      private void testPartnerLogoPresent() {
   3:          // verify that the Partner Logo is available
   4:          assertTrue(isPartnerLogoPresent());
   5:      }

 

On the surface, this might look as if you are doing a lot of extra typing and extra work, but if you have this partner logo show up on more than one page, all you have to do to verify it there is call this function.

 

0 TrackBacks

Listed below are links to blogs that reference this entry: Using the Power of OOP with Selenium.

TrackBack URL for this entry: http://www.estevenjones.com/cgi-bin/mt/mt-tb.cgi/48

 

 

The Tao of Calvin