Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up PhantomJs with Protractor does not work

i'm starting my adventure with Protractor & Jasmine & PhantomJS. What I wanted to achieve is to use PhantomJS to run tests from ProtractorDemo. But I failed, and I don't know why. Where are exact steps:

I've installed protractor-demo (https://github.com/juliemr/protractor-demo)

git clone https://github.com/juliemr/protractor-demo.git
cd protractor-demo
npm install

Then I've installed phantomjs:

npm install --save-dev phantomjs

Then I've updated configuration (based on http://angular.github.io/protractor/#/browser-setup):

capabilities: {
  'browserName': 'phantomjs',

  /* 
   * Can be used to specify the phantomjs binary path.
   * This can generally be ommitted if you installed phantomjs globally.
   */
  'phantomjs.binary.path':'./node_modules/phantomjs/bin/phantomjs',

  /*
   * Command line arugments to pass to phantomjs. 
   * Can be ommitted if no arguments need to be passed. 
   * Acceptable cli arugments: https://github.com/ariya/phantomjs/wiki/API-Reference#wiki-command-line-options
   */
  'phantomjs.cli.args':['--logfile=PATH', '--loglevel=DEBUG']
}

Full config file looks like this:

// Tests for the calculator. exports.config = {   seleniumAddress: 'http://localhost:4444/wd/hub',

  specs: [
    'spec.js'   ],

  capabilities: {
      'browserName': 'phantomjs',

      /* 
       * Can be used to specify the phantomjs binary path.
       * This can generally be ommitted if you installed phantomjs globally.
       */
      'phantomjs.binary.path': './node_modules/phantomjs/bin/phantomjs',

      /*
       * Command line arugments to pass to phantomjs. 
       * Can be ommitted if no arguments need to be passed. 
       * Acceptable cli arugments: https://github.com/ariya/phantomjs/wiki/API-Reference#wiki-command-line-options
       */
      'phantomjs.cli.args': ['--logfile=PATH', '--loglevel=DEBUG']   } };

Then I've executed commands from tutorial:

.\node_modules\.bin\webdriver-manager update

I've started WebDriver and web server:

.\node_modules\.bin\webdriver-manager start
npm start

The output from this command was:

Using the selenium server at http://127.0.0.1:4444/wd/hub
Server running at http://localhost:3456

And final step:

node_modules\.bin\protractor test\conf.js

and the output form other webdriver-manager console window was:

15:23:10.181 INFO - Executing: [new session: Capabilities [{phantomjs.binary.path=./node_modules/phantomjs/bin/phantomjs, count=1, browserName=phantomjs, phantomjs.cli.args=[--logfile=PATH, --loglevel=DEBUG]}]])
15:23:10.192 INFO - Creating a new session for Capabilities [{phantomjs.binary.path=./node_modules/phantomjs/bin/phantomjs, count=1, browserName=phantomjs, phantomjs.cli.args=[--logfile=PATH, --loglevel=DEBUG]}]
15:23:10.203 INFO - executable: d:\dev\protractor-demo\.\node_modules\phantomjs\bin\phantomjs
15:23:10.203 INFO - port: 44410
15:23:10.203 INFO - arguments: [--logfile=PATH, --loglevel=DEBUG, --webdriver=44410, --webdriver-logfile=d:\dev\protractor-demo\phantomjsdriver.log]
15:23:10.204 INFO - environment: {}

But nothing happens. I see not result of executed tests. Is there something I'm missing? When I change the browser from phantomjs to chrome, I see test results.

like image 881
dragonfly Avatar asked Oct 05 '14 13:10

dragonfly


1 Answers

In fact you don't need to run:

.\node_modules\.bin\webdriver-manager update

nor:

.\node_modules\.bin\webdriver-manager start

Instead you could start a ghost driver with the following command (9515 will be the port in which the driver will run) by running:

phantomjs --webdriver=9515

In addition to it you should modify your config file in order to let protractor know where the driver will be found. For your case, your config file should look like the following:

exports.config = {   
    seleniumAddress: 'http://localhost:9515',

    specs: ['spec.js'],

    capabilities: {
        'browserName': 'phantomjs',

         /* 
         * Can be used to specify the phantomjs binary path.
         * This can generally be ommitted if you installed phantomjs globally.
         */
         'phantomjs.binary.path': './node_modules/phantomjs/bin/phantomjs',

         /*
         * Command line arugments to pass to phantomjs. 
         * Can be ommitted if no arguments need to be passed. 
         * Acceptable cli arugments: https://github.com/ariya/phantomjs/wiki/API-Reference#wiki-command-line-options
         */
         'phantomjs.cli.args': ['--logfile=PATH', '--loglevel=DEBUG']   
      }
};

And then you will be able to run the tests by running:

node_modules\.bin\protractor test\conf.js
like image 160
Julio Avatar answered Oct 18 '22 23:10

Julio