【发布时间】:2017-12-16 17:52:14
【问题描述】:
假设我在页面上有一个按钮和一个 div 元素。
<button /><div>old text</div>
通过单击按钮,javascript 异步更改 div 的文本(即在 ajax 调用之后)。我如何与实习生一起测试它?
这不起作用:
function testButtonClick() {
return command
.findByTagName('button')
.click()
.end()
.findByTagName('div')
.getVisibleText()
.then(function(text) { assert.strictEqual(text,'new text')}); //errror, text is 'old text'
}
如果我在.end() 之后添加.sleep(5000),那么它可以正常工作(因为我的异步请求通常在 5 秒内完成)。但我不想等这么久,因为异步通常会更早完成。
但是使用时间值较低的睡眠,我冒着在请求完成之前对其进行测试的风险。
有没有更好的办法?
【问题讨论】:
标签: javascript testing intern