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

Javascript 实习生功能测试失败后如何清理?,javascript,functional-testing,intern,Javascript,Functional Testing,Intern,我有一些使用Intern(3)运行的功能测试,测试的最后一步是进行一些清理,包括清除远程浏览器上的localStorage,并通过立即存储窗口句柄切换回原始窗口,并在测试结束前切换回它(因此,任何后续测试都不会失败,因为如果上一个测试在另一个窗口上结束,它们将尝试在关闭的窗口上运行)。但是,如果某些chaijs断言在.then()中失败,则会跳过最后的清理代码。是否有更好的方法来清理即使某些断言失败仍会运行的功能测试 this.leadfoot.remote .get(require.t

我有一些使用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() {
    return this.remote
        .execute(function () {
            localStorage.clear();
        });
},

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

在每个
方法之后使用

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;
    },

只有在测试失败时才会执行local Storage.clear():

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

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

只有当测试失败时,才会执行local Storage.clear()
函数,但我无法使其工作。这就是您使用此方法的原因吗?是的,
clearLocalStorage
依赖于webdriver的实现,并且不是所有webdriver都实现该命令。如果驱动程序未实现本地存储命令,Leadfoot应该已经解决了这一问题,并运行类似于上述代码的代码,但是目前没有。()Leadfoot具有
clearLocalStorage()
函数,但我无法使其工作。这就是您使用此方法的原因吗?是的,
clearLocalStorage
依赖于webdriver的实现,并且不是所有webdriver都实现该命令。如果驱动程序未实现本地存储命令,Leadfoot应该已经解决了这一问题,并运行类似于上述代码的代码,但是目前没有