asdf_enel_hak
asdf_enel_hak

Reputation: 7640

Neither waitForAngular nor "then" work as expected

I tried all variations mentioned in this Q&A:

first one

 element(by.css('[ng-click="vm.openNewPage()"]')).click().then(function () {
        expect(element(by.css('[ng-click="vm.submitButtonOfThatPage()"]')).isPresent()).toBe(true);
    });

second one

element(by.css('[ng-click="vm.openNewPage()"]'));
browser.waitForAngular();        
expect(element(by.css('[ng-click="vm.submitButtonOfThatPage()"]')).isPresent()).toBe(true);

third one:

element(by.css('[ng-click="vm.openNewPage()"]'));
browser.sleep(1)
browser.waitForAngular();        
expect(element(by.css('[ng-click="vm.submitButtonOfThatPage()"]')).isPresent()).toBe(true);

none of them passes test: Expected false to be true. except this one with browser.sleep(1000)

element(by.css('[ng-click="vm.openNewPage()"]'));
browser.sleep(1000)
expect(element(by.css('[ng-click="vm.submitButtonOfThatPage()"]')).isPresent()).toBe(true);

Putting some seconds for sleep time is obviously not a solution.

What am I missing or what should I do to evaluate test successfully

Protractor version is: Version 2.1.0 with Jasmine2 framework

This is my command to start test:

C:\projects\eucngts\e2e\app>protractor conf.js --baseUrl=http://localhost:56225/euc/

And these are my relevant codes:

// conf.js
exports.config = {
    directConnect: true,
    seleniumAddress: 'http://localhost:4444/wd/hub',
    framework: 'jasmine2',
    specs: [
        './views/account/loginSpec.js'
        ,'./views/inStudents/inStudentsSpec.js'
    ]
}

//Spec File
describe('Testing Students Page', function () {

    var inStudents: InStudents = require('./inStudents.js');
    var defs: Defs = require('../defs.js');
    it('should check cell 2 2 ', function () {
        inStudents.createNewInStudent()
    });
});

//Testing file

class InStudents {

        createNewInStudent() {
            element(by.css('[ng-click="vm.openNewPage()"]'));
            browser.sleep(1000)
            expect(element(by.css('[ng-click="vm.submitButtonOfThatPage()"]')).isPresent()).toBe(true);
        }
    }
module.exports = new InStudents();

Upvotes: 2

Views: 553

Answers (1)

alecxe
alecxe

Reputation: 473873

Instead of a browser.sleep() delay, make it explicit with browser.wait() and wait for the element to become present:

var submitButton = element(by.css('[ng-click="vm.submitButtonOfThatPage()"]'));
var EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(submitButton), 5000);

Upvotes: 1

Related Questions