NPM for Karate
npm install @karatelabs/karatetest.js:``js`
#! /usr/bin/env node
const karate = require('@karatelabs/karate');
karate.exec();
And in package.json (use the latest version from npm):
`json`
{
"scripts": {
"test": "node test.js"
},
"devDependencies": {
"@karatelabs/karate": "^0.2.2"
}
}
When you run npm install, jbang and other Karate dependencies needed will be installed via jbang-npm.
And to run a single test:
``
npm run test karate/httpbin.feature
Or to run all tests in a folder:
``
npm run test karate
failing to complete and without any errors shown.Please do contribute if you can and improve how JavaScript projects can integrate smoothly with Java projects !
As a workaround, please install JBang manually and re-try the
npm install step.Setting Karate Version
To use a specific version of Karate, just set
karate.version before calling karate.exec():`js
#! /usr/bin/env node
const karate = require('@karatelabs/karate');
karate.version = '1.2.0';
karate.exec();
`CLI Reference
All Karate capabilities can be invoked by the command-line.The most common needs are to:
* run feature-file(s) or all feature-files in a folder as Karate tests
* start an API mock-server
The complete documentation can be found here.
You can also use the
--help command-line option to see all the possible options and brief descriptions on the console.$3
karate-config.js file in the current working directory.But if you need to point to a different directory, you can set
karate.config.dir before calling karate.exec()To pass arguments to the JVM use the jvm object
karate.jvm.argsCLI options can be passed as a string to the
karate.exec('-T=5') method.`js
#! /usr/bin/env node
const karate = require('@karatelabs/karate');
karate.config.dir = '/users/myname/some/dir';
karate.jvm.args = -Dlogback.configurationFile=${__dirname}/logback-test.xml;
karate.exec("-T=5");
``For teams that want to customize the Java classpath by adding libraries or custom-code, please refer to the wiki: Custom Fat JAR. This may be easier to achieve by using Maven to prepare a Docker image, which can then be used by teams on the command-line without needing NPM, Java or Karate - and only Docker is a pre-requisite.
If you want to use additional Java libraries or custom code and avoid Maven and Java dev-tools, refer to this example: Using Java Libraries with NPM.