【问题标题】:soda.js Selenium RC 2 How to Reuse Browser Sessionsoda.js Selenium RC 2 如何重用浏览器会话
【发布时间】:2012-12-04 23:06:00
【问题描述】:

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

   }
});

});

【问题讨论】:

    标签: javascript selenium teamcity mocha.js


    【解决方案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();
        });
    
    });
    

    到目前为止的结果是,通过重用会话而不是开始新会话,我没有看到任何真正的性能提升。我的测试仍然需要大致相同的时间。

    【讨论】:

      猜你喜欢
      • 2018-09-20
      • 1970-01-01
      • 2012-02-11
      • 2010-11-10
      • 2013-01-05
      • 2020-12-03
      • 2011-01-07
      • 1970-01-01
      • 2015-01-17
      相关资源
      最近更新 更多