CasperJS is a navigation scripting and testing utility for PhantomJS and SlimerJS written in JavaScript. CasperJS-as-a-Service makes CasperJS available as a web service. Dockerfile included.
The following command makes CasperJS-as-a-Service available at 127.0.0.1:31337
:
export HOSTPORT=31337
docker run -d --name casperjs -p 127.0.0.1:$HOSTPORT:80 metmajer/casperjs-as-a-service
CasperJS-as-a-service makes a /job
endpoint available, which serves requests via HTTP POST:
curl -f -H "Content-Type: application/json" http://127.0.0.1:$HOSTPORT/job -d '{
"git": {
"uri": "https://github.com/casperjs/casperjs.git",
"contextDir": "samples"
},
"casper": {
"script": "dynamic.js"
}
}'
CasperJS-as-a-service makes a /job
endpoint available, which serves requests via HTTP POST:
curl -f -H "Content-Type: application/json" http://127.0.0.1:$HOSTPORT/job -d '{
"git": {
"uri": "https://github.com/casperjs/casperjs.git",
"contextDir": "samples"
},
"casper": {
"mode": "test",
"script": "googletesting.js"
}
}'
You can advise CasperJS-as-a-Service to run all tests inside git.contextDir
when casper.mode
is set to test
and casper.script
is left undefined
.
curl -f -H "Content-Type: application/json" http://127.0.0.1:$HOSTPORT/job -d '{ \
"git": {
"uri": "https://github.com/casperjs/casperjs.git",
"contextDir": "samples"
},
"casper": {
"mode": "test"
}
}'
Note that this will only work with directories that do not contain navigation scripts (with CasperJS, navigation scripts and tests service a different purpose and have to be invoked in different ways). In the above example, casperjs will fail with the following error:
Test file: /tmp/92e6b4e3-4eb2-4838-a13d-a2f6c1b6b73c/samples/bbcshots.js
FAIL Fatal: you can't override the preconfigured casper instance in a test environment.
# type: error
# file: /tmp/92e6b4e3-4eb2-4838-a13d-a2f6c1b6b73c/samples/bbcshots.js
# subject: false
# error: "Fatal: you can't override the preconfigured casper instance in a test environment."
# stack: in create() in phantomjs://platform/casper.js:54
git.uri
: a URI to a Git repository (required)git.branch
: a branch name (optional, defaults tomaster
)git.contextDir
: a relative path to a directory inside the (cloned) repo (optional, defaults to/
)
casper.options
: a string containing options to be passed tocasperjs
(optional)casper.mode
: setting this totest
will result in an execution ofcasperjs test
(optional)casper.script
: a path fragment to a script underneathgit.contextDir
(required if mode is nottest
)
Licensed under the MIT License. See the LICENSE file for details.