简体   繁体   中英

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"> {{user?.login}}</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

While waiting for element with locator - Locator: By(css selector, span#spanuser)

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!

add browser.waitForAngularEnabled('false') in onPrepare of protractor conf.js

onPrepare: function() {
   browser.waitForAngularEnabled('false')
   // if you set this in onPrepare(), it will be a global setting, will
   // effect all script, so you no need to set it in other place.
}

use the jasmin defaulttimeoutinterval in config instead of manual sleep

jasmineNodeOpts: {
   defaultTimeoutInterval: 250000
    },
     allScriptsTimeout: 180000

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM