Photo from Chile

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.

TweetBacks
Comments