2012-05-27 6 views
5

Estoy usando QUnit y JQuery y quiero probar la interfaz de usuario de mi sitio web. Mi aplicación web reside en un iframe. Quiero hacer clic en un enlace de navegación, luego esperar hasta que se cargue la nueva página y luego quiero seleccionar algunos elementos a través de JQuery para asegurarme de que se cargó la página correcta.UI-Test con QUnit, JQuery y un iframe: ¿cómo esperar hasta que se cargue una nueva página?

¿Cómo lograr esto?

He leído sobre setTimeout(), delay(), ajaxSetup(), setInterval(), hasta ahora: sin éxito.

Aquí es un fragmento de código:

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

ACTUALIZACIÓN: yo era capaz de llamar a la ressource de ajax. De todos modos todavía no tengo idea de cómo llamar a 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); 
     }); 

Respuesta

2

Usted debe tratar

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

}) 

También hay un modo asíncrono para las pruebas en QUnit, pero estoy seguro de que ni se aplica a su caso (asyncTest(name, expected, test))

Cuestiones relacionadas