1

我使用 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'
};

描述(“TEST_SITE”,函数(){

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]();
               }
           }
       }

   }
});

});

4

1 回答 1

1

我找到了我的答案。我真的需要更多地专注于摩卡咖啡,我的回答大致如下:

    //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();
    });

});

The result so far was that I'm not seeing any real performance gain by reusing the session over starting a new one. My tests still take roughly the same amount of time.

于 2012-12-20T14:33:26.447 回答