Dan Fabulich wrote on 11/30/2005 05:27:28 PM:
> One of the side projects I've been working on this week is to try using 
> JsUnit as a runner for Selenium tests, instead of HTML-table Selenese. 
> This would make it easier to write complicated tests with conditionals, 
> loops, etc..

Nice... JavaScript syntax for Selenium tests has been on my wish list for 
a while.

> (I can't be the first person to have thought of this...?  Didn't 
Selenium 
> at one time depend on JsUnit?)

Selenium tests itself with table-style functional tests and comes with 
JsUnit unit tests for the core Selenium code. Selenium used to depend on 
JsUnit for its library of assert commands, but later on we decided to nix 
that dependency and use our own API.

Before Selenium was created, I gave a look at JsUnit before deciding to 
write my own tool.  A few things kept me from just sticking with JsUnit. 
The biggest reason is that JsUnit looked like it could easily handle the 
testing of single, discreet web pages... But it couldn't handle (and is 
not meant to handle) the transitions between pages (e.g.: enter data in a 
form, click a button, wait for new page, then proceed with the next 
command)-- aka "login to logout" style tests. Also, the JsUnit docs say 
that you could make the hidden iframe visible (like Selenium does)-- but 
only in IE. And I like the "stepping debugger" aspect of Selenium's 
interface for slowly stepping through tests to find out where and how a 
test failed. I didn't see how to easily do that with JsUnit. Lastly, at 
the time, I was enamored with Ward's FIT Framework, and its promise of 
"tests that people can read". Once I realized that JsUnit wasn't really 
meant for my idea of functional testing, Selenium started out as an 
experiment to implement FIT in JavaScript in the browser. FIT/tables-style 
Selenium is not going away, but I've since come around to supporting the 
idea of using plain old JavaScript syntax for tests when you need to do 
more complicated stuff than simple procedural commands (conditionals, 
loops, function definitions, etc.) In this case, I'd like to move to API 
similar to Watir's, but written in JavaScript. Anyway... there are lots of 
good ideas to borrow from in each project.


> Anyway, it turns out to be pretty easy to use Selenium in a JsUnit 
> context.  JsUnit's TestRunner.html defines a handy invisible iframe 
that's 
> pretty analogous to SeleniumRunner.html's "imyframe".  You access it 
like 
> this:
> 
(snip, snip)
> The main tricky part turns out to be waiting for events. 
(snip, snip)
> Many people have remarked about this as a weakness in JsUnit for testing 

> asynchronous events. 

This is an area that we do have working in Selenium. Although there is a 
proposal from Bret Pettichord to change or improve how we do it in 
Selenium. 
Getting the browser to wait is damn tricky business. Read these two posts 
from some "color commentary" on the subject.
http://www.josephmoore.net/2005/11/non-cpu-intensive-javascript-wait-loop.html
http://www.josephmoore.net/2005/11/using-seleniums-waitforvalue.html

> I've found a reasonable kludge for this, which I've 
> posted to the JsUnit mailing list (free subscription required): 
> http://groups.yahoo.com/group/jsunit/message/460

Yes, requiring a Java applet or ActiveX control to implement a wait 
command is very kludgey. :-)

> Putting the two together, you can use Selenium and the BrowserBot very 
> effectively in pure JsUnit tests to write your tests in pure JavaScript.

Because of the timing/event issues... I'm thinking it might be easier to 
run pure JavaScript tests in Selenium's TestRunner test harness than 
running Selenium tests in JsUnit's TestRunner. I think the way forward 
with this is to replace Selenium's parsing of a Selenium table with a 
simple "eval" of a pure JavaScript test and see what happens.
 
> Is this helpful to anyone?  Am I the only one who prefers writing tests 
in 
> JavaScript rather than HTML-table Selenese?

Yes, this is helpful (to me at least)... And I know for sure you're not 
the only one who'd like to write their Selenium tests in pure JavaScript.

-Jason
_______________________________________________
Selenium-users mailing list
Selenium-users@lists.public.thoughtworks.org
http://lists.public.thoughtworks.org/mailman/listinfo/selenium-users

Reply via email to