Javascript 量角器似乎没有';无法使用异步页面

Javascript 量角器似乎没有';无法使用异步页面,javascript,protractor,Javascript,Protractor,我有一个HTML页面,用javascript以异步方式填充。我用量角器创建了一个集成测试,但是当测试开始时,我无法访问页面DOM的元素 在量角器测试开始时,我需要访问DOM的一个元素,以检查它是否正确填充。不可能。我无法访问此元素 var EC = protractor.ExpectedConditions; condition = EC.presenceOf($('[id=asyncContentId]')); browser.wait(condition, 5000, "asyncConte

我有一个HTML页面,用javascript以异步方式填充。我用量角器创建了一个集成测试,但是当测试开始时,我无法访问页面DOM的元素

在量角器测试开始时,我需要访问DOM的一个元素,以检查它是否正确填充。不可能。我无法访问此元素

var EC = protractor.ExpectedConditions;
condition = EC.presenceOf($('[id=asyncContentId]'));
browser.wait(condition, 5000, "asyncContentId not ready");
Expect:我需要DOM元素'asyncContentId'

不幸的是,我从未访问过这个DOM元素

我使用Jasmine 2.1 这是我的上一个版本,但它不起作用: 它(“测试Ajax应用程序”,函数(完成){

}));
});

注意:以下是一个异步/等待示例,说明如何等待元素出现。如果您不使用async/await,我坚持您使用,因为SeleniumWebDriver已经有一段时间不推荐使用控制流了

旁注:预期条件可能需要角度同步,我不记得是否需要

在下面的示例中,您可以编写自己的函数来检查元素是否存在

// Turn off sychronization if we are not on an Angular page.
await browser.waitForAngularEnabled(false);

// Wait for the element to be present. This might throw an error when trying
// to find an element, in that case, return false and keep polling for the element
await browser.wait(async () => {
  try {
    return element(by.css('[id="asyncContentId"]')).isPresent();
  } catch (err) {
    // catch the thrown error when webdriver does not find the element
    // and return false so we can still continue to poll.
    return false;
  }
}, 5000, 'asyncContentId is not present.');

你好如果浏览器实例禁用waitForAngular,那么预期条件也不会等待angular,因为EC.presenceOf仍在调用isPresent insideOh neat。我已经有一段时间没有深入研究EC和waitForAngular了。谢谢,但是我的Jasmine是2.1,解决方案无法实现。每个人都有解决方案吗?首先感谢您,我的jasmine 2.1解决方案根本不起作用:
// Turn off sychronization if we are not on an Angular page.
await browser.waitForAngularEnabled(false);

// Wait for the element to be present. This might throw an error when trying
// to find an element, in that case, return false and keep polling for the element
await browser.wait(async () => {
  try {
    return element(by.css('[id="asyncContentId"]')).isPresent();
  } catch (err) {
    // catch the thrown error when webdriver does not find the element
    // and return false so we can still continue to poll.
    return false;
  }
}, 5000, 'asyncContentId is not present.');