单就地解决方案:你可以写browser.wait
自己的断言函数,将在浏览器端执行JS,如果关闭套接字返回true(或您自己的检查):
let waitForWebSocket =() => {
let jsFunction =() => {//some js code that will be executed on browser side
//pseudocode. I beleive this will be something with promises and event listeners
if (webSocketConnectionClosed) {
return true
} else {
return false
}
}
return browser.executeScript(jsFunction)
}
browser.wait(waitForWebSocket, 10000, 'WebSocket connection expected to be closed')
作为一个长期为您的测试项目提供长期的全球解我会建议看看量角器插件功能。你可以定义你自己的waitForPromise
钩子,它会在每个动作之间执行。
http://www.protractortest.org/#/plugins
/**
* Between every webdriver action, Protractor calls browser.waitForAngular() to
* make sure that Angular has no outstanding $http or $timeout calls.
* You can use waitForPromise() to have Protractor additionally wait for your
* custom promise to be resolved inside of browser.waitForAngular().
*
* @this {Object} bound to module.exports
*
* @throws {*} If this function throws an error, a failed assertion is added to
* the test results.
*
* @return {q.Promise=} Can return a promise, in which case protractor will wait
* for the promise to resolve before continuing. If the promise is
* rejected, a failed assertion is added to the test results, and protractor
* will continue onto the next command. If nothing is returned or something
* other than a promise is returned, protractor will continue onto the next
* command.
*/
exports.waitForPromise = function() {};
而且类似:
exports.waitForCondition
你说,一旦你收到回应,您导航到另一条路线。你能用吗?将'browser.wait()'与'getCurrentUrl()'合并,并在url包含新路由时返回 – Gunderson
我可以试试看,我也在考虑嘲笑我的websocket服务,但后来我想我离开一个真正的E2E测试。 – Jackie
事实上,如果我做了类似'browser.wait(function(){return browser.getCurrentUrl()。then(function(x){x ===“...”})}''但我我不确定我喜欢那样。当我收到一条不会更改网址或其他内容的消息时会发生什么。 – Jackie