我的应用程序基于运行在felix服务器上的osgi-model。GUI处于Angular状态。我正在开发与后端开发工具并行的GUI测试。目前还没有实现太多的GUI屏幕,所以现在使用量角器来测试GUI功能还为时过早。
然而,我想“假装服从gui”,并通过Felix发送和接收一些事件。这样,我就可以测试一些主要的已知后端功能,这些功能是由前端触发的。
但我不知道如何将事件发送到felix-server!我打算打开一个到felix-server的websocket连接,然后向它发送事件。下面是我的代码:
//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;
});
}); 这是我的cucmber-configuration:
//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-block之后,错误出现在下面的代码行中
websocket = new WebSocket(...);is:“未定义WebSocket”。
你知道我做错了什么吗?非常感谢。
发布于 2017-08-02 03:58:21
看起来您需要安装WebSocket包(npm install here),然后按照链接中的指示在websocket2Felix.js顶部调用('require')必要的文件。
https://stackoverflow.com/questions/44762599
复制相似问题