Skip to content

Instantly share code, notes, and snippets.

@Risto-Stevcev
Created March 5, 2015 20:46
Show Gist options
  • Save Risto-Stevcev/022a26ede86b8235f0dd to your computer and use it in GitHub Desktop.
Save Risto-Stevcev/022a26ede86b8235f0dd to your computer and use it in GitHub Desktop.
Protractor issue #1895 - Cannot start webdriver as a process
module.exports = function (grunt) {
grunt.registerMultiTask('foo', 'foo bar baz', function () {
var done = this.async()
var webdriver = grunt.util.spawn({
opts: { stdio: 'pipe' },
cmd: 'node',
args:['./node_modules/.bin/webdriver-manager', 'start']
})
webdriver.stdout.pipe(process.stdout)
webdriver.stderr.pipe(process.stderr)
function runProtractor() {
var ptor = grunt.util.spawn({
opts: { stdio: 'pipe' },
cmd: 'node',
args: ['./node_modules/.bin/protractor', '--seleniumAddress', 'http://localhost:4444/wd/hub', '--specs', 'tspec.js', '--browser', 'firefox']
},
function(error, result, code) {
done()
})
ptor.stdout.pipe(process.stdout)
ptor.stderr.pipe(process.stderr)
}
var webdriverStarted = false
webdriver.stderr.on('data', function(data) {
if (!webdriverStarted && (data && data.toString().match(/Started .*Server/))) {
webdriverStarted = true
runProtractor()
}
})
})
}
module.exports = function(grunt) {
grunt.initConfig({
foo: {
bar: {
options: {}
}
}
})
grunt.loadTasks('tasks')
grunt.registerTask('default', ['foo'])
}
{
"name": "tmp",
"version": "1.0.0",
"description": "",
"main": "proc.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"grunt": "^0.4.5",
"grunt-cli": "^0.1.13",
"protractor": "1.8.0"
}
}
var spawn = require('child_process').spawn
var webdriver
(function runWebdriver() {
webdriver = spawn('node', ['./node_modules/.bin/webdriver-manager', 'start'])
webdriver.stdout.pipe(process.stdout)
webdriver.stderr.pipe(process.stderr)
})()
function runProtractor() {
var ptor = spawn('node', ['./node_modules/.bin/protractor', '--seleniumAddress', 'http://localhost:4444/wd/hub', '--specs', 'tspec.js', '--browser', 'firefox'])
ptor.stdout.pipe(process.stdout)
ptor.stderr.pipe(process.stderr)
}
var webdriverStarted = false
webdriver.stderr.on('data', function(data) {
if (!webdriverStarted && (data && data.toString().match(/Started .*Server/))) {
webdriverStarted = true
runProtractor()
}
})
describe('it', function() {
beforeEach(function() {
browser.get('https://www.angularjs.org')
})
it('should sleep', function() {
browser.sleep(1000)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment