UI-Test with QUnit, JQuery and iframe - how to wait for a new page to load?

I use QUnit and jQuery and want to check the user interface of my site. My webapp is in an iframe. I want to click on the navigation link, then wait for the new page to load, and then I want to select several elements through jQuery to make sure the correct page is loaded.

How to do it?

I read about setTimeout (), delay (), ajaxSetup (), setInterval (), so far: without success.

Here is the code snippet:

// 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);
        });

UPDATE: I was able to call ressource using ajax. In any case, I still do not know how to call click () - wait () - compare ().

// Klick auf Unternehmen und vergleiche h1-Ueberschrift, Ajax S. 250
        test("Klick Unternehmen, checke Ueberschrift", function() {
            jQuery.ajax({
                url: "./../index/unternehmen/",
                async: false,
                success: function(response){
                    if (response){
                        jQuery('#ajaxcontent').html(response);
                    }
                },
                context: document.body,
                type: "POST"
            });
            var mes = "test: Klick Unternehmen, checke Ueberschrift;";
            var exp = "Unternehmen";
            var act = jQuery('#ajaxcontent h1').eq(0).text();
            equal(act, exp, mes);
        });
+5
source share
1 answer

You must try

$("#yourIframeID").load(function(){
    //do your testing stuff here..

})

QUnit, , (asyncTest( name, expected, test ))

+2

All Articles