title: Using PhantomJS with Karma (Win7 x64)
body: <p>Does anyone have a simple getting started guide on how to configure Karma to use PhantomJS?</p>
  
  <p>Using the phonecat sample, I have Karma running with Chrome fine and although the Karma docs mention PhantomJS (which I now have installed) I can't figure out how to amend the config file to get it to run.</p>
  
  <p>I've tried putting PhantomJS in the the <code>browsers</code> array of testacular.conf.js but I get;</p>
  
  <pre><code> { [Error: spawn OK] code: 'OK', errno: 'OK', syscall: 'spawn' }
  </code></pre>
  
  <p>Which I think means it's launching OK but it appears to me that (as a PhantomJS noob) it requires a different command line. I've also downloaded <a href="https://github.com/karma-runner/karma-phantomjs-launcher" rel="noreferrer">phantomjs-launcher</a> but it's not obvious how to use that.</p>
  
  <p>(I'm running Windows 7 64-Bit if that makes a difference.)</p>
  
  <h3>test.bat</h3>
  
  <pre><code>@echo off
  
  REM Windows script for running unit tests
  REM You have to run server and capture some browser first
  REM
  REM Requirements:
  REM -NodeJS (http://nodejs.org/)
  REM -Testacular (npm install -g karma)
  
  set BASE_DIR= % ~dp0
  karma start "%BASE_DIR%\..\config\testacular.conf.js" %*
  </code></pre>
  
  <h3>testacular.conf.js</h3>
  
  <pre><code>basePath = '../';
  
  files =[
    JASMINE,
    JASMINE_ADAPTER,
    'app/lib/angular/angular.js',
    'app/lib/angular/angular-*.js',
    'test/lib/angular/angular-mocks.js',
    'app/js/**/*.js',
    'test/unit/**/*.js'
  ];
  
  autoWatch = true;
  
  browsers =['Chrome', 'phantomjs'];
  
  junitReporter = {
      outputFile: 'test_out/unit.xml',
      suite: 'unit'
  };
  </code></pre>
  
  <p>According to procmon.exe PhantomJS wasn't launching at all, so to circumvent environmental issues, I've since amended my config thus;</p>
  
  <pre><code>browsers = ['Chrome','%USERPROFILE%\\AppData\\Roaming\\npm\\phantomjs.cmd'];
  </code></pre>
  
  <p>where <code>%userprofile%</code> is expanded, which seems to launch it, but now I get this;</p>
  
  <pre><code>INFO [launcher]: Starting browser %USERPROFILE%\AppData\Roaming\npm\phantomjs.cmd
  ERROR [launcher]: Cannot start %USERPROFILE%\AppData\Roaming\npm\phantomjs.cmd
          Can't open 'http://localhost:9876/?id=16572367'
  
  events.js:72
          throw er; // Unhandled 'error' event
            ^
  Error: spawn OK
      at errnoException (child_process.js:975:11)
      at Process.ChildProcess._handle.onexit (child_process.js:766:34)
  </code></pre>
  
  <p>That error seems to be coming from PhantomJS.exe now.</p>