量角器在承诺之后没有找到相同的元素

时间:2018-05-16 13:36:13

标签: javascript angular typescript testing protractor

我正在尝试从量角器中的元素获取文本,并在对文本执行某些操作后,我想单击相同的元素。这就是我所拥有的

HTML:

<span class="span-user" id="spanuser"> {{user?.login}}</span>

量角器测试:

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!');
        });
    });
});

第一部分工作正常,它得到测试并且它通过了期望,但是当我尝试在span上执行click()函数时,我得到以下错误:

  

失败:等待异步Angular任务在5秒后完成超时。这可能是因为当前页面不是Angular应用程序。有关详细信息,请参阅常见问题:https://github.com/angular/protractor/blob/master/docs/timeouts.md#waiting-for-angular

     

在等待带定位符的元素时 - 定位器:By(css选择器,   跨度#spanuser)

我尝试了什么:

    在spanuser.click()之前的
  • browser.waitForAngular()

  • 在spanuser.click()

    之前
  • browser.wait(10000)

  • 我在beforeAll函数中也有一个waitForAngular()。

有没有人对此有所了解?它对我来说没有任何意义,为什么找不到之前已经找到的相同元素?

非常感谢!

2 个答案:

答案 0 :(得分:1)

在量角器conf.js的browser.waitForAngularEnabled('false')中添加onPrepare

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.
}

答案 1 :(得分:0)

在config中使用jasmin defaulttimeoutinterval而不是手动睡眠

jasmineNodeOpts: {
   defaultTimeoutInterval: 250000
    },
     allScriptsTimeout: 180000