Skip to content

Instantly share code, notes, and snippets.

@kostajh
Last active December 31, 2015 12:49
Show Gist options
  • Save kostajh/7988413 to your computer and use it in GitHub Desktop.
Save kostajh/7988413 to your computer and use it in GitHub Desktop.
// Test Access to the online help section.
// The online help handbook should only be accessible to administrators.
casper.test.begin('Restrict access to online help to Administrators only', function suite(test) {
// Check that online help is not accessible to anonymous user.
casper.start();
casper.setHttpAuth('USERNAME', 'PASSWORD');
casper.thenOpen(link + '/handbook').waitForSelector('.error',
function then() {
this.test.assertTextExists('Access denied', 'Anonymous user denied access to restricted node.');
this.test.assertExists('#user-login', 'Login form present on Access Denied page');
},
function timeout() {
this.capture('/tmp/help-access-denied.png');
this.test.assert(false, 'Loaded user login form and displayed access denied');
}
);
// Logout
casper.thenOpen(link + '/user/logout', function() {
});
// Check that online help is not accessible to School Administrator.
casper.thenOpen(link + '/user').waitForSelector('#user-login',
function then() {
this.fill('form#user-login', {
'name': 'testOnlineHelpSchoolAdmin',
'pass': 'test'
}, true);
},
function timeout() {
this.test.assert(false, 'Failed to load login page.');
}
);
casper.thenOpen(link + '/handbook').waitForText('Access denied',
function then() {
this.test.assertTextExists('Access denied', 'School Administrator user denied access to restricted node.');
},
function timeout() {
this.capture('/tmp/handbook-access-denied.png');
this.test.assert(false, 'Loaded login form present on access denied.');
}
);
// Logout
casper.thenOpen(link + '/user/logout', function() {
});
// Check that online help is accessible to Administrator.
casper.thenOpen(link + '/user').waitForSelector('#user-login',
function then() {
this.test.assertExists('form#user-login', 'Loaded login page.');
},
function timeout() {
this.test.assert(false, 'Loaded login form.');
}
);
casper.then(function() {
this.fill('form#user-login', {
'name': 'testOnlineHelpAdmin',
'pass': 'test'
}, true);
});
// Access handbok as Admin user.
casper.thenOpen(link + '/handbook').waitForText('Online Help',
function then() {
this.test.assertTextExists('Online Help', 'Admin can access Online Help');
this.test.assertDoesntExist('#user-login', 'Login form not present on handbook page');
},
function timeout() {
this.capture('/tmp/online-help-not-loaded.png');
this.test.assert(false, 'Loaded Online Help for administrator.');
}
);
// Logout.
casper.thenOpen(link + '/user/logout', function() {
});
casper.run(function() {
this.test.done();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment