0
votes

I'm trying to write a simple "failed login" test in protractor. The thing is, i can't point (don't know how), to the specific string in the source code.

I tried all kinds of things like: cssContainingText, to equal, get text and etc. (maybe it's ok, but i did that wrong).

The test:

describe('login to POC', function() {


  it('should login to POC', function() {
    browser.get('http://emeaherz-swaqal:8080/web-client/login.html#/login');

    element(by.model('echos_username')).sendKeys('super1');

    element(by.model('echos_password')).sendKeys('super');

    element(by.id('loginButton')).click();


    expect(by.id('action-messages')).getText('The following error(s) occurred:').isPresent()).toBe(true);


  });

}); 

Please look on the source code.

I'm really need the suggestion here!

html source

the error i'm getting is:

@alecxe

1) login to POC should login to POC Message: NoSuchElementError: No element found using locator: By.cssSelector(".action-messages") Stacktrace: NoSuchElementError: No element found using locator: By.cssSelector(".action-messages") ==== async task ==== Asynchronous test function: it() Error at [object Object]. (/localfs/Poc/qapoc1/ECHOS-V2-POC/tests/fail_login.js:16:18) Error at [object Object]. (/localfs/Poc/qapoc1/ECHOS-V2-POC/tests/fail_login.js:6:3) at Object. (/localfs/Poc/qapoc1/ECHOS-V2-POC/tests/fail_login.js:1:63)

Finished in 4.942 seconds 1 test, 1 assertion, 1 failure

1

1 Answers

0
votes

You miss the element call and I think you can just expect the text of the error message. Replace:

expect(by.id('action-messages')).getText('The following error(s) occurred:').isPresent()).toBe(true);

with:

expect($('#action-messages ul li').getText()).toEqual("Sorry, your username ...");