3
This is an experiment in creating a "selenese" parser that drastically
4
cuts down on the line noise associated with writing tests in HTML.
6
The 'parse' function will accept the follow sample commands.
11
command "param" // comment
12
command "param" "param2"
13
command "param" "param2" // this is a comment
16
1) Deal with multiline parameters
17
2) Escape quotes properly
18
3) Determine whether this should/will become the "preferred" syntax
19
for delivered Selenium self-test scripts
23
function separse(doc) {
25
script = doc.getElementById('testcase')
27
lines = script.text.split('\n');
30
var command_pattern = / *(\w+) *"([^"]*)" *(?:"([^"]*)"){0,1}(?: *(\/\/ *.+))*/i;
31
var comment_pattern = /^ *(\/\/ *.+)/
33
// Regex each line into selenium command and convert into table row.
34
// eg. "<command> <quote> <quote> <comment>"
35
var new_test_source = '';
37
for (var x=0; x < lines.length; x++) {
38
result = lines[x].match(command_pattern);
40
new_line = "<tr><td>" + (result[1] || ' ') + "</td>" +
41
"<td>" + (result[2] || ' ') + "</td>" +
42
"<td>" + (result[3] || ' ') + "</td>" +
43
"<td>" + (result[4] || ' ') + "</td></tr>\n";
44
new_test_source += new_line;
46
result = lines[x].match(comment_pattern);
48
new_line = '<tr><td rowspan="1" colspan="4">' +
49
(result[1] || ' ') +
51
new_test_source += new_line;
57
body.innerHTML += "<table class='selenium' id='testtable'>"+