簡體   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