Neither waitForAngular nor "then" work as expected

时间:2015-09-01 21:49:39

标签: angularjs typescript protractor angularjs-e2e

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

1 个答案:

答案 0 :(得分:1)

而不是browser.sleep()延迟,请使用browser.wait()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);