OnetapInc / chromy

Chromy is a library for operating headless chrome. 🍺🍺🍺
MIT License
605 stars 41 forks source link

running multiple instances of chromy parallel #46

Open JOEAV opened 6 years ago

JOEAV commented 6 years ago

Hi , i'm trying to integrate chromy with my jasmine E2E testing environment(headless mode) . this is my chrome conf file .

const Chromy = require('chromy') const logger = require('../spec/specLogger') const specUtils = require('../spec/specUtils') const constants = require('../spec/specConstants') const colors = require('colors'); const timeout = 2 * 60000

const chromy = new Chromy({waitTimeout: timeout, gotoTimeout: timeout, evaluateTimeout: timeout})

const chrome = chromy.chain();

const runnerNames = specUtils.getRunnerNames(); runnerNames.forEach(runnerName => { const urlParams = { query: { jasmineSpec: constants.jasmineSpec + runnerName, }, runnerName: runnerName }

const url = specUtils.createTestUrl(urlParams);
try {
    chrome
        .goto(url)
        .wait(() => window.reporter && window.reporter.finished)
        .evaluate(() => window.reporter.specs())
        .result(specs => formatResults({url, runnerName, specs}))
} catch (e) {
    console.log(e)
}

})

as first look , i thought it should run the tests parallel but it seems it runs sync. any thoughts how can i run the instances parallel ? thanks in advance!

dotneet commented 6 years ago

Hi @JOEAV,

You need to create multiple Chromy instances that have different port to run in parallel.

example:

const Chromy = require('chromy')

let port = 9222
let promises = []
for (let i = 0; i < 4; i++) {
    let chromy = new Chromy({port: port++})
    let p = chromy.chain().goto('http://example.com').end().then(() => chromy.close())
    promises.push(p)
}
Promise.all(promises).then(() => {
  console.log('done')
})
JOEAV commented 6 years ago

thanks very much ill try it and will reply asap ! have a great day