Software: January 2010 Archives

There are many easy to use testing automation tools on the market.  There are many powerful testing automation tools on the market.  There are, however, rather few that are both.  Selenium is one that stands out, though and it is the tool that I most often use.  In this tutorial, I'll demonstrate a quick way to create simple tests using the tool.

 

In order to play back your tests, simply press the green arrow "play buttons" on the toolbar.

WHAT???  Why did my tests fail??

Well, your tests probably failed here, but that's ok.  This really demonstrates the speed of Selenium.  Your test most likely failed because Selenium tried to move on to the next step before the web page finished rendering.  So it tried to click on your next link before the link was actually on the page.  There are two ways to handle this.  The quick but bad way would be to adjust the speed of your test by adjusting the slider on the toolbar.  This would allow the web pages a chance to render prior to Selenium trying to act on it.  The better way to handle this would be to change the "click" commands to "ClickAndWait" commands, though.  This way, Selenium will wait for the page to completely render before moving on to the next command.  One thing to note about this method, however, if you are testing a page that has frames, you might run into problems with FireFox.  FireFox says the page is completed once the Frameset is complete rather than waiting for the contents of the frame have completely rendered.

Also before I sign off for this first tutorial, I'll mention the difference between Assert and Verify

When you ASSERT that an element is present, you are telling Selenium to stop the test and proceed no further if the assertion is not valid.  So, if I assert that an image is present and that image is NOT present, Selenium will not move on and all testing will stop.  The test will be marked a failure.

When you verify something is present, you are looking for something that is not terribly important enough to stop the entire test if it's not.

An example of when I might use assert versus using a verify:

If I loaded a web page displayed a render time, I might want to verify that the render time was under 5 seconds, but I wouldn't necessarily think that it's a total failure if it took 6 seconds to render.  I would want to use an assert to verify that it didn't take longer than 10 seconds because 10 seconds is way past my threshold for acceptable render times and there is no point in continuing my tests if it takes longer than that.

 

Stay tuned for the next session: "Creating Tests Suites"

 

 

The Tao of Calvin