2

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();
Community
  • 1
  • 1
asdf_enel_hak
  • 7,474
  • 5
  • 42
  • 84
  • Do yourself a favor, and assign a semantic ID to your buttons instead of locating them by whatever you put inside ng-click. We can't help without the code. – JB Nizet Sep 01 '15 at 21:53
  • 1
    Done what. I still don't have any idea of what the button does. You've just changed the name of the functions. – JB Nizet Sep 01 '15 at 22:01

1 Answers1

1

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);
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Thanks @alecxe a lot. It seems `browser.wait()` is deprecated with `proctrator 2.1.0`, is that right? – asdf_enel_hak Sep 02 '15 at 09:42
  • @asdf_enel_hak glad to help. Nope, `browser.wait` is coming from `webdriverjs`, it's definitely staying there (https://github.com/angular/protractor/blob/master/CHANGELOG.md). Thanks. – alecxe Sep 02 '15 at 12:38
  • I told wrong one. I meant: `expect(myelement).isPresent()).toBe(true)` is deprecated. Instead `browser.wait(EC.presenceOf(myElement), 5000);` will be used? – asdf_enel_hak Sep 02 '15 at 13:11
  • @asdf_enel_hak hm, I think both options are valid, they are different, but, in terms of syntax, valid. `browser.wait()` would basically check the condition until it's satisfied or it hits a timeout.. – alecxe Sep 02 '15 at 13:13