Skip to content

Instantly share code, notes, and snippets.

@carrodher
Created November 12, 2018 18:57
Show Gist options
  • Save carrodher/11eb5ea2f6d705cfeeb8fb9d51f1d3c4 to your computer and use it in GitHub Desktop.
Save carrodher/11eb5ea2f6d705cfeeb8fb9d51f1d3c4 to your computer and use it in GitHub Desktop.
Login test
casper.options.viewportSize = {width: 1280, height: 639};
const testingMode = process.env.TESTING_MODE;
const httpUrl = 'http://cms-' + testingMode + '-node:3000'
casper.test.begin('Login Test', function(test) {
casper.start(httpUrl);
casper.waitForText('Welcome to my new Blog', function() {
this.test.assertTextExists('Welcome to my new Blog', '"Welcome to my new Blog" text appears');
this.capture('welcome.png');
});
casper.waitUntilVisible('a.login-link', function() {
this.test.assertVisible('a.login-link', 'Login link is visible. Clicking...');
this.capture('login.png');
this.click('a.login-link');
});
casper.waitUntilVisible('form[action="/login"]', function() {
this.test.assertVisible('form[action="/login"]', 'Form is visible. Filling...');
this.capture('formEmpty.png');
this.fillSelectors('form[action="/login"]', {
'input#username': 'admin',
'input#password': '12345',
}, false);
this.capture('formFilled.png');
this.test.assertVisible('input[value="Log In"]', 'Log In button is visible. Clicking...');
this.click('input[value="Log In"]');
});
casper.waitForText('My Blog!', function() {
this.test.assertTextExists('My Blog!', 'Logged in successfully!');
this.capture('loggedIn.png');
});
casper.run();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment