带量角器的AngularJs-e2e测试:如何通过websocket连接到服务器
我的应用程序基于运行在felix服务器上的osgi模型。图形用户界面是有角度的。 我正在与后端开发人员并行开发GUI测试。目前还没有实现多少GUI屏幕,所以现在使用量角器测试GUI功能还为时过早 然而,我想“假装服从gui”,并通过Felix发送和接收一些事件。通过这种方式,我可以测试一些由前端启动的主要已知后端功能 但我不知道如何将事件发送到felix服务器!我想打开到felix服务器的websocket连接,然后向它发送事件。这是我的密码:带量角器的AngularJs-e2e测试:如何通过websocket连接到服务器,angularjs,websocket,protractor,cucumber,Angularjs,Websocket,Protractor,Cucumber,我的应用程序基于运行在felix服务器上的osgi模型。图形用户界面是有角度的。 我正在与后端开发人员并行开发GUI测试。目前还没有实现多少GUI屏幕,所以现在使用量角器测试GUI功能还为时过早 然而,我想“假装服从gui”,并通过Felix发送和接收一些事件。通过这种方式,我可以测试一些由前端启动的主要已知后端功能 但我不知道如何将事件发送到felix服务器!我想打开到felix服务器的websocket连接,然后向它发送事件。这是我的密码: //websocket2Felix.js var
//websocket2Felix.js
var websocket =null;
module.exports = {
openConnection: function() {
try{
websocket = new WebSocket("ws://localhost:8080/myproj");
websocket.onopen = function(evt) { onOpen(evt) };
websocket.onclose = function(evt) { onClose(evt) };
websocket.onmessage = function(evt) { onMessage(evt) };
websocket.onerror = function(evt) { onError(evt) };
}
catch(err){
browser.logger.info( err.message + "/n");
}
},
doSend: function(message) {
browser.logger.info("SENT: " + message);
websocket.send(message);
}
};
function onOpen(evt) {
}
function onClose(evt) {
}
function onMessage(evt) {
}
function onError(evt) {
}
我在测试用例定义中使用了这段代码,我使用cucumber语法编写了这段代码:
//home_steps.js
var websocketOnFelix = require ('./websocket2Felix.js');
var homeSteps = function() {
this.Given(/^I am on the home$/, function () {
browser.get("path/to/home");
});
this.When(/^I click on help button$/, function(){
//open websocket to felix to send gui-events to it
browser.pause();
websocketOnFelix.openConnection();
browser.pause();
/////// here to send the click event to felix//////
});
this.Then(/^The help screen should be displayed$/, function(){
el= element(by.css('#help-screen'));
expect( el.isPresent() ).to.be.ok;
});
});
这是我的黄瓜配置:
//cucumConfig.js
'use strict';
exports.config = {
seleniumAddress: 'http://127.0.0.1:4444/wd/hub',
getPageTimeout: 60000,
allScriptsTimeout: 500000,
framework: 'custom',
frameworkPath: require.resolve('protractor-cucumber-framework'),
output:'./output.json',
capabilities: {
'browserName': 'chrome'
},
specs: [
'*.feature'
],
cucumberOpts: {
require: '*_steps.js',
tags: false,
format: 'pretty',
profile: false
},
};
当我打电话时
protractor cucumbConfig.js
在这一行“websocketOnFelix.openConnection();”之后,我在控制台中得到了一个相当好的结果,在测试用例中永远不会到达下一行
添加try-catch块后,该错误由行引起
websocket = new WebSocket(...);
is:“未定义WebSocket”
知道我做错了什么吗?
非常感谢。看起来您需要安装WebSocket包(),然后调用websocket2Felix.js顶部的必要文件('require')
按照链接中的指示。在使用WebSocket软件包之前,我已经安装了它。我想问题是某种同步/异步通信。