Jasmine不加载iframe的内容

Jasmine doesn't load content of iframe

本文关键字:iframe 加载 Jasmine      更新时间:2023-09-26

我尝试在Jasmine测试中访问iframe的内容

<iframe 
    src="http://www.*******.net/" 
    style="width:100%; height: 100%;" 
    class="frame"
    id="test-frame"
></iframe>

JS代码:

    describe('DOM of color elements checking', function () {
    jasmine.getFixtures().fixturesPath = 'base/tests/units/js/fixtures';
    jasmine.getFixtures().load('frame.html');
    var fixtureIframe = readFixtures('iframe.html'); //here is iframe HTML
    $('.workspace__iframe-wrapper').append(fixtureIframe);
    $('iframe').load(function(){
       var body = $('.frame').contents().find('body');
       console.log(body);
    });
});

iframe中的内容无法加载

为什么会这样?

我已经找到解决办法了。启动测试后加载Iframe。这就是为什么我的测试没有看到框架。我添加了beforeEach函数,其中写入

JS

beforeEach(function(done){
   jasmine.getFixtures().fixturesPath = 'base/tests/units/js/fixtures';
   jasmine.getFixtures().load('frame.html');
   interval = jasmine.DEFAULT_TIMEOUT_INTERVAL;
   jasmine.DEFAULT_TIMEOUT_INTERVAL = 15000;
   intId = setInterval(function() {
       $('#frame').load(function(){
           done();
       });
    }, 500);
});

都在工作!!