I'm writing a test where I should log in. It passed given the proper inputs but when I change its password/username to garbage, it still passes. I'm new to this and I really think I missed something here. Please help me out?
Here is my code:
-------------------[config.js]-------------------------
'use strict';
var config = {
seleniumAddress : 'http://localhost:4444/wd/hub',
specs : [ 'test/e2e/features/login/login.feature' ],
baseUrl : http://someUrl.com,
capabilities : {
browserName : 'chrome'
},
onPrepare : function () {
var width = 1024;
var height = 600;
global.dv = browser.driver;
dv.manage().window().setSize( width, height );
// This will tell the Protractor not to wait for angular
global.isAngularSite = function(flag) {
browser.ignoreSynchronization = !flag;
};
},
framework : 'cucumber',
cucumberOpts : {
// define your step definitions in this file
require : 'test/e2e/features/login/spec.js',
format : 'pretty'
}
};
exports.config = config;
-------------------[login.feature]-------------------------
Feature: Login
As a user, I should be able to have login creadentials so that I can login to the system
Scenario: Valid login creadentials
Given I login using valid creadentials
Then I should be logged in
-------------------[page.js]-------------------------
'use strict';
( function () {
var navigate = function () {
browser.get( '' );
};
var login = function ( username, password ) {
this.username.sendKeys( username );
this.password.sendKeys( password );
this.loginButton.click();
};
var LoginPage = function () {
this.username = dv.findElement( by.css( '[data-ptor="loginEmail"]' ) );
this.password = dv.findElement( by.css( '[data-ptor="loginPassword"]' ) );
this.loginButton = dv.findElement( by.css( '[data-ptor="loginButton"]' ) );
};
LoginPage.prototype.navigate = navigate;
LoginPage.prototype.login = login;
module.exports = LoginPage;
} )();
-------------------[homepage.js]-------------------------
'use strict';
( function () {
var navigate = function () {
browser.get( '/#home' );
};
var HomePage = function () {
this.homeIndicator = dv.getCurrentUrl();
};
HomePage.prototype.navigate = navigate;
module.exports = HomePage;
} )();
-------------------[spec.js]-------------------------
'use strict';
var LoginPage = require( '../../features/login/page.js' );
var HomePage = require( '../../features/homepage/homepage.js' );
var chai = require( 'chai' );
var chaiAsPromised = require( 'chai-as-promised' );
chai.use( chaiAsPromised );
var expect = chai.expect;
module.exports = function () {
var loginPage;
var homePage;
this.Before( function ( callback ) {
loginPage = new LoginPage();
homePage = new HomePage();
isAngularSite(false);
loginPage.navigate();
callback();
} );
this.After( function ( callback ) {
//logout
callback();
} );
// First Scenario
this.Given( 'I login using valid creadentials', function ( callback ) {
loginPage.login( 'username', 'password' ); //valid creadential
callback();
} );
this.Then( 'I should be logged in', function ( callback ) {
expect(homePage.homeIndicator).toEqual('http://someUrl.com/#home');
callback();
} );
};