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