mercredi 16 mai 2018

Protractor not finding the same element after a promise

I'm trying to obtain the text from a element in protractor, and after doing something with the text, i want to click on the same element. This is what i have

HTML:

<span class="span-user" id="spanuser"> </span>

Protractor test:

describe('Login OK with correct pass', () => {
    it('should login successfully with admin account', () => {
        // logging

        username.clear();
        username.sendKeys('admin');
        password.clear();
        password.sendKeys('admin');
        element(by.css('button[type=submit]')).click();
        // check if the username <span> has the current login username

        const expect2 = /admin/;
        const spanuser = element(by.css('span#spanuser'));
        spanuser.getText().then((value) => {
            console.log('inside');
            console.log(value ? value : 'no value');
            expect(value).toMatch(expect2);
        });
        // then i try to click on the same span, to do some stuff

        spanuser.click().then(() =>  {
            console.log('It has been pressed!');
        });
    });
});

The first part works just fine, it gets the test and it passes the expect, but when i try to do the click() function on the span, i get the following error:

Failed: Timed out waiting for asynchronous Angular tasks to finish after 5 seconds. This may be because the current page is not an Angular application. Please see the FAQ for moredetails: https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular

What have i tried:

  • browser.waitForAngular() before spanuser.click()

  • browser.wait(10000) before spanuser.click()

  • also i have a waitForAngular() in the beforeAll function.

Does anyone has a idea on this? It doesn't really make any sense to me, why wouldn't find the same element that has already found before?

Thanks a lot!

Aucun commentaire:

Enregistrer un commentaire