Setup DOM to test on

1 view
Skip to first unread message

Ingo

unread,
Nov 7, 2007, 4:47:21 AM11/7/07
to crosscheck
Hi,

I am just getting started with crosscheck and I got some basic tests
to run, but what I got stuck with is how to set up a DOM to test on.
Ideally, I would like to have crosscheck load a html page from a file
or a url - is that possible? The test scripts I saw create DOM
elements to test on using DOM methods.

Ingo

jdwad...@gmail.com

unread,
Nov 7, 2007, 11:07:31 AM11/7/07
to crosscheck
There's is no built-in method for loading an html page from a file or
a URL. You can load html into the DOM using crosscheck.Host.parse.
That will return a DOM object that you can then insert into the
document wherever you need it.

Ex.

var elem = crosscheck.Host.parse("<strong>some html</strong>");
document.body.appendChild(elem);

You could also use innerHTML, but that will be subject to the same
quirks as using innerHTML in a browser.

Also, it should be possible to use Java classes to load a string from
a file or a URL, which you can then pass to the Host.parse function.

Ex.
var io = Packages.java.io;
try {
var file = new io.File("snippet.html");
var reader = new io.BufferedReader(new io.FileReader(file));
var text = "";
var line = "";
while( (line = reader.readLine()) != null ) { text += line; }
} finally {
if (reader) reader.close();
}
var elem = crosscheck.Host.parse(text);
document.body.appendChild(elem);

But, in any of these cases, remember that Crosscheck will not execute
any of the javascript in the text that you parse. You still need to
use crosscheck.load() to initialize your javascript library.

Reply all
Reply to author
Forward
0 new messages