Testing framework integration for Jasmine and Webdriver.
Jasmine is an amazing testing framework, just as Webdriver is a fantastic browser automation tool. These two pieces of software haven't worked so amazingly well together, until now.
Injecting tests etc. into a Webdriver session is not an amazingly complicated task, but why do all that work for a single project? JasDriver takes care of that mess for you, by proving a simple interface to configure your testing needs (specs, webdriver config).
JasDriver needs a simple configuration file, called jasdriver.config.js
:
module.exports = {
closeDriverOnFinish: true,
exitOnFinish: true,
junitOutput: "./junit-report.xml",
runnerDir: ".",
runnerFilename: "_SpecRunner.html",
specs: [],
specFilter: function(filename) { return /\.spec\.js$/.test(filename); },
webdriver: null,
webdriverBrowser: "chrome"
};
Most of the configuration can be left alone in any normal situation. JasDriver will automatically create a webdriver session for you, with Chrome, if you don't configure a thing.
To get off the ground, simply pass in your spec filenames (absolute paths).
You can also use a different name for the config file, providing you pass its path into the jasdriver cli command. JasDriver looks for the config file in the current directory.
Close the webdriver instance upon finishing the tests. Runs webdriver.quit()
under the hood.
Allow JasDriver to run process.exit()
when finished (used for returning non-zero exit codes for failures).
Output results to a JUnit XML file - the path for the output file.
The directory to place the spec-runner in.
The filename of the spec-runner.
An array of absolute paths to the spec files you want to include. These do not only have to contain tests, they can be helpers and assets also. These are executed in order.
Paths can also be directories, which are scanned recursively.
Provide a filtering function to filter each spec by its filename. The default filter function is function() { return true; }
.
Provide a webdriver instance for JasDriver to use. This is set to null
by default, so that JasDriver will build its own instance using webdriverBrowser
as the browser type.
If JasDriver builds its own instance of webdriver, it will use this setting as the browserName
value when initialising.
With a few easy steps, it's easy to use JasDriver in your project.
Firstly, install JasDriver:
npm install jasdriver --save-dev
Jump into your package.json
and add a test script:
{
"name": "MyApp",
"scripts": {
"test": "jasdriver"
}
}
Create a tests
folder - you'll place your jasmine test files in here.
Next, add a JasDriver config file to the root directory of your project:
const path = require("path");
module.exports = {
specs: [
path.resolve(__dirname, "tests")
]
};
Once you've added a test to your tests
directory, simply run npm test
in your project root to see the tests run!