Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 0.9.0 stops working with phantomjs setup #1005

Closed
le0pard opened this issue Jun 6, 2016 · 6 comments
Closed

Version 0.9.0 stops working with phantomjs setup #1005

le0pard opened this issue Jun 6, 2016 · 6 comments
Labels

Comments

@le0pard
Copy link

le0pard commented Jun 6, 2016

Hello. I trying to read changelog between 0.8.18 and 0.9.0 and trying to understand, what changes influence on working environment. What I have:

phantomjs 2.1.1
nightwatch 0.8.18

nightwatch.json

{
  "src_folders" : ["tests/features"],
  "output_folder" : "tests/reports",
  "custom_commands_path" : "tests/commands",
  "custom_assertions_path" : "tests/assertions",
  "page_objects_path" : "tests/page_objects",
  "globals_path" : "tests/globals.js",

  "selenium" : {
    "start_process" : false,
    "server_path" : "",
    "log_path" : false,
    "host" : "127.0.0.1",
    "port" : 4444,
    "cli_args" : {
      "webdriver.chrome.driver" : "",
      "webdriver.ie.driver" : ""
    }
  },

  "test_settings" : {
    "default" : {
      "skip_testcases_on_fail": false,
      "launch_url" : "http://localhost",
      "selenium_port"  : 4444,
      "selenium_host"  : "localhost",
      "silent": true,
      "screenshots" : {
        "enabled": true,
        "on_failure": true,
        "on_error": false,
        "path" : "tests/screenshots"
      },
      "desiredCapabilities": {
        "browserName" : "phantomjs",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      }
    }
  }
}

and gulp task:

var gulp = require('gulp')
var childProcess = require('child_process')
var net = require('net')
var nightwatch = require('nightwatch')
var runSequence = require('run-sequence')

function wrapWithServer(serverProcess, port, payload) {
  process.on('exit', function() {
    serverProcess.kill('SIGTERM')
  })
  var waitingSocket = new net.Socket()
  waitingSocket.on('connect', function() {
    waitingSocket.end()
    payload(function(cb) {
      serverProcess.on('exit', cb)
      serverProcess.kill('SIGTERM')
    })
  })
  waitingSocket.on('error', function() {
    setTimeout(function() {
      waitingSocket.connect(port)
    }, 100)
  })
  waitingSocket.connect(port)
}

gulp.task('nightwatch-tests', function(done) {
  var nodePort = 31337
  var apiPort = 31338
  var seleniumPort = 4444
  var selenium = null

  if (process.env.NIGHTWATCH_SELENIUM) {
    selenium = childProcess.spawn('java',
      ['-jar', process.env.NIGHTWATCH_SELENIUM],
      {
        stdio:  'inherit',
        stderr: 'inherit'
      }
    )
  } else {
    selenium = childProcess.spawn(process.env.PHANTOMJS_BIN || '/usr/local/bin/phantomjs',
      ['--webdriver=' + seleniumPort, '--webdriver-loglevel=WARN', '--load-images=no', '--ignore-ssl-errors=yes'],
      {
        stdio:  'inherit',
        stderr: 'inherit'
      }
    )
  }

  var appServer = childProcess.spawn('node',
    ['build/server'],
    {
      env: {
        APP_LOCALE: 'en',
        NODE_ENV:   'test',
        PORT:       nodePort,
        WEBAPI_URL: 'http://localhost:' + apiPort,
        PATH:       process.env.PATH,
        NODE_PATH:  process.env.NODE_PATH
      },
      stdio:  'inherit',
      stderr: 'inherit'
    }
  )
  wrapWithServer(appServer, nodePort, function(nodeDone) {
    wrapWithServer(selenium, seleniumPort, function(phantomDone) {
      nightwatch.cli(function(argv) {
        argv.retries = 2 // make 2 retries for failed tests
        argv.suiteRetries = 2 // make 2 retries for failed suite
        nightwatch.runner(argv, function(finished) {
          nodeDone(function() {
            phantomDone(function() {
              done(finished ? 0 : 1)
            })
          })
        })
      })
    })
  })
})

And this work without any problem. If I trying to update to nightwatch 0.9.0 - I get, what after nightwatch.runner I get zero output and don't see any runing process, except phantomjs and node server, which I run before this call.

What configuration is missed for 0.9.0 version?

@beatfactor
Copy link
Member

is it possible to try without gulp?

@le0pard
Copy link
Author

le0pard commented Jun 7, 2016

@beatfactor From command line works without any problem.

$ /usr/local/bin/phantomjs --webdriver=4444 --webdriver-loglevel=WARN
$ PORT=31337 WEBAPI_URL=http://localhost:31338 node build/server.js
$ ./node_modules/.bin/nightwatch tests/features/affiliate.js                                                                                                                                                     ruby-2.3.0 redesign 30bed90

[Affiliate] Test Suite
==========================

Running:  begin
No assertions ran.

Running:  handleAffiliate
 ✔ Element <.page-content.homepage> was present after 21 milliseconds.
 ✔ Testing if the URL equals "http://localhost:31337/".
 ✔ Checking for missing or unexpected API calls
 ✔ Checking that no JS errors happened

OK. 4 assertions passed. (4.69s)

OK. 4  total assertions passed. (4.85s)

@le0pard
Copy link
Author

le0pard commented Jun 7, 2016

Looks like I found difference. From command line run we have this argv after Nightwatch.cli

{ _: [],
  config: './nightwatch.json',
  c: './nightwatch.json',
  output: 'tests_output',
  o: 'tests_output',
  reporter: 'junit',
  r: 'junit',
  env: 'default',
  e: 'default',
  filter: '',
  f: '',
  tag: '',
  a: '',
  '$0': '/Users/leo/.nvm/versions/node/v4.4.3/bin/node ./node_modules/.bin/nightwatch' }

Inside gulp:

{ _: [ 'nightwatch' ],
  config: './nightwatch.json',
  c: './nightwatch.json',
  output: 'tests_output',
  o: 'tests_output',
  reporter: 'junit',
  r: 'junit',
  env: 'default',
  e: 'default',
  filter: '',
  f: '',
  tag: '',
  a: '',
  '$0': '/usr/local/bin/gulp' }

As I understand inside gulp in some case changed $0 and _. How to fix this?

@beatfactor
Copy link
Member

hmm yeah. thanks for looking into this. I will try to post a fix soon.

@le0pard
Copy link
Author

le0pard commented Jun 7, 2016

Thanks. I just add this to code and it start working.

argv['$0'] = '/Users/leo/.nvm/versions/node/v4.4.3/bin/node ./node_modules/.bin/nightwatch'
argv['_'] = []

But will wait for your fix, because it is very dirty changes.

@beatfactor beatfactor added the bug label Jun 7, 2016
@beatfactor beatfactor changed the title Version 0.9.0 stop working with phantomjs setup Version 0.9.0 stops working with phantomjs setup Jun 13, 2016
@le0pard
Copy link
Author

le0pard commented Jun 15, 2016

@beatfactor confirmed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants