繁体   English   中英

实习生功能测试失败后如何清理?

[英]How to clean up after failed Intern functional tests?

我有一些使用Intern(3)运行的功能测试,测试的最后一步是进行一些清理,包括清除远程浏览器上的localStorage,并通过立即存储窗口句柄并切换回来切换回原始窗口在测试结束之前添加到它(因此,任何后续测试都不会失败,因为如果先前的测试在另一个测试上结束,则它们将尝试在关闭的窗口上运行)。 但是,如果某些chaijs断言在.then()中失败,则将跳过最后的清理代码。 对于某些断言仍然失败的功能测试,还有更好的方法进行清理吗?

this.leadfoot.remote
    .get(require.toUrl(url))
    .execute(function() { return document.querySelector('#welcome').textContent})
    .then(welcome => {
        assert.equal(welcome, 'hello world', 'properly greeted');
    })
    .execute(function() {
        localStorage.clear();
    });

如果断言失败,它将永远不会在最后清除localStorage,并且如果运行的下一个测试期望localStorage为空,它也会失败。 功能测试后是否有更好的清理方法?

使用afterEach方法。

afterEach() {
    return this.remote
        .execute(function () {
            localStorage.clear();
        });
},

'my test'() {
    return this.remote
        .get(...)
        .execute(...)
        .then(welcome => {
            assert.equal(welcome, ...);
        });
}

在我们的项目中,我们这样做:

afterEach: function() {
        var command = this.remote;
        if(intern.variables.currentCase && !intern.variables.currentCase.hasPassed) {
            command = command.execute(function () {
               localStorage.clear();
            });
        }
        return command;
    },

仅在测试失败时才执行本地Storage.clear():

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM