我使用Soda.js、mocha和selenium RC。我正在尝试加快我的测试速度,我想的一种方式是,因为我正在为每个测试启动一个新的会话(即,通过关闭/打开新浏览器并登录到一个站点)。
我在不同的论坛/留言板上看到了许多关于在其他语言中重用会话的不完整帖子,但我的测试都是Javascript。
有没有人知道如何在开始测试后重用以前的浏览器/会话,这样我就不必在每次测试中都启动新的会话。
我的汽水测试跑步器看起来像这样。
var soda = require('soda'),
util = require('util'),
//config object - values injected by TeamCity
config = {
host: process.env['SELENIUM_HOST'] || 'localhost',
port: process.env['SELENIUM_PORT'] || 4444,
url: process.env['SELENIUM_SITE'] || 'http://google.com',
browser: process.env['SELENIUM_BROWSER'] || 'firefox'
};describe("TEST_SITE",function(){
beforeEach(
function(done){
browser = soda.createOnPointClient(config);
// Log commands as they are fired
browser.on('command', function(cmd, args){
console.log(' \x1b[33m%s\x1b[0m: %s', cmd, args.join(', '));
});
//establish the session
browser.session(function(err){
done(err);
});
}
);
afterEach(function(done){
browser.testComplete(function(err) {
console.log('done');
if(err) throw err;
done();
});
});
describe("Areas",function(){
var tests = require('./areas');
for(var test in tests){
if(tests.hasOwnProperty(test)){
test = tests[test];
if(typeof( test ) == 'function')
test();
else if (util.isArray(test)) {
for(var i=0, l=test.length;i<l;i++){
if(typeof( test[i] ) == 'function')
test[i]();
}
}
}
}
});});
发布于 2012-12-20 22:33:26
我找到了答案。我真的需要更多地关注摩卡咖啡,因为我的答案是这样的:
//before running the suite, create a connection to the Selenium server
before(
function(done){
browser = soda.createOnPointClient(config);
// Log commands as they are fired
browser.on('command', function(cmd, args){
console.log(' \x1b[33m%s\x1b[0m: %s', cmd, args.join(', '));
});
//establish the session
browser.session(function(err){
done(err);
});
}
);
//after each test has completed, send the browser back to the main page (hopefully cleaning our environment)
afterEach(function(done){browser.open('/',function(){
done();
});
});
//after the entire suite has completed, shut down the selenium connection
after(function(done){
browser.testComplete(function(err) {
console.log('done');
if(err) throw err;
done();
});
});到目前为止的结果是,通过重用会话而不是启动新会话,我没有看到任何真正的性能提升。我的测试仍然需要大致相同的时间。
https://stackoverflow.com/questions/13921167
复制相似问题