代码之家  ›  专栏  ›  技术社区  ›  ruiribeiro

如何使用Intern在execute或executeAsync内截图

  •  1
  • ruiribeiro  · 技术社区  · 7 年前

    executeAsync() 捕捉正在测试的页面的一些事件。我不知道将要发生的事件的数量,对于每一个被捕捉到的事件,我想截屏 .takeScreenshot() . 目前,我正在使用以下代码:

    return this.parent
        .setExecuteAsyncTimeout(5000)
        .executeAsync(function(done) {
            window.events = function(event){
                if(event.message == 'takeScreenshot'){
                    return done(event);
                } else if(event.message == 'endTest'){
                    return done(event);
                }
            };
        }, [])
        .then(function(event){
             return this.parent
                 .takeScreenshot()
                 .then(function(data) {
                     //previously defined array to save the screenshots
                     bufferArray.push(data);
                 })
        .end();
    })
    

    这段代码正在工作,但问题是它只需要一个屏幕截图,因为它只捕获第一个事件,然后完成测试,而不是等待其他事件。谁能告诉我是否可以打电话给 .截图() 内部 .executeAsync()

    1 回复  |  直到 7 年前
        1
  •  0
  •   jason0x43    7 年前

    这个 takeScreenshot 无法从内部调用方法 executeAsync

    function takeScreenshots() {
        return this.parent
            // Wait for a takeScreenshot or endTest event
            .executeAsync(function (done) {
                window.events = function (event) {
                    if (
                        event.message === 'takeScreenshot' ||
                        event.message === 'endTest'
                    ) {
                        done(event);
                    }
                };
            })
            .then(function (event) {
                // If the event was a takeScreenshot, take it and then
                // call takeScreenshots again to wait for another
                // event.
                if (event.message === 'takeScreenshot') {
                    return this.parent
                        .takeScreenshot()
                        .then(function (data) {
                            bufferArray.push(data);
                        })
                        .then(takeScreenshots);
                }
            });
    }
    
    return this.parent
        .setExecuteAsyncTimeout(5000)
        .then(takeScreenshots);