实习生功能测试和清除 cookie 之前和之后
Intern functional testing and clearing cookies with before and after
使用
intern 编写一系列功能测试,我尝试使用 Before 和 After 方法来清除所有 cookie 和本地存储的数据,以便每个测试都干净开始。
这是我尝试使用的cleanEnvironment函数,位于名为utils
的模块中:
cleanEnvironment: function(name) {
name = name || 'NONE';
// window params
var defaultHeight = 768;
var defaultWidth = 1024;
if (this.remote.environmentType.webStorageEnabled === true) {
this.remote
.clearSessionStorage()
.clearLocalStorage();
}
return this.remote
.setWindowSize(defaultWidth, defaultHeight)
.getCookies()
.then(
function(cookies) {
console.log('in ', name);
console.log('Existing cookies that will be cleared are ', cookies);
}
)
.clearCookies()
.then(
function(cookies) {
console.log('in ', name);
console.log('Existing cookies are ', cookies);
}
);
},
这是我尝试在之前/之后的方法中调用它的方式:
after: function() {
console.log('timestamp for login after start is ', Date.now());
utils.cleanEnvironment.call(this, 'login before');
console.log('timestamp for login after finish is ', Date.now());
},
我终于意识到(并重读了这样说的文档)我无法保证多个套件之前和之后的顺序,因为我不会在这些模块中返回 Promise。但是我正在努力编写一个承诺,允许我使用此外部模块utils
所以我不会在每个套件中重复代码。
成功通过并返回对this.remote
的正确引用的 before
/after
方法中的 promise 会是什么样子?我在这些方法中没有找到任何承诺的例子,到目前为止,我要么在未定义this.remote
的 cleanEnvironment
函数中出现错误,要么浏览器从未加载测试 URL,我认为这意味着我永远不会解决承诺。
这是我的尝试之一:
after: function() {
var self = this;
return new Promise(function(resolve, reject) {
console.log('timestamp for login after start is ', Date.now());
utils.cleanEnvironment.call(self, 'login before');
console.log('timestamp for login after finish is ', Date.now());
resolve();
});
},
我确定我完全错过了关于 Promise 的一些明显的东西,但是在盯着这段代码 7 个小时后,我对它是什么视而不见。
命令类似于 promise,可用于异步操作,因此您可以在 after
方法中返回 cleanEnvironment
函数的结果。
after: function () {
return utils.cleanEnvironment(...)
}
您还应该注意维护cleanEnvironment
中的单个链。在原始cleanEnvironment
中,可以启动两个独立的链,并且只返回第二个链。如果由于某种原因,第一个比第二个运行的时间更长,实习生不会等待它完成。要保持链的连续性,请执行以下操作:
var chain = this.remote;
if (this.remote.environmentType.webStorageEnabled === true) {
chain = this.remote
.clearSessionStorage()
.clearLocalStorage();
}
return chain
.setWindowSize(defaultWidth, defaultHeight)
.getCookies()
// ...
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- 在chrome.tabs.onCreated之后加载HTML页面
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 单击jquery清除输入值
- 在Jquery detachment()和appendTo()之后定位元素
- AngularJS:ng之后,重复$scope值未按预期更新
- 为什么元素的宽度在页面加载之后和那一刻之后不同
- 没有在Angular应用程序中定义firebase(在firebase迁移之后)
- Javascript复选框函数:;缺少:在属性id之后"
- 选中此之后剩余的复选框值.form.reset清除
- 实习生功能测试和清除 cookie 之前和之后
- 清除间隔名称未在 JS while 循环之后定义
- 如何防止在清除间隔之前执行 setInterval() 之后的指令
- 如何在清除过滤器之后通过点击“;清除“;按钮
- HTML5 Canvas为什么fillText()方法清除clearRect()之后的所有内容
- 使用jquery清除(data)之后的内容
- 如何在setCustomValidity("…)"之后清除,删除或重置HTML5表单验证状态
- 即使在使用empty()清除DOM之后,jquery函数也会执行两次
- SetInterval即使在我清除它之后仍在运行
- Yii2 Select2没有在Select2 .empty()之后清除选中的值