Question

I have been playing with Intern and made my tests work in the browser. To better integrate with my current workflow I'm trying to run my tests through grunt with phantomjs. However all my attempts have failed. I've been looking at this question as a reference Intern WebDriver and PhantomJS but can't figure out all of the steps to make it work.

First of all: Is it even possible to run the tests through grunt and phantomjs?

A little bit of info:

  • I don't want/can't connect to Sauce Labs or a Selenium testing environment.
  • I want to test browser code while having jQuery as a shimmed dependency
  • I have Grunt 0.4.1 and phantomjs 1.9.1 installed
  • I'm not testing any ajax request (as the linked question is having problem with)
  • I'm not familiar with neither Selenium nor Sauce Lab

If it is possible to test through grunt and phanomjs, how would I go about doing it?

I guess that I have to start the GhostDriver

phantomjs --webdriver=8910

But then what are the important pieces of info in the Intern config to make this work?

define({
  proxyPort: 9000,
  proxyUrl: 'http://localhost:9000/',
  environments: [
    {
      browserName: 'phantom',
      version: '1.9.0',
      platform: 'Linux'
    }
  ],
  webdriver: {
    host: 'localhost',
    port: 8910
  },
  maxConcurrency: 3,
  useSauceConnect: false,
  // ...
});

How does the environments browserName map to phantomjs? I've tried the browserNames 'phantom' as well as 'phanomjs' with different versions and platforms (running Mac 10.7)

My Gruntfile section for intern looks like:

intern: {
    phantom: {
        options: {
            config: 'tests/intern',
            reporters: ['webdriver']
        }
    }
}

Running this setup without any test-suite that includes browser code outputs 'ReferenceError: document is not defined' in 'node_modules/intern/lib/reporters/webdriver.js:41:19'

Adding browser tests gives 'ReferenceError: window is not defined' in 'src/vendor/jquery/jquery-1.9.1.js:9597:5'

Running it through node gives the same 'window is not defined' error.

node node_modules/intern/client.js config=tests/intern

What am I doing wrong/missing here?

Was it helpful?

Solution

There are two problems with your Gruntfile configuration:

  1. The default run type for the Grunt task is 'client', which means it runs the Node.js client by default, not the test runner. You need to set runType: 'runner' in your Gruntfile options to run tests against your specified environments.
  2. The webdriver reporter is for use in a browser client only and is specified automatically by the test runner when it is needed. You should typically never use it directly. The reporter you specify in the Gruntfile should be the one you want the test runner to use; the console default is usually appropriate.

These two things in combination mean that you’ve configured Intern to try to use a reporter that only works in a browser in conjunction with the test runner inside the Node.js client, hence the error. Once corrected, the remaining configuration should work properly to run on PhantomJS, assuming it is already running on localhost at port 8910.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top