Jun 10
2011
The easiest way to create a CFSelenium test case is to use the
Selenium IDE plugin for Firefox to compose the test, then export the
test using the export formatter Bob Silverberg included in the
CFSelenium.ᅠ You end up with a test that can be run the test against
Firefox but can be further customized to your needs.
Of course the
beauty of CFSelenium is that it lets you run those tests against
browsers other than Firefox, to conduct cross-browser testing.ᅠ But who
wants to create multiple copies of the original tests, or edit the test
files whenever you want to check them against another browser?
Not this guy.
Read more...
May 24
2011
In my earlier blog post on how to install and run CFSelenium, my steps included directions on copying the .jar file for the Selenium-RC/Selenium Server application to an easily accessible location and then starting your CFSelenium testing session by executing that .jar file from the command line.
I'm happy to report that anyone using CFSelenium in conjunction with ColdFusion 8 or 9 can skip those particular steps.ᅠ Marc Esher (of MXUnit fame) recently contributed code to the CFSelenium project that enables CFSelenium to start the Selenium Server (if it's not already running) anytime you run a test, and stops the server once the test is complete.ᅠ This code is now part of the latest version of CFSelenium that can be download via the CFSelenium GitHub page.
Unfortunately, when I revised the tag-based, CF 7/8-friendly versions of the CFSelenium files to incorporate Marc's code and ran it against CF 7, I found that CF 7 apparently could not start and stop the Selenium Server via the new code.ᅠ So ColdFusion 7 users will still have to start Selenium Server from the command line, but otherwise CFSelenium still works in CF 7.
Apr 3
2011
When you use Selenium IDE to play back the actions you've recorded on a web page (the clicks, the text input, etc.), you can control the waiting period between the execution of each command using the slider control on the left end of the tool bar:

With CFSelenium, the way that you control the time period between executions is with the setSpeed(string milliseconds) function.ᅠ Once you set the execution speed with this function, the time period between executions will remain set at that length until you use setSpeed again.ᅠ So you could set the speed once within the setUp() function of your MXUnit test case...
public void function setUp() {
browserUrl = "http://local.test";
selenium = new CFSelenium.selenium(browserUrl, "localhost", 4444, "*firefox");
selenium.start();
selenium.setTimeout(30000);
selenium.setSpeed("1000");
}
ᅠ
...or you could alter the speed within a test case function...
public void function testFormValidation() {
selenium.open("blah/index.cfm?event=addEditUser&userId=12");
selenium.setSpeed("3000");
//Now Selenium will wait 3 seconds between each of the following command statements
selenium.type("firstName", "John");
selenium.type("lastName", "White");
//Setting the speed back down to 1 second
selenium.setSpeed("1000");
....
}
ᅠ
Knowing how to change the speed in CFSelenium is crucial if you're testing any sort of operation that might take a second or two to update the page, like an AJAX call that populates a drop-down box:ᅠ if the next command in your test requires that drop-down box to be populated, but CFSelenium tries to run that command before the AJAX call completes, either your test will fail or you'll get an error message from Selenium.ᅠ The setSpeed function lets you slow down the execution speed so your AJAX calls have time to do their work before the next step in the test.
Mar 27
2011
In addition to doing browser behavior testing, there are four functions in CFSelenium that you can use to capture screenshots.ᅠ The first two are:
captureScreenshotToString(): captures a shot of your current monitor display in .png format and returns the image data as a base-64 encoded string. **
captureScreenshot(string filename): captures a shot of
your current monitor display in .png format and writes the image data to
the filename passed in as the argument.ᅠ The filename parameter must be
a full path ending in a filename, like
"C:\Data\Screenshots\screenshot1.png." **
ᅠ
**These two functions work for all supported browsers, but because
they take an image of the entire monitor screen, the browser window
launched by *CFSelenium may be obscured by other windows on your
monitor, and sometimes CFSelenium (or more specifically the Selenium
Server) places the browser window in the lower half of the monitor,
cutting off the view of the lower half of the window.
The other two screenshot functions capture only an image of the web
page in the browser launched by CFSelenium, and they capture that page in its entirety:
even if the page is long enough to scroll for several screens, all of
that content will be captured.ᅠ While that can make for some very
elongated
images, it does capture all parts of the page.ᅠ But unlike the first two
functions, these can only be used with certain browsers:
Read more...
Mar 27
2011
When using CFSelenium
to send Selenium commands to the Selenium Server, you start off by
instantiating CFSelenium as an object.ᅠ If you're using the ColdFusion 9
version, you would instantiate it with a statement like this:
browserUrl= "http://www.cnn.com";
selenium = new CFSelenium.selenium(browserUrl);
ᅠ
If you're using the ColdFusion 7 or 8 version, you might instantiate it like so:
<cfset var browserUrl= "http://www.cnn.com" />
<cfset variables.selenium= CreateObject("component","CFSelenium.selenium_tags").init(browserUrl) />
ᅠ
In both cases, you're calling the init() function of the respective
CFSelenium .cfc file. The init() function can take 4 arguments:
-
browserURL: (required) the URL of the website (just the
address to the webroot, not to any subfolders) you want to run the
Selenium commands against.
-
host: (optional) the IP address or hostname of the machine
running the Selenium Server instance CFSelenium will be communicating
with. The default value is "localhost"
-
port: (optional) the port number used to communicate with the Selenium Server instance. The default is 4444.
-
browserStartCommand: (optional) a string that tells Selenium
which web browser on the machine running the Selenium Server instance to
use. The default value is "*firefox"
By default, CFSelenium uses Firefox to conduct the browser tests
(which makes sense because most of the time you'll use the Selenium IDE
Firefox plugin to create your tests). In order to have CFSelenium run a
test case through a different browser, you'll have to pass a different
browserStartCommand string into the init() function.ᅠ You can see a list
of the different browserStartCommand strings in this post on
StackOveflow:ᅠ http://stackoverflow.com/questions/2569977/list-of-selenium-rc-browser-launchers.
Sometimes it's just that simple, but sometimes it's not...and when
it's not, it can be a real pain to figure out.ᅠ WIth some trial and
error, I was able to get Selenium Server/CFSelenium to interact with all
of the browsers I had installed on my Windows and Macintosh laptops.ᅠ
Here's what I had to do it each case:
Read more...
Recent Comments