mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-04-08 17:15:08 +02:00
Add dummy test case for casperjs
The dummy test only checks whether our build server has the correct title when called. Also the i2w-config.js toolkit is provided to help testing correct paths refs #4213
This commit is contained in:
parent
11f4a5b0b5
commit
a1298e6edd
19
test/frontend/cases/static-page-test.js
Normal file
19
test/frontend/cases/static-page-test.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* This test simply checks the icinga build server and tests
|
||||||
|
* if the title is correct
|
||||||
|
**/
|
||||||
|
i2w = require('./i2w-config');
|
||||||
|
|
||||||
|
var casper = i2w.getTestEnv();
|
||||||
|
|
||||||
|
casper.start("http://build.icinga.org/jenkins");
|
||||||
|
|
||||||
|
casper.then(function() {
|
||||||
|
this.test.assertTitle("icinga-web test [Jenkins]", "The jenkins page");
|
||||||
|
});
|
||||||
|
|
||||||
|
casper.run(function() {
|
||||||
|
this.test.done();
|
||||||
|
});
|
||||||
|
|
5
test/frontend/casperjs.config
Normal file
5
test/frontend/casperjs.config
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"host": "localhost",
|
||||||
|
"port": 80,
|
||||||
|
"path": "icinga2-web"
|
||||||
|
}
|
107
test/frontend/i2w-config.js
Normal file
107
test/frontend/i2w-config.js
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
/**
|
||||||
|
* Tools for setting up the casperjs tests
|
||||||
|
* mainly setting host, port and path path
|
||||||
|
**/
|
||||||
|
|
||||||
|
// load config files
|
||||||
|
var fs = require('fs');
|
||||||
|
var env = require('system').env;
|
||||||
|
var args = require('system').args;
|
||||||
|
var utils = require('utils');
|
||||||
|
|
||||||
|
|
||||||
|
var configFile = fs.absolute('./casperjs.config');
|
||||||
|
var host = null;
|
||||||
|
var port = null;
|
||||||
|
var path = null;
|
||||||
|
var verbose = false;
|
||||||
|
|
||||||
|
|
||||||
|
if (typeof(env.CASPERJS_HOST) === "string")
|
||||||
|
host = env.CASPERJS_HOST;
|
||||||
|
if (typeof(env.CASPERJS_PORT) === "string")
|
||||||
|
port = parseInt(env.CASPERJS_PORT, 10);
|
||||||
|
if (typeof(env.CASPERJS_PATH) === "string")
|
||||||
|
path = env.CASPERJS_PATH;
|
||||||
|
|
||||||
|
|
||||||
|
for (var i=0;i<args.length;i++) {
|
||||||
|
switch(args[i]) {
|
||||||
|
case '--verbose':
|
||||||
|
verbose = true;
|
||||||
|
break;
|
||||||
|
case '--configFile':
|
||||||
|
configFile = args[++i];
|
||||||
|
break;
|
||||||
|
case '--host':
|
||||||
|
host = args[++i];
|
||||||
|
break;
|
||||||
|
case '--port':
|
||||||
|
port = parseInt(args[++i], 10);
|
||||||
|
break;
|
||||||
|
case '--path':
|
||||||
|
path = args[++i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fs.isReadable(configFile)) {
|
||||||
|
var cfg = fs.read(configFile);
|
||||||
|
try {
|
||||||
|
config = JSON.parse(cfg);
|
||||||
|
if(host === null)
|
||||||
|
host = config.host;
|
||||||
|
if(port === null)
|
||||||
|
port = parseInt(config.port, 10);
|
||||||
|
if(path === null)
|
||||||
|
path = config.path;
|
||||||
|
} catch(e) {
|
||||||
|
console.error("Configuration "+cfg+" is invalid: "+e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (host === null)
|
||||||
|
throw "Can't initialize tests: No host given in casperjs.config or via CASPERJS_HOST environment";
|
||||||
|
if (port === null)
|
||||||
|
throw "Can't initialize tests: No port given in casperjs.config or via CASPERJS_PORT environment";
|
||||||
|
if (path === null)
|
||||||
|
throw "Can't initialize tests: No path given in casperjs.config or via CASPERJS_PATH environment";
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var getBaseURL = function(url) {
|
||||||
|
url = url || "";
|
||||||
|
if (url.substr(0,4) == "http") {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
url = "http://"+host+":"+port+"/"+path+"/"+url;
|
||||||
|
};
|
||||||
|
var cstart = casper.start;
|
||||||
|
var copen = casper.open;
|
||||||
|
var copenFrom = casper.openFrom;
|
||||||
|
var startFromBase = function(url, then) {
|
||||||
|
return cstart.apply(casper,[this.getBaseURL(url), then]);
|
||||||
|
};
|
||||||
|
|
||||||
|
var thenOpenFromBase = function(url, options) {
|
||||||
|
return copen.apply(casper,[this.getBaseURL(url), options]);
|
||||||
|
};
|
||||||
|
|
||||||
|
var openFromBase = function(url, options) {
|
||||||
|
return copenFrom.apply(casper,[this.getBaseURL(url), options]);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.getTestEnv = function() {
|
||||||
|
casper.getBaseURL = getBaseURL;
|
||||||
|
casper.start = startFromBase;
|
||||||
|
casper.thenOpen = thenOpenFromBase;
|
||||||
|
casper.open = openFromBase;
|
||||||
|
return casper;
|
||||||
|
};
|
||||||
|
|
||||||
|
})();
|
||||||
|
|
||||||
|
|
1
test/frontend/regression/test.txt
Executable file
1
test/frontend/regression/test.txt
Executable file
@ -0,0 +1 @@
|
|||||||
|
test
|
Loading…
x
Reference in New Issue
Block a user