Commit 77aacf3f authored by Sven Franck's avatar Sven Franck

test: finished test setup

parent b5f638d6
...@@ -164,7 +164,7 @@ ...@@ -164,7 +164,7 @@
// ======================= start here =========================== // ======================= start here ===========================
trigger = function (window, d, $, testHelper) { trigger = function (window, d, $, testHelper) {
// oh lord // oh lord... please buy me another test code generator
var another_string = var another_string =
'<table cellspacing="1" cellpadding="1" border="1" name="SELENIUM-TEST">' + '<table cellspacing="1" cellpadding="1" border="1" name="SELENIUM-TEST">' +
'<thead>' + '<thead>' +
...@@ -209,6 +209,21 @@ ...@@ -209,6 +209,21 @@
'</tr>' + '</tr>' +
'<tr>' + '<tr>' +
'<td>click</td>' + '<td>click</td>' +
'<td>//a[.="Login"]</td>' +
'<td></td>' +
'</tr>' +
'<tr>' +
'<td>verifyAttribute</td>' +
'<td>//div[@id="global-popup-popup"]@class</td>' +
'<td>ui-popup-active</td>' +
'</tr>' +
'<tr>' +
'<td>click</td>' +
'<td>//a[.="Facebook"]</td>' +
'<td></td>' +
'</tr>' +
'<tr>' +
'<td>waitForElementPresent</td>' +
'<td>//a[.="Menu"]</td>' + '<td>//a[.="Menu"]</td>' +
'<td></td>' + '<td></td>' +
'</tr>' + '</tr>' +
...@@ -219,29 +234,35 @@ ...@@ -219,29 +234,35 @@
'</tr>' + '</tr>' +
'<tr>' + '<tr>' +
'<td>click</td>' + '<td>click</td>' +
'<td>//h1[.="My Account"]</td>' + '<td>//a[.="Menu"]</td>' +
'<td></td>' + '<td></td>' +
'</tr>' + '</tr>' +
'<tr>' + '<tr>' +
'<td>waitForElementPresent</td>' + '<td>waitForElementPresent</td>' +
'<td>//a[.="Add network"]</td>' + '<td>//a[.="My Account"]</td>' +
'<td></td>' + '<td></td>' +
'</tr>' + '</tr>' +
'<tr>' + '<tr>' +
'<td>click</td>' + '<td>click</td>' +
'<td>//a[.="Add network"]</td>' + '<td>//a[.="My Account"]</td>' +
'<td></td>' + '<td></td>' +
'</tr>' + '</tr>' +
'<tr>' + '<tr>' +
'<td>waitForElementPresent</td>' + '<td>waitForElementPresent</td>' +
'<td>//input[@id="network_new_title"]</td>' + '<td>//th[.="Email Address"]</td>' +
'<td></td>' + '<td></td>' +
'</tr>' + '</tr>' +
'<tr>' + '<tr>' +
'<td>type</td>' + '<td>click</td>' +
'<td>id=network_new_title</td>' + '<td>//a[@class="table_link"][0]</td>' +
'<td>Bazbam</td>' + '<td></td>' +
'</tr>' + '</tr>' +
'<tr>' + '<tr>' +
'<td>pause</td>' + '<td>pause</td>' +
'<td>5000</td>' + '<td>5000</td>' +
...@@ -829,7 +850,7 @@ ...@@ -829,7 +850,7 @@
// (7) // (7)
var tableToParse, tag, selector, val, ins, find, close_async, i, var tableToParse, tag, selector, val, ins, find, close_async, i,
instruction, madeJS, add, menu_button, testForElement, countDown, instruction, madeJS, add, menu_button, testForElement, countDown,
getParam, test_value; getParam, test_value, test_attr, test_log, wrap, iter;
// parse table into objcet // parse table into objcet
...@@ -847,12 +868,24 @@ ...@@ -847,12 +868,24 @@
// extract selector identifier (class, id, :contains...) // extract selector identifier (class, id, :contains...)
selector = function(str) { selector = function(str) {
var base = str.split("[")[1].split("=")[0].replace("@", ""); var base = str.split("[")[1].split("=")[0].replace("@", "");
switch (base) { switch (base) {
case "class": return [".", ""];
case "id": return ["#", ""]; case "id": return ["#", ""];
case ".": return [":contains('", "')"]; case ".": return [":contains('", "')"];
} }
}; };
// which element
nth = function (str) {
if (str.split("][").length > 1) {
return ":nth-child(" +
str.split("]").slice(-2).shift().replace("[","") +
")";
}
return ""
};
// extract selector value // extract selector value
val = function(str) { val = function(str) {
return str.split("=")[1] return str.split("=")[1]
...@@ -868,113 +901,112 @@ ...@@ -868,113 +901,112 @@
madeJS = 'var frame = document.getElementsByTagName("iframe")[0];' + madeJS = 'var frame = document.getElementsByTagName("iframe")[0];' +
'var d = frame.contentDocument;' + 'var d = frame.contentDocument;' +
'var w = frame.contentWindow;' + 'var w = frame.contentWindow;' +
'var $i = $( d );'; 'var $i = w.$( d );' +
'var test_log = 0;' +
'var $body = w.$("body");';
// dump all testmethods here, because they need to be available // dump all testmethods here, because they need to be available
// inside the iFrame... // inside the iFrame...
madeJS += '$.testHelper.countDown = function(test, iteration) {' + madeJS += '$.testHelper.eventTarget = $body;' +
'var ticker = iteration || 0;' + '$.testHelper.stepSequence = function (fns) {' +
'if (ticker > 10) {' + '$.testHelper.eventSequence( "step", fns );' +
'return false;' + '};' +
'}' + '$.testHelper.runTest = function (command, condition, arr) {' +
'window.setTimeout(function() {' + 'var message = command + " - CRITERIA - " + arr[0] + "|" + arr[1] + "|" + arr[2];' +
'if (test === true) {' + 'ok(condition, message);' +
'return true;' + '$body.trigger("step");' +
'$body.trigger("test_runner");' +
'};' +
'$.testHelper.countDown = function (arr, command) {' +
'var condition, is_done;' +
'var ticker = 0;' +
'var i = w.setInterval(function() {' +
'switch (command) {' +
'case "verifyAttribute":' +
'condition = $i.find(arr[0]).eq(0).attr(arr[1]).indexOf(arr[2]) > -1;' +
'break;' +
'case "waitForElementPresent":' +
'condition = $i.find(arr[0]).length > 0;' +
'break;' +
'}' + '}' +
'if (condition) {' +
'$.testHelper.runTest(command, condition, arr);' +
'w.clearInterval(i); ' +
'}'+
'ticker += 1;' + 'ticker += 1;' +
'$.testHelper.countDown(test, ticker);' + 'if (ticker === 10) {' +
'$.testHelper.runTest(command, condition, arr);' +
'w.clearInterval(i);' +
'}' +
'}, 1000);' + '}, 1000);' +
'};' +
'$.testHelper.testForAttribute = function(element, attr, value) {' +
'var look = $i.find(element).eq(0).attr(attr);' +
'return $.testHelper.countDown(' +
'look.indexOf(value) > -1' +
');' +
'};' +
'$.testHelper.testForElement = function(element) {' +
'return $.testHelper.countDown(' +
'$i.find(element).length > 0' +
');' +
'};'; '};';
madeJS += 'module("' + 'SlapOS UI Basic Interaction' + '");'; madeJS += 'module("' + 'SlapOS UI Basic Interaction' + '");';
len = tableToParse.length; len = tableToParse.length;
// loop table rows // loop table rows
for (i = 0; i < 9; i += 1) { for (i = 0; i < 17; i += 1) {
instruction = tableToParse[i]; instruction = tableToParse[i];
// parse instructions // parse instructions
console.log(instruction.command)
switch (instruction.command) { switch (instruction.command) {
case "openAndWait": case "openAndWait":
// close previous async block
if (close_async) {
madeJS += 'function() {start();} ]) });';
madeJS = madeJS.replace(/__number__/, count.toString());
close_asyn = undefined;
count = undefined;
}
// start a new block // start a new block
close_async = true; close_async = true;
count = 0; count = 0;
madeJS += ' asyncTest( "' + instruction.selector + '", function() { expect( __number__ );'; madeJS += ' asyncTest( "' + instruction.selector + '", function() { expect( __number__ );';
madeJS += '$.testHelper.pageSequence(['; madeJS += '$.testHelper.stepSequence([ function () {';
madeJS += '$body.on("test_runner", function (e) {' +
'test_log += 1;' +
'if (test_log === __number__) {' +
'start();' +
'}' +
'});' +
'}, function () {';
break; break;
case "click": case "click":
ins = instruction.selector; ins = instruction.selector;
wrap = selector(ins); wrap = selector(ins);
find = tag(ins) + wrap[0] + val(ins) + wrap[1]; find = tag(ins) + wrap[0] + val(ins) + nth(ins) + wrap[1];
madeJS += 'function () {' + madeJS += '$i.find("' + find + '").trigger("click");';
'$("' + find + '").trigger("click");' +
'},';
break; break;
case "verifyAttribute": case "verifyAttribute":
ins = instruction.selector; ins = instruction.selector;
wrap = selector(ins); wrap = selector(ins);
count += 1; count += 1;
find = (tag(ins) + wrap[0] + val(ins) + wrap[1]).split("@")[0]; find = (tag(ins) + wrap[0] + val(ins) + nth(ins) + wrap[1]).split("@")[0];
test_value = getParam(ins); test_attr = getParam(ins);
madeJS += 'function () {'; test_value = instruction.value;
switch (test_value) { madeJS += '$.testHelper.countDown(' +
case 'class': '["' + find + '", "' + test_attr + '", "' + test_value + '"],' +
madeJS += 'var t = $.testHelper.testForAttribute("' + '"verifyAttribute"' +
find + '", "' + test_value + '", "' + instruction.value + ');}, function () {';
'");';
break;
}
madeJS += '}, function (t) {' +
'ok(t, "attribute present");' +
'},';
break; break;
case "waitForElementPresent": case "waitForElementPresent":
ins = instruction.selector; ins = instruction.selector;
wrap = selector(ins); wrap = selector(ins);
find = tag(ins) + wrap[0] + val(ins) + wrap[1]; find = tag(ins) + wrap[0] + val(ins) + nth(ins) + wrap[1];
count += 1; count += 1;
madeJS += 'function () {' + madeJS += '$.testHelper.countDown(' +
'var t = $.testHelper.testForElement("' + find + '");' + '["' + find + '", undefined, undefined],' +
'}, function (t) {' + '"waitForElementPresent"' +
'ok(t, "element present");' + ');}, function () {';
'},';
break; break;
} }
} }
if (close_async) { if (close_async) {
madeJS += 'function() {start();} ]) });'; console.log("CLOSED")
madeJS = madeJS.replace(/__number__/, count.toString()); madeJS += '} ]) });';
madeJS = madeJS.replace(/__number__/g, count.toString());
close_asyn = undefined; close_asyn = undefined;
count = undefined; count = undefined;
} }
console.log(madeJS) console.log(madeJS);
// inject // inject
add = d.createElement("script"); add = d.createElement("script");
add.type = "text/javascript"; add.type = "text/javascript";
...@@ -984,79 +1016,7 @@ ...@@ -984,79 +1016,7 @@
$.testHelper = testHelper; $.testHelper = testHelper;
QUnit.start();
// just a dummy....
window.setTimeout(function () {
QUnit.start();
// ========================
module( "Network Section" );
asyncTest( "Navigate to network page", function() {
var network_page, menu_button;
expect( 1 );
$.testHelper.pageSequence([
function() {
menu_button= $("#global-header").find("a[data-rel='panel']");
ok( menu_button.length === 1, "Menu button exists, application init rendered correctly");
menu_button.trigger( "click" );
},
/*
function() {
setTimeout(function() {
ok( $("#global-panel").hasClass("ui-panel-open"), "panel opens when clicking menu button" );
$("a[href='#networks']").trigger("click");
}, 800);
},
function(){
setTimeout(function(){
network_page = $("div.ui-page").last();
ok( network_page.length === 1, "network page loaded" );
}, 800);
},
function(){
var table, new_button;
setTimeout(function(){
table = network_page.find("table");
new_button = $("a[href='#networks/new']");
ok( table.length === 1, "network table generated" );
ok( table.find("tbody tr").length > 0, "network table has records (zero result record, or 1+ records" );
ok( new_button.length === 1, "New network button available");
new_button.trigger("click");
}, 1000);
},
function() {
var new_network, form, input, submit;
setTimeout(function(){
new_network = $("div.ui-page").last();
form = new_network.find("form");
input = form.find("div.ui-input-text input[type='text']");
submit = form.find("input[type='submit']");
ok( input.length === 1, "new network title input exits");
input.val("foobarbazbam");
submit.trigger("click");
}, 800);
},
function() {
var i, network_page, inputs, test_value;
setTimeout(function() {
network_page = $("div.ui-page").last();
inputs = network_page.find("input");
for (i = 0; i < inputs.length; i += 1) {
if (inputs.eq(i)[0].value === "foobarbazbam") {
test_value = true;
}
}
ok(test_value, "network has been generated and the name is matching what was entered before");
}, 1000);
},*/
function() {
start();
}
]);
})
}, 1000);
}; };
// let's go // let's go
...@@ -1075,4 +1035,4 @@ ...@@ -1075,4 +1035,4 @@
Your browser doesn't support Iframes Your browser doesn't support Iframes
</div> </div>
</body> </body>
</html> </html>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment