2

I am running my intern unit tests on a Selenium 2 Grid. This works fine when all tests execute normally. Also a run-time error within a test is dealt with properly: the test is reported as failed and other tests continue to execute.

Some other types of errors though are not dealt with nicely:

  • A syntax error is detected by the Istanbul code coverage code and the intern-runner finishes without executing any further tests. The opened browser window on the node is not closed.
  • A dependency error (reference to non existent file) causes an error in the loader. The browser windows stay open and the intern-runner keeps waiting forever.

Since I want to integrate the test execution in the build I prefer that the test finishes and releases its resources, even in case of errors.

I did look at the below sources that suggest that I should set the right timeouts, but without success: https://code.google.com/p/selenium/wiki/Grid2
https://docs.saucelabs.com/reference/test-configuration/#timeouts

Here is my test setup:

  • Node.js – 0.10.28
  • Intern – 1.7.0
  • Selenium 2 Server – 2.42.2
  • ChromeDriver – 2.10
  • Internet Explorer Webdriver – 2.42

I start the hub with:

java -jar selenium-server-standalone-2.42.2.jar -role hub -timeout=20 -browserTimeout=60

I start a node with:

java -jar selenium-server-standalone-2.42.2.jar -role node -hub http://192.168.29.1:4444/grid/register -browser browserName=internetexplorer,version=10,maxInstances=1,platform=VISTA -browser browserName=chrome,version=35,maxInstances=3,platform=VISTA

I then start my tests with:

node node_modules\intern\bin\intern-runner.js config=picard\tests\intern

where this is the content of the intern config file:

define({
    proxyPort: 9000,
    proxyUrl: 'http://192.168.29.1:9000/',

    capabilities: {
      'selenium-version': '2.42.2',
      'max-duration': 30
      //'idle-timeout': 30
    },

    environments: [
        { browserName: 'internetexplorer', version: '10', platform: 'VISTA' },
        { browserName: 'chrome', version: '35', platform: 'VISTA' }
    ],

    maxConcurrency: 3,
    useSauceConnect: false,

    webdriver: {
        host: 'localhost',
        port: 4444
    },

    useLoader: {
        'host-node': 'dojo/dojo',
        'host-browser': 'node_modules/dojo/dojo.js'
    },

    loader: {
      packages: [
        { name: 'cbtree', location: 'external/cbtree' },
        { name: 'dgrid', location: 'external/dgrid' },
        { name: 'put-selector', location: 'external/put-selector' },
        { name: 'xstyle', location: 'external/xstyle' }
      ]
    },

    suites: [
      'picard/tests/crashingtest,
      'picard/tests/passingtest
    ],

    functionalSuites: [ ],

    excludeInstrumentation: /^(node_modules|dojo|dojox|dijit|dgrid|xstyle|external)/
});

How can I configure my tests such that the intern-runner finishes execution and browser windows are closed, even if errors occurred? Regards, Johan

1 Answers1

0

At the end of each test you'll want to call a method that handles the selenium cleanup for you. That way if there is a failure because of an error this method should still be called, and will close the browser for you.

The common name for the method that should handle cleanup is afterEach(function ())

Saeed Gatson
  • 517
  • 5
  • 18