How can I test http authentication error and fetch the error code with CasperJS (can't use any other tool like SlimerJS) when accessing a web page with wrong credentials?
My code start with:
var casper = require('casper').create();
if (casper.cli.has("ip") === false) {
casper.echo("Usage: casper.js test sample.js --ip=<x.x.x.x>").exit();
}
casper.test.begin('Get info', 1, function suite(test) {
casper.start("http://" + casper.cli.get("ip") + ":xxxx/menta/", function() {
test.assertTitle("Operation & Management", "Correct title");
test.assertExists('form[name="loginForm"]', "login form is found");
this.fill('form[name="loginForm"]', {
'userId': 'root',
'password': '12345678'
}, false);
});
casper.then(function() {
test.assertTextExists("Welcome", "Login");
this.click('a#menu.menu1itemUnSel[tabindex="4"]');
});
...
But of course this fails:
# Get info
PASS Correct title
PASS login form is found
FAIL Login
# type: assertTextExists
# subject: false
# text: "Welcome"
How can I test this with CasperJS?
BTW, in my case i first contact the login page of the web-page to fill in auth. credentials and then a "Welcome" page is loaded. So at the beginning the HTTP status is already 200OK.
I couldn't manage to use the status().currentHTTPStatus
or assertHttpStatus
.
For the moment i changed my code to:
casper.test.begin('Get info', 1, function suite(test) {
casper.start("http://" + casper.cli.get("ip") + ":xxxx/menta/", function() {
test.assertTitle("Operation & Management", "Correct title");
test.assertExists('form[name="loginForm"]', "login form is found");
this.fill('form[name="loginForm"]', {
'userId': 'root',
'password': '12345678'
}, false);
this.waitForText("Welcome", function then() {
this.echo('message sent');
}, function timeout() {
this.die('sending message failed');
});
});