失败:无法读取未定义

时间:2016-02-10 03:15:29

标签: javascript promise protractor

我是量角器测试的新手。似乎getWebelement缺失了。我的保护者的版本是3.0.0。另一个属性很好(例如点击,评估......)

browser.wait(element(by.id('some-element')).getWebElement);

browser.wait(element(by.id('some-element')).isPresent);

(C:\ Users \用户XXX \应用程序数据\漫游\ NPM \ node_modules \量角器\ lib中\ element.js:754:36)         在c:\ Users \ xxx \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ webdriver \ webdriver.js:720:12         at goog.async.run.processWorkQueue(c:\ Users \ xxx \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ goog \ async \ run.js:124:15)         at process._tickCallback(node.js:368:9)     来自:任务:         at new wrappedCtr(c:\ Users \ xxx \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ goog \ base.js:2468:26)         at goog.async.run.processWorkQueue(c:\ Users \ xxx \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ goog \ async \ run.js:124:15)         at process._tickCallback(node.js:368:9)     来自:任务:         at [object Object] .webdriver.WebDriver.wait(c:\ Users \ xxx \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ webdriver \ webdriver.js:716:21)         at [object Object] .to。(匿名函数)[as wait](c:\ Users \ xxx \ AppData \ Roaming \ npm \ node_modules \ protractor \ lib \ protractor.js:65:25)         在对象。 (C:\用户\ XXX \ WebstormProjects \ PT \ spec.js:45:21)         在c:\ Users \ xxx \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ jasminewd2 \ index.js:96:23         at new wrappedCtr(c:\ Users \ xxx \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ selenium-webdriver \ lib \ goog \ base.js:2468:26)         在controlFlowExecute(c:\ Users \ xxx \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ jasminewd2 \ index.js:82:18)     From:任务:在控制流程中运行它(“未知”)         在对象。 (C:\ Users \用户XXX \应用程序数据\漫游\ NPM \ node_modules \量角器\ node_modules \ jasminewd2 \ index.js:81:14)         at attemptAsync(c:\ Users \ xxx \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ jasmine \ node_modules \ jasmine-core \ lib \ jasmine-core \ jasmine.js:1819:24)         在QueueRunner.run(c:\ Users \ xxx \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ jasmine \ node_modules \ jasmine-core \ lib \ jasmine-core \ jasmine.js:1774:9)         在QueueRunner.execute(c:\ Users \ xxx \ AppData \ Roaming \ npm \ node_modules \ protractor \ node_modules \ jasmine \ node_modules \ jasmine-core \ lib \ jasmine-core \ jasmine.js:1762:10)

2 个答案:

答案 0 :(得分:2)

browser.wait(element(by.id('some-element')).isPresent());

在isPresent ...

之后你缺少括号

并在getWebElement之后......

browser.wait(element(by.id('some-element')).getWebElement());

答案 1 :(得分:1)

您需要在函数中包含对isPresent()的调用,如下所示:

browser.wait(function() {
  return element(by.id('some-element')).isPresent();
})

以便isPresent()每次browser.wait调用它时都会运行。