Skip to content

Instantly share code, notes, and snippets.

@frequent
Created April 1, 2014 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frequent/9914224 to your computer and use it in GitHub Desktop.
Save frequent/9914224 to your computer and use it in GitHub Desktop.
I would like to be async
var frame = document.getElementsByTagName("iframe")[0];
var $frame = $(frame);
var d = frame.contentDocument;
var w = frame.contentWindow;
var $i = w.$(d);
var test_log = 0;
var $body = w.$("body");
$.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);
$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 = $i.find(arr[0]);
if (el.length > 0) {
condition = el.eq(0).attr(arr[1]).indexOf(arr[2]) > -1;
} else {
condition = false;
}
break;
case "verifyText":
el = $.find(arr[0]);
if (el.length > 0) {
condition = $.find(arr[0]).eq(0).text(arr[2]).length > 0;
} else {
condition = false;
}
break;
case "waitForElementPresent":
condition = $i.find(arr[0]).length > 0;
break;
}
if (condition) {
$.testHelper.runTest(command, condition, arr);
w.clearInterval(i);
}
ticker += 1;
if (ticker === 10) {
$.testHelper.runTest(command, condition, arr);
w.clearInterval(i);
}
}, 1000);
};
module("SlapOS UI Basic Interaction");
asyncTest("${base_url}", function () {
expect(4);
$.testHelper.stepSequence([
function () {
$frame.on("test_runner", function (e) {
test_log += 1;
if (test_log === 4) {
start(0);
}
});
$frame.trigger("step");
},
function () {
$.testHelper.countDown(["div#global-panel", undefined, undefined], "waitForElementPresent");
},
function () {
$.testHelper.countDown(["div#global-popup-popup", undefined, undefined], "waitForElementPresent");
},
function () {
$i.find("a:contains('Login')").trigger("click");
$.testHelper.countDown(["div#global-popup-popup", "class", "ui-popup-active"], "verifyAttribute");
},
function () {
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("a[data-reference='google']")[0].href;
},
function () {
$.testHelper.countDown(["div#global-popup-popup", "class", "ui-popup-hidden"], "verifyAttribute");
},
function () {}
])
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment