Need a protractor waiting for service to return before testing

I'm relatively new to transportation and I haven't been able to get the protractor to wait for the page to unload before testing. See example below:

    //in loginPage object
    function login(email, password) {
        element(by.id('inputEmail')).sendKeys(email);
        element(by.id('inputPassword')).sendKeys(password);
        element(by.css('.btn.btn-primary')).click();
        browser.driver.sleep(4000);
        return !(element(by.binding('userCtrl.labels.signIn()')).isPresent());
    }

      

The sleep operator doesn't work, however, as you can see, the test below always fails even when login succeeds and the browser navigates away from the login page:

        //in separate test page
        it('should allow a valid user to login', function() {
            expect(loginPage.login('tiratf@gmail.com', '12345678')).toBe(true);
        });

      

Thank!

+3


source to share


1 answer


Handler actions (for example isPresent()

) return a promise, not a base value. those. this is a promise:element(by.binding('userCtrl.labels.signIn()')).isPresent()

Read this https://github.com/angular/protractor/blob/master/docs/control-flow.md .

This should go:

function login(email, password) {
    element(by.id('inputEmail')).sendKeys(email);
    element(by.id('inputPassword')).sendKeys(password);
    element(by.css('.btn.btn-primary')).click();
    browser.driver.sleep(4000);
    return element(by.binding('userCtrl.labels.signIn()')).isPresent();
}

      



-

//in separate test page
it('should allow a valid user to login', function() {
    expect(loginPage.login('tiratf@gmail.com', '12345678')).toBe(false);
});

      

What was expected was unleashed by the promise so that you can assert its base value.

+3


source







All Articles