Commit 619f51a0 authored by Sven Franck's avatar Sven Franck

test: added multiple start/stop to wait for async requests

parent 283886f1
......@@ -168,6 +168,8 @@
d = el.contentDocument;
j = el.contentWindow.$;
helper = $.testHelper;
// unbind onload handler
frame.onload = undefined;
// ======================= start here ===========================
trigger = function (window, d, $, testHelper) {
......@@ -215,21 +217,37 @@
'<td>//div[@id="global-panel"]</td>' +
'<td></td>' +
'</tr>' +
'<tr>' +
'<td>waitForElementPresent</td>' +
'<td>//div[@id="global-popup-popup"]</td>' +
'<td></td>' +
'</tr>' +
'<tr>' +
'<td>click</td>' +
'<td>//a[.="Login"]</td>' +
'<td></td>' +
'</tr>' +
'<tr>' +
'<td>waitForElementPresent</td>' +
'<td>//div[@id="global-popup-popup"]</td>' +
'<td>verifyAttribute</td>' +
'<td>//div[@id="global-popup-popup"]@class</td>' +
'<td>ui-popup-active</td>' +
'</tr>' +
'<tr>' +
'<td>click</td>' +
'<td>//a[@data-reference="google"]</td>' +
'<td></td>' +
'</tr>' +
'<tr>' +
'<td>pause</td>' +
'<td>5000</td>' +
'<td></td>' +
'</tr>' +
'<tr>' +
'<td>verifyAttribute</td>' +
'<td>//div[@id="global-popup-popup"]@class</td>' +
'<td>ui-popup-active</td>' +
'<td>ui-popup-hidden</td>' +
'</tr>' +
'</tbody>' +
'</table>';
......@@ -304,6 +322,7 @@
// set reference, because what we do is not working
madeJS = 'var frame = document.getElementsByTagName("iframe")[0];' +
'var $frame = $(frame);' +
'var d = frame.contentDocument;' +
'var w = frame.contentWindow;' +
'var $i = w.$( d );' +
......@@ -311,26 +330,28 @@
'var $body = w.$("body");';
// dump all testmethods here, because they need to be available
// inside the iFrame...
madeJS += '$.testHelper.eventTarget = $body;' +
madeJS += '$.testHelper.eventTarget = $frame;' +
'$.testHelper.stepSequence = function (fns) {' +
'$.testHelper.eventSequence( "step", fns );' +
'};' +
'$.testHelper.runTest = function (command, condition, arr) {' +
'var message = command + " - CRITERIA - " + arr[0] + "|" + arr[1] + "|" + arr[2];' +
'ok(condition, message);' +
'$body.trigger("step");' +
'$body.trigger("test_runner");' +
'$frame.trigger("step");' +
'$frame.trigger("test_runner");' +
'};' +
'$.testHelper.countDown = function (arr, command) {' +
'var condition, is_done;' +
'var ticker = 0;' +
'var el;' +
'var skip_test;' +
'var source;' +
'var i = w.setInterval(function() {' +
'switch (command) {' +
'case "verifyAttribute":' +
'el = $.find(arr[0]);' +
'el = $i.find(arr[0]);' +
'if (el.length > 0) {' +
'console.log("OI");console.log(arr);condition = $i.find(arr[0]).eq(0).attr(arr[1]).indexOf(arr[2]) > -1;' +
'condition = el.eq(0).attr(arr[1]).indexOf(arr[2]) > -1;' +
'} else {' +
'condition = false;' +
'}' +
......@@ -380,13 +401,13 @@
count = 0;
madeJS += ' asyncTest( "' + instruction.selector + '", function() { expect( __number__ );';
madeJS += '$.testHelper.stepSequence([ function () {';
madeJS += '$body.on("test_runner", function (e) {' +
madeJS += '$frame.on("test_runner", function (e) {' +
'test_log += 1;' +
'if (test_log === __number__) {' +
'start();' +
'start(0);' +
'}' +
'});' +
'}, function () {';
'$frame.trigger("step");}, function () {';
break;
case "select":
......@@ -409,7 +430,20 @@
ins = instruction.selector;
wrap = selector(ins);
find = tag(ins) + wrap[0] + val(ins) + nth(ins) + wrap[1];
madeJS += '$i.find("' + find + '").trigger("click");';
source = find.indexOf("google") !== -1;
if (source) {
madeJS += 'stop(0);frame.onload = function () {' +
'frame.onload=undefined;' +
'$i = frame.contentWindow.$(frame.contentDocument);' +
'window.setTimeout(function() {' +
'$frame.trigger("step");start(1);' +
'},5000);' +
'};' +
'frame.src = $i.find("' + find + '")[0].href;' +
'}, function() {';
} else {
madeJS += '$i.find("' + find + '").trigger("click");';
}
break;
case "verifyText":
......@@ -486,6 +520,7 @@
<div id="playground">
<iframe id="testbed" src="../index.html">
Your browser doesn't support Iframes
</iframe>
</div>
</body>
</html>
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