Photo from Chile

CFSelenium 1.8 - Improvements to waitFor Methods and Upgrade for Selenium 2.20

A new version of CFSelenium was released today which upgrades the bundled version of Selenium Server to version 2.20.0, and also includes improvements to the waitFor helper methods. Those improvements were contributed by Michael Wilson.

As always, the latest version is available via the CFSelenium RIAForge page and via the CFSelenium GitHub Project.The latter also includes a detailed Readme file which can help you get started using CFSelenium.

Many thanks to Michael for his contribution.

CFSelenium 1.7 - Upgrades for Selenium 2.16 and Firefox 9

A new version of CFSelenium was released today which upgrades the bundled version of Selenium Server to version 2.16.0, and also provides Firefox 9 (and above) compatibility for the bundled Firefox plugin.

As always, the latest version is available via the CFSelenium RIAForge page and via the CFSelenium GitHub Project.The latter also includes a detailed Readme file which can help you get started using CFSelenium.

CFSelenium 1.6 - Upgrades for Selenium 2.2 and Firefox 5

A new version of CFSelenium was recently released which upgrades the bundled version of Selenium Server to version 2.2.0, and also provides Firefox 5 compatibility for the bundled Firefox plugin.

As always, the latest version is available via the CFSelenium RIAForge page and via the CFSelenium GitHub Project. The latter also includes a detailed Readme file which can help you get started using CFSelenium.

CFSelenium 1.5 - With Some Handy Helper Methods

A new version of CFSelenium was recently released which includes a few helper methods that I've found useful. First off, I'd like to thank the fine folks on the Mozilla Web QA team, from whom I borrowed the idea for these methods. I wrote a couple of tests for them in Python, and their Python base page object contains these methods. While I agree that it makes sense to include these methods in a base page object, not everyone using CFSelenium is using the Page Object Model, and as the creator and co-maintainer of CFSelenium I figured I'd just make everyone's life simpler and include them directly in the client library.

The three methods, which are waitForElementPresent, waitForElementVisible, and waitForElementNotVisible, are helpful when testing applications that make use of AJAX, or even just simple JavaScript. When you want to check that a page has responded to a user interaction, and the response is generated by JavaScript, you can often run into timing issues in your Selenium tests. If you issue a click command and then immediately include an assert with a getText command in it, it may be that the element that you are attempting to get hasn't been created by the browser yet. The same can be true when elements are shown or hidden. To address this issue the three methods mentioned above can be used, each of which is described in more detail below.

Arguments

Each of these methods accepts one required and one optional argument. The first argument, locator, is just that; the locator of the element that you want to wait for. The second, optional, argument is timeout, which is a number, in milliseconds, that you want CFSelenium to wait for the element before it throws an exception. The default value for timeout is 30000 (or 30 seconds), and this can be overridden in one of two ways. You can override the default for your entire test case by passing a value into the waitTimeout argument of CFSelenium's init method. You can also override the default on any call to any of these methods by passing a value into the second argument of the methods, which is timeout.

waitFor Methods

In case it isn't completely obvious, here is what the waitFor methods do:

  • waitForElementPresent - Waits for the specified element to be added to the DOM. If the element is not present by the end of the timeout interval an exception is thrown.
  • waitForElementVisible - Waits for the specified element to become visible. If the element is not visible by the end of the timeout interval an exception is thrown. Note that the element must be present in the DOM or the Selenium server will throw an exception immediately.
  • waitForElementNotVisible - Waits for the specified element to become hidden. If the element is still visible by the end of the timeout interval an exception is thrown.

As always, the latest version is available via the CFSelenium RIAForge page and via the CFSelenium GitHub Project. The latter also includes a detailed Readme file which can help you get started using CFSelenium.

CFSelenium 1.4 - Starts and Stops Selenium-RC Java Server For You

A new version of CFSelenium was recently released which includes an enhancement contributed by Marc Esher. In previous versions you had to manually start and stop the Selenium-RC Java server, but in this latest version CFSelenium is smart enough to start it for you, in the background, if it is not already started. You can also shut down the java server by calling the stopServer() method on the selenium.cfc component. This will only stop the Java server if CFSelenium was the one that started it.

Marc also added a base test case for MXUnit which includes code to start and stop the server. The base test case is called CFSeleniumTestCase.cfc and the code to both start the Selenium Java server, and to start a browser session is in the beforeTests() method. There is also code to stop the browser and stop the server in the afterTests() method. This will allow all of your tests to run using the same browser session, which is much faster that starting a new browser session for each individual test.

To create a test case which is based on this new base test case, just extend it and add your own beforeTests() method which sets a variable for the base url for your tests and then calls the beforeTests() method in the parent. It will look something like this:

view plain print about
1component extends="cfselenium.CFSeleniumTestCase" {
2
3    function beforeTests(){
4        // set the base url for your tests
5        browserURL = "http://github.com/";
6        super.beforeTests();
7    }
8
9    function myTest() {
10        // note that the variable selenium is available to you which refers to an instance of CFSelenium
11        selenium.open("/bobsilverberg/CFSelenium");
12        assertEquals("bobsilverberg/CFSelenium - GitHub", selenium.getTitle());
13        selenium.click("link=readme.md");
14        selenium.waitForPageToLoad("30000");
15        assertEquals("readme.md at master from bobsilverberg/cfselenium - github", selenium.getTitle());
16    }
17    
18}

If you want to use a browser other than the default (which is Firefox), you can also specify a value for the variable browserCommand which will control which browser is used.

The latest version is available via the CFSelenium RIAForge page and via the CFSelenium GitHub Project. The latter also includes a detailed Readme file which can help you get started using CFSelenium.

Slides for Introduction to Browser Automation and Testing with Selenium

cf.Objective() 2011 has come and gone, and by all accounts it was an awesome conference. I presented an Introduction to Browser Automation and Testing with Selenium, and I'm making my slides available via this blog post. You can download the PDF here.

The real meat of the session consisted of demos of Selenium-IDE, Selenium-RC and CFSelenium, so I'm not sure that you'll get much from the slides alone. If you're interested in using Selenium via ColdFusion, please visit the CFSelenium project and look over the readme file. It should give you all you need to get started writing your own functional tests with ColdFusion and Selenium.

CFSelenium Now Supports ColdFusion 7 and 8

Just a quick note to let you know that Brian Swartzfager has added support for ColdFusion 7 and 8 to the CFSelenium project by adding a tag-based cfc. This is now included in the latest version (1.2), which can be downloaded from the CFSelenium RIAForge page.

Brian, who will be maintaining the tag-based version, has written up a blog post about this addition to the CFSelenium project.

More Entries