Intern Installation

intern

// Intern - Installation and configuration:

1. Download and unpack selenium server from http://docs.seleniumhq.org/download/
2. Download and unpack selenium drivers
   Firefox: https://github.com/mozilla/geckodriver/releases
   Chrome: https://sites.google.com/a/chromium.org/chromedriver/
   Opera: https://github.com/operasoftware/operachromiumdriver/
   Ghost / PhantomJS: https://github.com/detro/ghostdriver
   Microsoft Edge: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
   HTML Unit: https://github.com/seleniumhq/htmlunit-driver
   Selendroid: http://selendroid.io/
   Appium: http://appium.io/
3. Add the downloaded drivers folder to the PATH environment variable 
4. Install Node (if we do not yet have it installed)
5. Install intern: npm install intern --save-dev
6. Copy the sample configuration file that comes with intern to the root of our 
   project foler.  The sample configuration file can be found inside
   node_module\intern\tests\example.intern.js

Sample intern.config.js:

define({

    // unit tests to run in each browser
    suites: [
        'path/relative/to/configfile/tests/unit/inputValidation',
        'path/relative/to/configfile/tests/unit/sessionManager'
    ],

    // Functional test suite(s) to run in each browser once unit tests are completed
    functionalSuites: [
        'path/relative/to/configfile/functional/suites/changeProfile',
        'path/relative/to/configfile/functional/suites/postStatus'
    ]

});

To run tests, from the root foler of our project:

node_modules\.bin\intern-runner -config=path\to\config leaveRemoteOpen

If we want to run functional tests using Firefox, we may want to create a 
dedicated Firefox profile:

firefox.exe -p

We can create shell scripts to start Selenium and to run our tests:

java -Dos.name=windows -jar selenium-server-standalone-2.44.0.jar
  -Dwebdriver.ie.driver=C:\path\to\IEDriverServer.exe
  -Dwebdriver.firefox.profile=NameOfFirefoxProfile
  -Dwebdriver.log.file="C:\tmp\log.txt"
  -Dwebdriver.firefox.logfile="c:\tmp\fflog.txt"

Sample test suite:

define([
    // base
    'intern!object',
    'intern/chai!assert',

    // helpers
    'require'
], function(
    // base
    registerSuite, assert,

    // helpers
    require
    ) {
    'use strict';

    registerSuite({
        name: 'sample test',
        login: function() {
            return this.remote
                .get(require.toUrl('http://localhost'))
                .then(function() {
                    assert();
                });
        }
    });
});

In the above code, notice that we give the suite a name, using the 'name' 
attribute.  Each function is a test case.  Inside each test case, the 
this.remote object is an object that we can use to interact with the browser.  
It is an instance of loadfoot/Command.

As the list of test cases grows bigger, it is not manageable to define each and 
every test case in the same file, so we should separate each test in a different 
file.  The suite file should look like this:

define([
  // base
  'intern!object',

  // tests:
  'path/relative/to/this/file/sanityTest',
  'path/relative/to/this/file/realityTest'

], function(
  // base
  registerSuite,

  // tests
  sanityTest, realityTest
  ) {
    'use strict';
    registerSuite({
      name: 'load chrome extension',
      // function references instead of function definitions (lambdas)
      'sanity test': sanityTest,
      'reality test': realityTest
    });
});

And each test would be something like:

define([
  // base
  'intern/chai!assert',
  'require',

  // resources
  'path/relative/to/this/file/resources'
], function(
  // base
  assert, require,

  // resources
  resources
  ) {
      'use strict';
      // return the test function from the module
      return function() {
        // we can still refer to this.remote, like in the previous example
        return this.remote
          .get(require.toUrl('http://localhost'))
          .then(function() {
            assert(); // assert something
           });
      }
});

Intern relies heavily on promises.  Most (if not all) of intern/leadfoot 
commands return promises.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License