Note: This tutorial focus on Automate Functional Testing on Ubuntu.
- Install : JDK - Java .
- Download: Selenium server - a
*.jar
file from this Link.- Now, we need something to test our environment. Git Clone: TheIntern-Tutorial project from here.
- Install necessary
npm
packages using following commands :
cd intern-tutorial
npm install --save-dev intern
Sample intern.js
Path : intern-tutorial/tests/intern.js
// Learn more about configuring this file at <https://theintern.github.io/intern/#configuration>.
// These default settings work OK for most people. The options that *must* be changed below are the
// packages, suites, excludeInstrumentation, and (if you want functional tests) functionalSuites
define({
// Default desired capabilities for all environments. Individual capabilities can be overridden by any of the
// specified browser environments in the `environments` array below as well. See
// <https://theintern.github.io/intern/#option-capabilities> for links to the different capabilities options for
// different services.
//
// The port on which the instrumenting proxy will listen
proxyPort: 8080,
// A fully qualified URL to the Intern proxy
proxyUrl: 'http://localhost:8080/',
// Browsers to run integration testing against. Note that version numbers must be strings if used with Sauce
// OnDemand. Options that will be permutated are browserName, version, platform, and platformVersion; any other
// capabilities options specified for an environment will be copied as-is
environments: [
{ browserName: 'firefox', version: '37', platform: [ 'Linux'] },
],
// Maximum number of simultaneous integration tests that should be executed on the remote WebDriver service
maxConcurrency: 2,
// Name of the tunnel class to use for WebDriver tests.
// See <https://theintern.github.io/intern/#option-tunnel> for built-in options
tunnel: 'NullTunnel',
// Configuration options for the module loader; any AMD configuration options supported by the AMD loader in use
// can be used here.
// If you want to use a different loader than the default loader, see
// <https://theintern.github.io/intern/#option-useLoader> for instruction
loaderOptions: {
// Packages that should be registered with the loader in each testing environment
packages: [ { name: 'myPackage', location: '.' } ]
},
// Non-functional test suite(s) to run in each browser
suites: [ /* 'myPackage/tests/foo', 'myPackage/tests/bar' */ ],
// Functional test suite(s) to execute against each browser once non-functional tests are completed
functionalSuites: [ 'tests/functional/index' ],
// A regular expression matching URLs to files that should not be included in code coverage analysis
excludeInstrumentation: /^(?:tests|node_modules)\//
});
Create Test File
Path : intern-tutorial/tests/functional/index.js
Ad following code to index.js
define(function (require) {
var registerSuite = require('intern!object');
var assert = require('intern/chai!assert');
registerSuite({
name: 'index',
'greeting form': function () {
return this.remote
.get(require.toUrl('index.html'))
.setFindTimeout(5000)
.findByCssSelector('body.loaded')
.findById('nameField')
.click()
.type('Elaine')
.end()
.findByCssSelector('#loginForm input[type=submit]')
.click()
.end()
.findById('greeting')
.getVisibleText()
.then(function (text) {
assert.strictEqual(text, 'Hello, Elaine!',
'Greeting should be displayed when the form is submitted');
});
}
});
});
java -jar selenium-server-standalone-2.xx.x.jar
node node_modules/.bin/intern-runner config=tests/intern leaveRemoteOpen
This will open up Firefox and your Test will execute.
Note: Update your Google Chrome, make sure Chrome is >43.0
If you want to run Tests on Chrome, we need Chrome Driver.
Download it from here. (Always use latest)
Unzip & Copy the downloaded ChromeDriver file to this path usr/local/share
java -Dwebdriver.chrome.driver=/usr/local/share/chromedriver -jar selenium-server-standalone-2.xx.x.jar
Change your Intern.js file to run tests on Chrome
environments: [
{ browserName: 'chrome', version: '39', platform: [ 'LINUX'] },
// { browserName: 'firefox', version: '37', platform: [ 'Linux'] },
]
node node_modules/.bin/intern-runner config=tests/intern leaveRemoteOpen
Selenium WebDriver API
To run chrome Driver
You may need to give execute permission to chrome driver