Thursday, March 8, 2007

Selenium IDE - format for CakePHP Selenium helper

This is a companion post to Daniel Hofstetter's (author of cakebaker blog), about cakephp selenium helper.

OpenQA Selenium Core is a testing framework for web applications.
Cakephp is a MVC framework for php.
SeleniumIDE is a firefox extension that allows recording and running of selenium test cases within the browser.

The Cakephp Selenium helper allows writing test cases for selenium in php code, instead of the annoying html table style "selenese". I was using it for a while before I tried out the SeleniumIDE firefox extension. I found out that it had an export capability that created code for different languages like ruby and perl, but no cakephp :(. Luckily writing a new formatter is fairly easy.

Here is the code for an implementation of a cakephp formatter. It's not perfect, and doesn't add a line for creating the testCase name, but that should be pretty easy to add:


/**
* Parse source and update TestCase. Throw an exception if any error occurs.
*
* @param testCase TestCase to update
* @param source The source to parse
*/

function parse(testCase, source) {
}

/**
* Format TestCase and return the source.
*
* @param testCase TestCase to format
* @param name The name of the test case, if any. It may be used to
embed title into the source.
*/

function format(testCase, name) {
var result = '<?php\n';

var commands = testCase.commands;
result += formatCommands(commands);
result += '?>';

return result;
}

/**
* Format an array of commands to the snippet of source.
* Used to copy the source into the clipboard.
*
* @param The array of commands to sort.
*/

function formatCommands(commands) {
var result = '';
for (var i = 0; i < commands.length; i++) {
var command = commands[i];
if (command.type == 'command') {
if (command.value !== "") {
result += '$selenium->' + command.command
+ '(\'' + command.target + '\',\'' + command.value + '\');\n';
}
else {
result += '$selenium->' + command.command
+
'(\'' + command.target + '\');\n';
}
}
}

return result;
}

/*
* Optional: The customizable option that can be used in
format/parse functions.
*/

//options = {nameOfTheOption: 'The Default Value'}

/*
* Optional: XUL XML String for the UI of the options dialog
*/

//configForm = '<textbox id="options_nameOfTheOption"/>'


To add a formatter to SeleniumIDE follow the following tutorial:

1. Open the SeleniumIDE extension, and choose options in the menu


2. Click the "add" button


3. Paste the code presented above in the textarea


4. Record your test, and then you can choose "File/Export Test As/cakephp"


And something like


$selenium->open('/');
$selenium->clickAndWait('link=test problem');
$selenium->clickAndWait('img_avatar');
$selenium->clickAndWait('sign_in');
$selenium->type('UserUsername','bla');
$selenium->type('PasswordPassword','bla');
$selenium->click('rememberme');
$selenium->clickAndWait('submit');
?>


is generated.

If you would like to open an existing cakephp test in SeleniumIDE, you don't need to write a parser, just "open" the url for your test, for example "http://localhost/pages/tests/test1" and your testcase will generate the table that is parsed by SeleniumIDE, you can make your changes, and export it back to cakephp.



Tags: ,

21 comments:

סולי וישקאוצן said...

Cakebaker just posted a formatter for his new selenium test suite http://cakebaker.42dh.com/2007/03/11/formats-for-the-selenium-ide/.

butlimous said...
This comment has been removed by a blog administrator.
סולי וישקאוצן said...

I am aware of some bugs in the IDE formatter. Anyone who wishes to pick this up and fix it is welcome to contact me for help. Currently our team is not working with cake so much so I don't use it. I wonder why Selenium Core hasn't picked up. I want to check Selenium RC, to see if it's more programmer friendly. It's also quite easy to convert the CakePHP selenium helper to work with basic PHP, so we already used the formatter in a non CakePHP project as well.

Anonymous said...

female viagra
viagra for women

jorge said...

منتديات ستار تايمز, الجزيرة الرياضية, مباريات اليوم, abu dhabi sport

Blogger.jinbo said...

chi flat iron . we have best price and free shipping.Welcome to wholesale chi flat iron at http://www.chiflatiron.us/.

men's clothing said...

I feel honored and privileged after reading your posts.You know,summer is coming!
Chaussures Homme Nike,Chaussures Homme pas cher.fashionable homme chaussure,Best wishes to you!
Acheter Chaussures Homme in our shop

rootpp said...

milf videos
Thanks for such a great post and the review, I am totally impressed! Keep stuff like this coming.

huang said...

Reliable and Professional China USB Flash Disk manufacturing

company, they have all types of USB Flash Disk, Logo USB,
Custom USB, as well as the newest and best USB Flash Disk,
plastic usb drive,
rubber usb drive,
metal usb drive,
leather usb drive,
metal usb drive,
fingerprint usb drive,
card usb drive,
swivel usb drive,
wooden usb drive,

nancy2 said...

Wow, that sounds fantastic. The figs and cheese sound especially good. I will definitely check this out.
youxizhe

Unknown said...

which averages to about 7,353 watches per year.
http://www.watchestoo.com
replica watches
Men’s watches
Fake watches
ROLEX
rolex oyster perpetual datejust watch
rolex oyster perpetual datejust replica watch
rolex oyster perpetual datejust
rolex ladies datejust
rolex 116200
rolex 18k
rolex stainless
BREITLING
TAG HEUER
CARTIER
OMEGA
IWC
u boat
iw500112
IW376705

artrepro said...

buy cheap oil paintings
abstract oil paintings
impressionist oil paintings
landscape oil paintings
still life oil paintings
flowers oil paintings
religious oil paintings
realistic oil paintings

walkintub said...

That is some inspirational stuff. Never knew that opinions could be this varied. Thanks for all the enthusiasm to offer such

helpful information here.
I bookmarked it into my facebook and digg and share the good stuff with my friends too,Keep up work.Is there more aspect

about this subject?I am looking forward to seeing it.

walk in tub|
walk in tubs|
walk in baths|
walk in bathtubs

Unknown said...

that's good thanks for sharing
one tree hill season 7 on dvd
the big bang theory dvd
cold case dvd box set
true blood season 3 dvd
burn notice dvd
bones dvd
doctor who dvd
ncis seasons 1-7
that 70s show dvd box set
the golden girls dvd

gethqnet said...

pc games
Thanks for such a great post and the review, I am totally impressed! Keep stuff like this coming.

gethqnet said...

Perfect post. Thanks!
big boobs

Unknown said...

These ugg australia are incredibly comfortable
as the sheepskin is providing excellent insulation against the cold but also absorbs excessive
moisture while letting your feet breath. To get the best fit in our ugg bailey button
it is best to measure your bare foot. To do this measure your ugg boots
from heel to longest toe.

Unknown said...

Both sides also collectively released a 3 festivities to commemorate the tenth anniversary of cooperation
Nike Air Max Shoes
Nike Air Max 2011
Nike Air Max
Nike Air Max 2009
Nike Air Max 95
Nike Air Max 91
Nike Air Max 87
Nike Air Max 180
Nike Air Max Griffey Max 1
Nike Air Max 90
Nike Air Max 1
Nike Air Max Wildwood Supreme
Nike Air Max Turbulence
Nike Air Max Skyline
Nike Air Max Goadome
Nike Air Max Fitsole
Nike Air Max Zenyth
Nike Air Max Boots
Nike Air Max Zoom Kobe
Nike Air Max Tn
Nike Air Max LTD
Nike Air Max Presto
Nike Air Max BW
Nike Air Max 24 7
Nike Air Max 2010
Nike Air Max 2011
Abercrombie and Fitch London
Abercrombie & Fitch Clothes
Vibram Shoes
Cheap Air Max
Nike Air Max Shoes
I saw peach falling from the window in your house. Walking really happy, to ensure that all of the uncomfortable into simple

silence. I'm the only person who heard one's heart beat.

Paul Simmon said...

This really is a terrific web site, could you be interested in performing an interview about just how you produced it? If so e-mail me!
http://www.oilpaintingsgallery.net/

Paul Simmon said...

Welcome to my Cheap oil painting!

Luke said...

Yumm. Cake...female conservative