Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save sean-hill/3ceea3f22c074c77a7be2dbb41b36f93 to your computer and use it in GitHub Desktop.

Select an option

Save sean-hill/3ceea3f22c074c77a7be2dbb41b36f93 to your computer and use it in GitHub Desktop.

Revisions

  1. sean-hill revised this gist Nov 22, 2016. 1 changed file with 3 additions and 10 deletions.
    13 changes: 3 additions & 10 deletions selenium.js
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ var xvfb = new Xvfb({
    xvfb_args: ['-screen', '0', '2880x1800x24']
    });

    exports.boot = function(finished) {
    exports.boot = function (finished) {

    async.waterfall([

    @@ -95,7 +95,7 @@ function startSelenium(selenium, args, started) {

    };

    function kill(dontExit) {
    function kill() {

    if (selenium && selenium.children) {

    @@ -111,16 +111,9 @@ function kill(dontExit) {
    xvfb.stopSync();
    }

    if (dontExit) {
    return;
    }
    else {
    process.exit(1);
    }

    };

    exports.boot = boot;
    exports.kill = kill;

    process.on('SIGINT', function(){
    console.log('Process SIGINT');
  2. sean-hill revised this gist Nov 22, 2016. No changes.
  3. sean-hill revised this gist Nov 22, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion selenium.js
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ exports.boot = function(finished) {
    });
    },

    // 3rd. Start Selenium Hub
    // 3rd. Start Selenium Grid
    function (done) {
    startSelenium(selenium, ['-role', 'hub', '-timeout', '100'], done);
    },
  4. sean-hill revised this gist Nov 22, 2016. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions selenium.js
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ var xvfb = new Xvfb({
    xvfb_args: ['-screen', '0', '2880x1800x24']
    });

    exports.go = function(finished) {
    exports.boot = function(finished) {

    async.waterfall([

    @@ -95,7 +95,7 @@ function startSelenium(selenium, args, started) {

    };

    function end(dontExit) {
    function kill(dontExit) {

    if (selenium && selenium.children) {

    @@ -120,14 +120,14 @@ function end(dontExit) {

    };

    exports.end = end;
    exports.boot = boot;

    process.on('SIGINT', function(){
    console.log('Process SIGINT');
    end();
    kill();
    });

    process.on('SIGTERM', function(){
    console.log('Process SIGTERM');
    end();
    kill();
    });
  5. sean-hill revised this gist Nov 22, 2016. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion selenium.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,5 @@
    var async = require('async');
    var selenium = require('selenium-standalone');
    var maxNodes = 6;
    var Xvfb = require('xvfb');
    var xvfb = new Xvfb({
    displayNum: 99,
  6. sean-hill revised this gist Nov 22, 2016. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions selenium.js
    Original file line number Diff line number Diff line change
    @@ -39,6 +39,9 @@ exports.go = function(finished) {
    // 4th. Start Selenium Nodes
    function (selenium, done) {

    // Ideal amount of Selenium Grid nodes on an Amazon m3.large instance
    var maxNodes = 6;

    async.times(maxNodes, function(n, next){

    var args = ['-role', 'node', '-hub', 'http://localhost:4444/grid/register', '-maxSession', '1'];
  7. sean-hill revised this gist Nov 22, 2016. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions selenium.js
    Original file line number Diff line number Diff line change
    @@ -3,9 +3,9 @@ var selenium = require('selenium-standalone');
    var maxNodes = 6;
    var Xvfb = require('xvfb');
    var xvfb = new Xvfb({
    displayNum: 99
    , reuse: true
    , xvfb_args: ['-screen', '0', '2880x1800x24']
    displayNum: 99,
    reuse: true,
    xvfb_args: ['-screen', '0', '2880x1800x24']
    });

    exports.go = function(finished) {
  8. sean-hill revised this gist Nov 22, 2016. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion selenium.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,6 @@ var xvfb = new Xvfb({
    , xvfb_args: ['-screen', '0', '2880x1800x24']
    });


    exports.go = function(finished) {

    async.waterfall([
  9. sean-hill created this gist Nov 22, 2016.
    1 change: 1 addition & 0 deletions node.js, selenium grid, xvfb, and webdriver.io
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    node.js, selenium grid, xvfb, and webdriver.io
    132 changes: 132 additions & 0 deletions selenium.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,132 @@
    var async = require('async');
    var selenium = require('selenium-standalone');
    var maxNodes = 6;
    var Xvfb = require('xvfb');
    var xvfb = new Xvfb({
    displayNum: 99
    , reuse: true
    , xvfb_args: ['-screen', '0', '2880x1800x24']
    });


    exports.go = function(finished) {

    async.waterfall([

    // 1st. Start Xvfb
    function (done) {
    xvfb.start(function(err){
    return done(err);
    });
    },

    // 2nd. Install Selenium
    function (done) {
    selenium.children = [];
    selenium.install({
    logger: function (message) {
    console.log('Selenium install:', message);
    }
    }, function(err){
    return done(err);
    });
    },

    // 3rd. Start Selenium Hub
    function (done) {
    startSelenium(selenium, ['-role', 'hub', '-timeout', '100'], done);
    },

    // 4th. Start Selenium Nodes
    function (selenium, done) {

    async.times(maxNodes, function(n, next){

    var args = ['-role', 'node', '-hub', 'http://localhost:4444/grid/register', '-maxSession', '1'];
    var port = '555' + n;
    args.push('-port');
    args.push(port);

    startSelenium(selenium, args, next);

    }, function(){
    return done(null, selenium);
    });

    }

    ], function (err) {

    if (err) {
    console.log('Selenium startup error:', err);
    }
    else {
    console.log('Selenium listening!');
    }

    if (finished) {
    return finished();
    }

    });

    };

    function startSelenium(selenium, args, started) {

    selenium.start({
    seleniumArgs: args
    }, function (err, child) {

    if (err) {
    return started(err);
    }

    child.stderr.on('data', function(data){
    console.log(data.toString());
    });

    selenium.children.push(child);

    return started(null, selenium);

    });

    };

    function end(dontExit) {

    if (selenium && selenium.children) {

    for (var i = 0; i < selenium.children.length; i++) {
    console.log('Killing selenium with PID:', selenium.children[i].pid);
    selenium.children[i].kill();
    };

    }

    if (xvfb) {
    console.log('Killing xvfb');
    xvfb.stopSync();
    }

    if (dontExit) {
    return;
    }
    else {
    process.exit(1);
    }

    };

    exports.end = end;

    process.on('SIGINT', function(){
    console.log('Process SIGINT');
    end();
    });

    process.on('SIGTERM', function(){
    console.log('Process SIGTERM');
    end();
    });