使用QUnit、JQuery和iframe进行UI测试-如何等待新页面加载?
我正在使用QUnit和JQuery,想测试我网站的用户界面。我的webapp驻留在iframe中。我想单击导航链接,然后等待新页面加载,然后我想通过JQuery选择一些项目,以确保加载了正确的页面 如何做到这一点 我读过关于setTimeout()、delay()、ajaxSetup()、setInterval(),到目前为止:没有成功 以下是一段代码片段:使用QUnit、JQuery和iframe进行UI测试-如何等待新页面加载?,jquery,wait,qunit,Jquery,Wait,Qunit,我正在使用QUnit和JQuery,想测试我网站的用户界面。我的webapp驻留在iframe中。我想单击导航链接,然后等待新页面加载,然后我想通过JQuery选择一些项目,以确保加载了正确的页面 如何做到这一点 我读过关于setTimeout()、delay()、ajaxSetup()、setInterval(),到目前为止:没有成功 以下是一段代码片段: // Klick auf Unternehmen und vergleiche h1-Ueberschrift. test
// Klick auf Unternehmen und vergleiche h1-Ueberschrift.
test("Klick Unternehmen, checke Ueberschrift", function() {
var mes = "test: Klick Unternehmen, checke Ueberschrift;";
var exp = "Unternehmen";
jQuery.ajaxSetup({ async: false }); //turn off async so tests will wait for ajax results
jQuery('#testframe').attr('src', './../index/unternehmen/').delay(3000);
var t = setTimeout('doNothing()', 2000);
//alert('now');
var act = jQuery('h1').eq(1);
//var act = "Unternehmen";
//console.log(mes);
equal(act, exp, mes);
});
更新:我能够通过ajax调用ressource。无论如何,仍然不知道如何调用click()-wait()-compare()
你应该试试
$("#yourIframeID").load(function(){
//do your testing stuff here..
})
在QUnit
中还有一种异步测试方法,但我不确定它是否适用于您的案例(asyncTest(name,expected,test)
)
$("#yourIframeID").load(function(){
//do your testing stuff here..
})