Skip to content

Instantly share code, notes, and snippets.

@binhqd
Last active June 20, 2016 08:47
Show Gist options
  • Save binhqd/daf57a2913c719464a541de833541111 to your computer and use it in GitHub Desktop.
Save binhqd/daf57a2913c719464a541de833541111 to your computer and use it in GitHub Desktop.
Sample BDD test preparation
//var screenshot = require('./../screenshot');
describe('Test Login page', function() {
beforeEach(function() {
// doing something here
});
var width = 1600;
var height = 2400;
browser.driver.manage().window().setSize(width, height);
// browser.driver.manage().window().maximize();
// clean up
browser.manage().deleteAllCookies();
describe('Testing Sign In function', function() {
it('Homepage MUST be accessibled.', function() {
browser.get("http://ateam.greenglobal.vn:85/");
});
it('Click on "Sign in" will bring up a popup.', function() {
var btnLogin = by.css('.login-bt');
browser.driver.findElement(btnLogin).then(function(elem) {
elem.click().then(function() {
expect(element.all(by.css('.modal-popup-content')).count()).toEqual(1);
});
});
});
browser.sleep(50);
it("An error message: 'Email for sign in is required' will appear if user submit with no data or user enter valid other fields but not enter Email field.", function() {
var btnLogin = by.css('.btn-orange-sm');
browser.driver.findElement(btnLogin).then(function(elem) {
elem.click().then(function() {
browser.sleep(50);
expect(element.all(by.css('.toast-warning')).count()).toEqual(1);
expect(element(by.css('.toast-warning')).getText()).toMatch('Email for sign in is required');
});
});
});
it("If user not enter password, a message will appear: 'Password is required'", function() {
element(by.model('signInCtrl.account.username')).sendKeys('namdh@greenglobal.vn');
var btnLogin = by.css('.btn-orange-sm');
browser.driver.findElement(btnLogin).then(function(elem) {
elem.click().then(function() {
browser.sleep(50);
expect(element.all(by.css('.toast-warning')).count()).toEqual(1);
expect(element(by.css('.toast-warning')).getText()).toMatch('Password is required');
});
});
});
it("If user enter invalid email, a message will appear: 'Please enter a valid email address'", function() {
element(by.model('signInCtrl.account.username')).clear().sendKeys('namdh@greenglobal');
element(by.model('signInCtrl.account.password')).sendKeys('12345678');
var btnLogin = by.css('.btn-orange-sm');
browser.driver.findElement(btnLogin).then(function(elem) {
elem.click().then(function() {
browser.sleep(50);
expect(element.all(by.css('.toast-warning')).count()).toEqual(1);
expect(element(by.css('.toast-warning')).getText()).toMatch('Please enter a valid email address');
});
});
});
it("If user enter an invalid password but email is valid, a error message still appears: 'Email or pasword is incorrect'", function() {
element(by.model('signInCtrl.account.username')).clear().sendKeys('namdh@greenglobal.vn');
element(by.model('signInCtrl.account.password')).clear().sendKeys('1234567');
var btnLogin = by.css('.btn-orange-sm');
browser.driver.findElement(btnLogin).then(function(elem) {
elem.click().then(function() {
browser.sleep(50);
expect(element.all(by.css('.toast-error')).count()).toEqual(1);
expect(element(by.css('.toast-error')).getText()).toMatch('Email or password is incorrect.');
});
});
});
it("If user enters valid email and password then the login will be successful ", function() {
element(by.model('signInCtrl.account.username')).clear().sendKeys('namdh@greenglobal.vn');
element(by.model('signInCtrl.account.password')).clear().sendKeys('12345678');
var btnLogin = by.css('.btn-orange-sm');
browser.driver.findElement(btnLogin).then(function(elem) {
elem.click().then(function() {
browser.sleep(50);
expect(element.all(by.css('.iconateam-user')).count()).toBeGreaterThan(0);
});
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment