2

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();
    } );

};
  • this is by the way a test for a non-angular app.. – Marianne Jun 21 '15 at 22:53
  • Maybe the check you are doing is not ok and it applies for both cases valid/invalid. I think you should review the 'I should be logged in' step and see what you validate. – lauda Aug 26 '16 at 9:24
  • what is the application state after performing these steps? Does it show the home page even on entering incorrect credentials? Or shows any errors? – Vishal Aggarwal Jul 28 '18 at 16:21
-2

Instead of using callback(), try using setTimeout(callback, 1000);

  • 4
    Could you please add some explanation about why doing this will help the OP? – Kate Paulk Nov 23 '16 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.