Skip to content

Ortus-Solutions/CFSelenium

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

96 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CFSelenium - A Native CFML (ColdFusion) Client Library for Selenium-RC

This project was forked from Bob Silverberg's project: http://github.com/bobsilverberg/CFSelenium

What is CFSelenium?

CFSelenium is a ColdFusion Component (CFC) which provides a native client library for Selenium-RC. This allows you to write tests, using CFML, which will drive a browser and verify results via Selenium-RC.

Requirements

  1. ColdFusion 10+ or Lucee 4.5+
  2. The Selenium-RC Server jar, the latest version of which is included in the distribution
  3. TestBox for Behavior Driven Development and contributing to our test suite.

Support

Installation

CFSelenium can be installed via CommandBox by typing:

box install cfselenium

This will create the following structure under a cfselenium folder:

  • formats : Browser Extensions
  • Selenium-RC : The Selenium Standalone Java Server
  • BaseSpec.cfc : The TestBox base specification to use for Selenium driven specs
  • Selenium.cfc : This nice project CFC
  • Server.cfc : The driver CFC for the embedded server

Note: Optionally if you would like to integrate with TestBox you will have to create a mapping to the cfselenium installed folder as /cfselenium.

Contributing

If you want to contribute to this project, please make sure you clone it from here: https://github.com/Ortus-Solutions/CFSelenium/. You will need CommandBox in order to do development, so once installed and cloned, just type:

box install && box server start

In the root of the clone and all the required dependencies will be installed and you can contribute to the project. An embedded server will also be started so you can execute the tests and develop.

Usage

Optionally, start the Selenium-RC server. Selenium.cfc will automatically start the Selenium-RC server for you in the background if it isn't already started. To start it manually, the command is similar to this:

java -jar selenium-server-standalone-2.46.0.jar

Create an instance of selenium.cfc.

selenium = new Selenium();

You can also pass the host and port into the constructor, which default to localhost and 4444:

selenium = new Selenium( "localhost", 4444 );

To start up a browser, call selenium.start() passing in the starting URL and, optionally, a browser command telling it which browser to start (the default is *firefox):

selenium.start( "http://github.com/" );

To start a different browser (e.g., Google Chrome), pass in the browser command too:

selenium.start( "http://github.com/", "*googlechrome" );

Call methods on the selenium object to drive the browser and check values. Most likely you will be using TestBox for driving expectations on these values:

// all your suites go here.
describe( "CFSelenium", function(){

    it( "can open an external readme", function(){
        selenium.open("/Ortus-Solutions/CFSelenium");

        expect( selenium.getTitle() ).toInclude( "CFSelenium" );
    });

    it( "can navigate and verify", function(){
        selenium.click( "link=readme.md" );
        selenium.waitForPageToLoad( "30000" );          
        sleep( 1000 );

        expect( selenium.getTitle() ).toInclude( "readme.md" );

        selenium.click( "raw-url" );
        selenium.waitForPageToLoad( "30000" );

        expect( selenium.getTitle() ).toBeEmpty();
        expect( selenium.isTextPresent("[CFSelenium]") ).toBeTrue();

    });

});

You can shut down the browser using the `stop()`` method:

selenium.stop();

TestBox Integration

CFSelenium integrates with TestBox via the BaseSpec.cfc that can be found in the root of the project. Every Spec that you create in which you want to enable CFSelenium for will inherit from this spec, which in turn inherits from the TestBox BaseSpec as well.

component extends="cfselenium.BaseSpec"{}

Then you will have access to our life-cycle methods of beforeAll and afterAll. The beforeAll() method takes in two arguments in order to setup the Selenium connection. The afterAll() method can be omitted in your concrete spec and it stops the Selenium connection.

BeforeAll()

/**
* Please note the two arguments to get a selenium server started
* @browserURL The base URL of the application to test.
* @browser The browser to run the tests, defaults to *firefox
*/
function beforeAll( required browserURL, browser="*firefox" ){}

You can then use it in your specs:

/**
* Readme Spec
*/
component extends="cfselenium.BaseSpec"{
    
/*********************************** LIFE CYCLE Methods ***********************************/

    // executes before all suites+specs in the run() method
    function beforeAll(){
        super.beforeAll( "http://github.com/", "*firefox" );
    }

}

A Selenium-IDE Formatter Too

Also included in the distribution is a Firefox extension which will add a formatter to Selenium-IDE which will allow you to export tests in CFSelenium / MXUnit format. The plugin can be found in the formats folder.

About

A native Selenium RC binding for ColdFusion

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • ColdFusion 90.7%
  • JavaScript 8.2%
  • HTML 1.1%